4.弹性网络( Elastic Net)
来源:互联网 发布:ncut算法优劣 编辑:程序博客网 时间:2024/05/19 18:48
ElasticNet 是一种使用L1和L2先验作为正则化矩阵的线性回归模型.这种组合用于只有很少的权重非零的稀疏模型,比如:class:Lasso, 但是又能保持:class:Ridge 的正则化属性.我们可以使用 l1_ratio 参数来调节L1和L2的凸组合(一类特殊的线性组合)。
当多个特征和另一个特征相关的时候弹性网络非常有用。Lasso 倾向于随机选择其中一个,而弹性网络更倾向于选择两个.
在实践中,Lasso 和 Ridge 之间权衡的一个优势是它允许在循环过程(Under rotate)中继承 Ridge 的稳定性.
弹性网络的目标函数是最小化:
ElasticNetCV 可以通过交叉验证来用来设置参数 alpha
() 和 l1_ratio
()
print(__doc__)import numpy as npimport matplotlib.pyplot as pltfrom sklearn.linear_model import lasso_path, enet_pathfrom sklearn import datasetsdiabetes = datasets.load_diabetes()X = diabetes.datay = diabetes.targetX /= X.std(axis=0) # Standardize data (easier to set the l1_ratio parameter)# Compute pathseps = 5e-3 # the smaller it is the longer is the pathprint("Computing regularization path using the lasso...")alphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps, fit_intercept=False)print("Computing regularization path using the positive lasso...")alphas_positive_lasso, coefs_positive_lasso, _ = lasso_path( X, y, eps, positive=True, fit_intercept=False)print("Computing regularization path using the elastic net...")alphas_enet, coefs_enet, _ = enet_path( X, y, eps=eps, l1_ratio=0.8, fit_intercept=False)print("Computing regularization path using the positve elastic net...")alphas_positive_enet, coefs_positive_enet, _ = enet_path( X, y, eps=eps, l1_ratio=0.8, positive=True, fit_intercept=False)# Display resultsplt.figure(1)ax = plt.gca()ax.set_color_cycle(2 * ['b', 'r', 'g', 'c', 'k'])l1 = plt.plot(-np.log10(alphas_lasso), coefs_lasso.T)l2 = plt.plot(-np.log10(alphas_enet), coefs_enet.T, linestyle='--')plt.xlabel('-Log(alpha)')plt.ylabel('coefficients')plt.title('Lasso and Elastic-Net Paths')plt.legend((l1[-1], l2[-1]), ('Lasso', 'Elastic-Net'), loc='lower left')plt.axis('tight')plt.figure(2)ax = plt.gca()ax.set_color_cycle(2 * ['b', 'r', 'g', 'c', 'k'])l1 = plt.plot(-np.log10(alphas_lasso), coefs_lasso.T)l2 = plt.plot(-np.log10(alphas_positive_lasso), coefs_positive_lasso.T, linestyle='--')plt.xlabel('-Log(alpha)')plt.ylabel('coefficients')plt.title('Lasso and positive Lasso')plt.legend((l1[-1], l2[-1]), ('Lasso', 'positive Lasso'), loc='lower left')plt.axis('tight')plt.figure(3)ax = plt.gca()ax.set_color_cycle(2 * ['b', 'r', 'g', 'c', 'k'])l1 = plt.plot(-np.log10(alphas_enet), coefs_enet.T)l2 = plt.plot(-np.log10(alphas_positive_enet), coefs_positive_enet.T, linestyle='--')plt.xlabel('-Log(alpha)')plt.ylabel('coefficients')plt.title('Elastic-Net and positive Elastic-Net')plt.legend((l1[-1], l2[-1]), ('Elastic-Net', 'positive Elastic-Net'), loc='lower left')plt.axis('tight')plt.show()
0 0
- 4.弹性网络( Elastic Net)
- 4.弹性网络( Elastic Net)
- 弹性网络( Elastic Net) 多任务 Lasso回归 MultiTaskLasso
- Elastic Net
- 弹性光网络(基础知识)
- Lasso and Elastic Net for Sparse Signals:线性模型之套索和弹性网稀疏信号对比
- 弹性网络
- Ridge & LASSO & Elastic Net
- scikit-learn学习:elastic net
- elastic
- elastic
- LASSO, sparse group LASSO, elastic net
- LASSO, sparse group LASSO, elastic net
- Lasso和Elastic net的区别
- L0、L1、L2、Elastic Net正则项
- 岭回归、LASSO与elastic net
- L0、L1、L2、Elastic Net正则项
- 中兴ElasticNet 弹性网络解决方案
- Shell
- 修改Eclipse的package explore字体的方法
- java 元数据metadata
- Linux进程描述符——task_struct(初学者的简单学习)
- 日志库
- 4.弹性网络( Elastic Net)
- 屏蔽ViewPager的预加载
- ssh-keygen 的man手册译文
- UVA2070-Interesting Numbers
- 第一篇博客
- C++全局变量与静态变量构造析构顺序问题
- Python学习笔记 --- ImportError: No module named sqlalchemy
- 关于使用echarts.js插件写的一个折线图demo
- 利用Tcp通信模式实现登陆验证(单线程)