4.弹性网络( Elastic Net)
来源:互联网 发布:耐玩的手机小游戏知乎 编辑:程序博客网 时间:2024/06/10 21:17
ElasticNet 是一种使用L1和L2先验作为正则化矩阵的线性回归模型.这种组合用于只有很少的权重非零的稀疏模型,比如:class:Lasso, 但是又能保持:class:Ridge 的正则化属性.我们可以使用 l1_ratio 参数来调节L1和L2的凸组合(一类特殊的线性组合)。
当多个特征和另一个特征相关的时候弹性网络非常有用。Lasso 倾向于随机选择其中一个,而弹性网络更倾向于选择两个.
在实践中,Lasso 和 Ridge 之间权衡的一个优势是它允许在循环过程(Under rotate)中继承 Ridge 的稳定性.
弹性网络的目标函数是最小化:
ElasticNetCV 可以通过交叉验证来用来设置参数
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 弹性网络解决方案
- 写给Android开发者的混淆使用手册
- 【bzoj 1003】 物流运输 【ZJOI2006】
- 我的学习记录57
- top,rownum,limit,用法和分页
- 第三章:Python基础
- 4.弹性网络( Elastic Net)
- Wireshark安装
- PHP MySQL 简介
- mysql 远程访问不行解决方法 Host is not allowed to connect to this MySQL server
- spark学习-52-Spark的org.apache.spark.SparkException: Task not serializable
- Android Studio3.0中dependencies依赖由compile变为implementation的区别
- 集成学习
- PHP 连接 MySQL
- 第7章 数据规整化:清理、转换、合并、重塑(2)