4.弹性网络( Elastic Net)
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 np
- import matplotlib.pyplot as plt
- from sklearn.linear_model import lasso_path, enet_path
- from sklearn import datasets
- diabetes = datasets.load_diabetes()
- X = diabetes.data
- y = diabetes.target
- X /= X.std(axis=0) # Standardize data (easier to set the l1_ratio parameter)
- # Compute paths
- eps = 5e-3 # the smaller it is the longer is the path
- print("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 results
- plt.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()
4.弹性网络( Elastic Net)的更多相关文章
- 【笔记】简谈L1正则项L2正则和弹性网络
L1,L2,以及弹性网络 前情提要: 模型泛化与岭回归与LASSO 正则 ridge和lasso的后面添加的式子的格式上其实和MSE,MAE,以及欧拉距离和曼哈顿距离是非常像的 虽然应用场景不同,但是 ...
- 机器学习:模型泛化(L1、L2 和弹性网络)
一.岭回归和 LASSO 回归的推导过程 1)岭回归和LASSO回归都是解决模型训练过程中的过拟合问题 具体操作:在原始的损失函数后添加正则项,来尽量的减小模型学习到的 θ 的大小,使得模型的泛化能力 ...
- 机器学习算法--Elastic Net
1) alpha : float, optional Constant that multiplies the penalty terms. Defaults to 1.0. See the note ...
- [源码解析] 深度学习分布式训练框架 horovod (20) --- Elastic Training Operator
[源码解析] 深度学习分布式训练框架 horovod (20) --- Elastic Training Operator 目录 [源码解析] 深度学习分布式训练框架 horovod (20) --- ...
- 基于C#的机器学习--颜色混合-自组织映射和弹性神经网络
自组织映射和弹性神经网络 自组织映射(SOM),或者你们可能听说过的Kohonen映射,是自组织神经网络的基本类型之一.自组织的能力提供了对以前不可见的输入数据的适应性.它被理论化为最自然的学习方式之 ...
- 阿里云弹性裸金属服务器-神龙架构(X-Dragon)揭秘
在5月16日的飞天技术会新品直播中,特别邀请了业界知名大咖狒哥以及阿里云虚拟化资深专家旭卿作为现场直播的嘉宾.本次直播主要从产品背景到“X-Dragon架构”,从硬件设备到软件应用来深度的剖析“X-D ...
- [Machine Learning] 机器学习常见算法分类汇总
声明:本篇博文根据http://www.ctocio.com/hotnews/15919.html整理,原作者张萌,尊重原创. 机器学习无疑是当前数据分析领域的一个热点内容.很多人在平时的工作中都或多 ...
- Spark入门实战系列--8.Spark MLlib(上)--机器学习及SparkMLlib简介
[注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .机器学习概念 1.1 机器学习的定义 在维基百科上对机器学习提出以下几种定义: l“机器学 ...
- 转:netflix推荐系统竞赛
原文链接:Netflix recommendations: beyond the 5 stars (Part 1), (Part 2) 原文作者:Xavier Amatriain and Justin ...
随机推荐
- idea 实用插件
尊重劳动成果,本插件的整理原文出自:https://blog.csdn.net/weixin_41846320/article/details/82697818,感谢老铁的辛苦原创. 插件安装方式: ...
- apache 防盗链
方法1:Apache防盗链的第一种实现方法,可以用rewrite实现 (1.)首先要确认Apache的rewrite module可用,打开 httpd.conf 文件,如果前面有注释去掉 LoadM ...
- [networking][sdn] BGP/EGP/IGP是什么
引子 这是一个惊悚的故事,胆小的人不要点开.整个故事,是从这张图开始的. 整个图,分左中右三块.左边是tom和他所在的网络.右边是jerry和他所在的网络.这两个网络可以在世界上的任何一个角落.彼此有 ...
- Python安装package_name包
官网:https://packaging.python.org/tutorials/installing-packages/ 首先查看已安装的包: 1. 命令行模式输入:pydoc modules 2 ...
- java相关网址汇总1
Java网站汇总 官方 框架 数据库 资源网站 视频学习网站 开发工具 其他工具 github/gitee框架项目 社区 博客/个人 官方 Sun公司网站Sun公司中文网站J2SE下载网站JavaSE ...
- linux网络编程之posix线程(一)
今天继续学习posix IPC相关的东东,消息队列和共享内存已经学习过,接下来学习线程相关的知识,下面开始: [注意]:创建失败这时会返回错误码,而通常函数创建失败都会返回-1,然后错误码会保存在er ...
- 0016SpringBoot实现RESTFUL形式的增删改查
1.列表页面如下 <!DOCTYPE html><!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples ...
- python pip获取所有已安装的第三包
pip freeze > requirements.txt # 生成txt 文件 pip install -r requirements.txt # 别人使用时可以直接安装所有的包 [progr ...
- Hadoop集群分布搭建
一.准备工作 1.最少三台虚拟机或者实体机(官网上是默认是3台),我这边是3台 s1: 10.211.55.18 s2: 10.211.55.19 s3: 10.211.55.20 2.安装JDK 3 ...
- 011_GoldWave软件安装及使用
(一)软件安装包: 链接:https://pan.baidu.com/s/15c5veooyA8bAYIAgLFOLjg提取码:jiis 复制这段内容后打开百度网盘手机App,操作更方便哦 (二)降低 ...