python - What's the right way to use a sparse matrix in scikit? -
python - What's the right way to use a sparse matrix in scikit? -
i'm trying accomplish classification task trying utilize sparse matrix. when pass training set logistic regression function, in scikit, returns error:
valueerror: array contains nan or infinity.
the type of matrix i'm passing argument logistic regression scipy.sparse.csr.csr_matrix
.
this how create sparse matrix, numpy array nans:
x=sparse.csr_matrix(x_hat)
what doing wrong? same error train_test_split
, , these functions supposed take sparse matrices argument according documentation.
i'm using version 0.14 of scikit-learn.
update: total traceback.
--------------------------------------------------------------------------- valueerror traceback (most recent phone call last) <ipython-input-65-acdaac419166> in <module>() 1 ----> 2 model2.fit(x_train, y_train) c:\anaconda\lib\site-packages\sklearn\svm\base.pyc in fit(self, x, y) 666 " one.") 667 --> 668 x = atleast2d_or_csr(x, dtype=np.float64, order="c") 669 670 self.class_weight_ = compute_class_weight(self.class_weight, c:\anaconda\lib\site-packages\sklearn\utils\validation.pyc in atleast2d_or_csr(x, dtype, order, copy, force_all_finite) 132 """ 133 homecoming _atleast2d_or_sparse(x, dtype, order, copy, sparse.csr_matrix, --> 134 "tocsr", force_all_finite) 135 136 c:\anaconda\lib\site-packages\sklearn\utils\validation.pyc in _atleast2d_or_sparse(x, dtype, order, copy, sparse_class, convmethod, force_all_finite) 105 x = sparse_class(x, dtype=dtype) 106 if force_all_finite: --> 107 _assert_all_finite(x.data) 108 x.data = np.array(x.data, copy=false, order=order) 109 else: c:\anaconda\lib\site-packages\sklearn\utils\validation.pyc in _assert_all_finite(x) 25 if (x.dtype.char in np.typecodes['allfloat'] , not np.isfinite(x.sum()) 26 , not np.isfinite(x).all()): ---> 27 raise valueerror("array contains nan or infinity.") 28 29 valueerror: array contains nan or infinity.
python scikit-learn sparse-matrix logistic-regression
Comments
Post a Comment