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.
The Sklearn 'Predict' Method Predicts an Output That being the case, it provides a set of tools for doing things like training and evaluating machine learning models. What is this? And it also has tools to predict an output value, once the model is trained (for ML techniques that actually make predictions).
You can use the Lasso or elastic net regularization for generalized linear model regression which can be used for classification problems.
Evaluation of the lasso model can be done using metrics like RMSE and R-Square. Alpha is a hyper-parameter in the lasso model which can be tuned using lassoCV to control the regularization.
In Python, Lasso regression can be performed using the Lasso class from the sklearn. linear_model library. The Lasso class takes in a parameter called alpha which represents the strength of the regularization term. A higher alpha value results in a stronger penalty, and therefore fewer features being used in the model.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With