5
votes

Following the example: http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html

from sklearn import linear_model
clf = linear_model.Lasso(alpha=0.1)
clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])

clf.predict(np.array([0,0]).reshape(1,-1))
Out[13]: array([ 0.15])

Can I get the prediction to be a classification instead of a regression. In other words when I give it an input, I would like an output that is categorical.

2
Can't you just add some "if" statements after your regression? Most classifiers are based on dividing the space into subspaces in order to labelise them. Basicly it's only adding "if" statements after mapping your data into the wanted space (usually one that permits a linear classification).ysearka
I am really not sure sure. I thought maybe rounding?Kevin
You can use sklearn.linear_model.LogisticRegression model with 'l1' penalty.Stergios

2 Answers

3
votes

Use LogisticRegression with penalty='l1'.
It is, essentially, the Lasso regression, but with the additional layer of converting the scores for classes to the "winning" class output label.
Regularization strength is defined by C, which is the INVERSE of alpha, used by Lasso.
Scikit-learn has a very nice brief overview of linear models:
https://scikit-learn.org/stable/modules/linear_model.html

-1
votes

You can use Lasso and sort prediction results in descending way, so the first 50% will be 1 and the last are 0.