scikit-learn-contrib/lightning

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

Sandy4321 opened this issue · 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'

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]

I want to solve this issue , @Sandy4321

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

thanks

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