lightning icon indicating copy to clipboard operation
lightning copied to clipboard

CDClassifier : error for penalty="l1" and penalty="l2", but no error for penalty="l1/l2"

Open Sandy4321 opened this issue 2 years ago • 5 comments

CDClassifier : error for penalty="l1" and penalty="l2", but no error for penalty="l1/l2"

from lightning.classification import CDClassifier #Estimator for learning linear classifiers by (block) coordinate descent clf = CDClassifier(loss="squared_hinge", penalty="l2", #penalty="l1/l2", #
multiclass=False, max_iter=20, alpha=1e-4, C=1.0 / X_train_vectorised.shape[0], tol=1e-3, n_jobs =5) # clf.fit(X_train_vectorised, y_train)

clf.fit(X_train_vectorised, y_train) File "c:\my_py_environments\py310_env_apr2023\lib\site-packages\lightning\impl\primal_cd.py", line 258, in fit y, n_classes, n_vectors = self._set_label_transformers(y, File "c:\my_py_environments\py310_env_apr2023\lib\site-packages\lightning\impl\base.py", line 78, in _set_label_transformers y = y.astype(np.int32)

builtins.AttributeError: 'list' object has no attribute 'astype'

Sandy4321 avatar Jul 31 '23 19:07 Sandy4321

X_train_vectorised <1177x4883 sparse matrix of type '<class 'numpy.float64'>' with 87732 stored elements in Compressed Sparse Row format> y_train ['0\n', '1\n', '0\n', '1\n', '1\n']

same error for reformating y_train = [int(x) for x in y_train]

Sandy4321 avatar Jul 31 '23 20:07 Sandy4321

I want to solve this issue , @Sandy4321

DhruvSanghvi2002 avatar Aug 14 '23 17:08 DhruvSanghvi2002

@Sandy4321 y needs to be a numpy array of integers, you used a list of strings.

mblondel avatar Aug 15 '23 04:08 mblondel

thanks

Sandy4321 avatar Aug 17 '23 21:08 Sandy4321

by the way is it possible to predict with probability like scikit learn https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html predict_proba(X) Probability estimates. image

Sandy4321 avatar Aug 18 '23 19:08 Sandy4321