Linear Model
The following linear models are available in scikit-learn for regression and classification tasks, if is the target variable, is the feature vector, and is the weight vector
- is the
intercept_
- are the
coef_
Linear Regression
Fits a linear model with coefficients to minimize the residual sum of squares between the observed targets in the dataset, and the targets predicted by the linear approximation.
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
Ridge Regression
Applies L2 regularization to reduce the complexity of the model and prevent overfitting.
- Hyperparameter
- if , then the model is the same as Linear Regression
from sklearn.linear_model import Ridge
ridge = Ridge(alpha=1.0)
from sklearn.linear_model import RidgeCV
Lasso Regression
Applies L1 regularization to reduce the complexity of the model and prevent overfitting.
- Hyperparameter
- if , then the model is the same as Linear Regression
from sklearn.linear_model import Lasso
lasso = Lasso(alpha=1.0)
Elastic Net Regression
Applies both L1 and L2 regularization to reduce the complexity of the model and prevent overfitting.
- Hyperparameter and
- if , and , then the model is the same as Linear Regression
from sklearn.linear_model import ElasticNet
elastic_net = ElasticNet(alpha=1.0, l1_ratio=0.5)
Polynomial Regression
Generates polynomial features and fits a linear model to the transformed data.
- Hyperparameter
degree
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import make_pipeline
poly = PolynomialFeatures(degree=2)
poly_reg = make_pipeline(poly, LinearRegression())
Logistic Regression
Use when you want to predict a binary outcome (0 or 1, yes or no, true or false) given a set of independent variables.
from sklearn.linear_model import LogisticRegression
log_reg = LogisticRegression()
Stocastic Gradient Descent
Use when you want to train large datasets.
- Hyperparameter
eta0
is the learning rate
from sklearn.linear_model import SGDClassifier, SGDRegressor
sgd_clf = SGDClassifier()
sgd_reg = SGDRegressor()
Bayesian Ridge Regression
Bayesian Ridge Regression is similar to Ridge Regression, but it introduces a prior on the weights .
- Original Algorithm is detailed in the book
Bayesian learning for neural networks
- Hyperparameter
alpha_1
,alpha_2
,lambda_1
,lambda_2
from sklearn.linear_model import BayesianRidge
bayesian_ridge = BayesianRidge()
Passive Aggressive
Passive Aggressive algorithms are a family of algorithms for large-scale learning
from sklearn.linear_model import PassiveAggressiveClassifier, PassiveAggressiveRegressor
passive_aggressive_clf = PassiveAggressiveClassifier()
passive_aggressive_reg = PassiveAggressiveRegressor()
RANSAC Regression
RANSAC (RANdom SAmple Consensus) is an iterative algorithm for the robust estimation of parameters from a subset of inliers from the complete data set.
from sklearn.linear_model import RANSACRegressor
ransac_reg = RANSACRegressor()