弹性网络
弹性网络是一个lasso和ridge的结合
下图是官方文档的解释,感觉说的还是很清楚~
Lasso and Elastic Net
from itertools import cycle
from sklearn.linear_model import lasso_path,enet_path
from sklearn import datasets
import numpy as np
import matplotlib.pyplot as plt
diabetes = datasets.load_diabetes()
x = diabetes.data
y = diabetes.target
x = x/x.std(axis=0)#对于每个变量标准化,(easier to set the l1_ratio parameter)
eps = 5e-3
alphas_lasso,coef_lasso,_ = lasso_path(x,y,eps,fit_intercept = False)
#The alphas and coefs along the path where models are computed.
#注意后面的这个_,是用来填补后面的变量滴
alphas_positive_lasso,coef_positive_lasso,_ = lasso_path(x,y,eps,positive=True
,fit_intercept = False)
#强制把系数约束为正数
alphas_en