注:本文所有内容可从scikit-learn官网中找到
from sklearn import linear_model
reg=linear_model.LinearRegression()
reg.fit([[0,0],[1,1],[2,2]],[0,1,2])
print(reg)
c=reg.coef_
print(c)
from sklearn import linear_model
reg=linear_model.Ridge(alpha=.5)
reg.fit([[0,0],[1,1],[2,2]],[0,.1,1])
print(reg.coef_)
print(reg.intercept_)
from sklearn import linear_model
reg=linear_model.Lasso(alpha=.1)
reg.fit([[0,0],[1,1]],[0,1])
print(reg.coef_)
print(reg.intercept_)
print(reg.predict([[1,1]]))
from sklearn import linear_model
reg=linear_model.LassoLars(alpha=.1)
reg.fit([[0,0],[1,1]],[0,1])
print(reg.coef_)
print(reg.intercept_)
print(reg.predict([[1,1]]))
from sklearn import linear_model
x=[[0,0],[1,1],[2,2],[3,3]]
Y=[0,1,2,3]
reg=linear_model.BayesianRidge()
reg.fit(x,Y)
print(reg.coef_)
print(reg.intercept_)
print(reg.predict([[1,1]]))