scikit learn之Elastic Net

本文介绍了Elastic Net,这是一种结合了Lasso和Ridge回归特性的方法。通过官方文档的解释,清晰阐述了Elastic Net在回归问题中的作用和优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

弹性网络

弹性网络是一个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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值