zoukankan      html  css  js  c++  java
  • sklearn中的弹性网函数 ElasticNet

     

    语法:

     ElasticNet(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, normalize=False, precompute=False, max_iter=1000, copy_X=True, tol=1e-4, warm_start=False, positive=False, random_state=None, selection=’cyclic’)

    类型:

     sklearn.linear_model.coordinate_descent 中的类,使用L1和L2组合作为正则项的线性回归。最小化目标函数为

     
    1(2nsamples)||yXw||22+αl1_ratio||w||1+0.5 alpha(1l1_ratio)||w||221(2∗nsamples)||y−Xw||22+α∗l1_ratio∗||w||1+0.5∗ alpha∗(1−l1_ratio)∗||w||22

     如果关注L1和L2惩罚项的分类,记住下面的公式:
     
    a=L1+bL2a=L1+b∗L2

     这里:
     
    α=a+bl1_ratio=a/(a+b)α=a+bl1_ratio=a/(a+b)

     这里参数l1_ratio对用R中的glmnet包中的αα ,αα 对用R中的λλ ,特别的,l1_ratio = 1 是lasso惩罚,当前l1_ratio0.01l1_ratio≤0.01 是不可靠的,除非你使用自己定义的alpha序列。

     在用户指南中读取更多。

    输入参数:

    • 参数名:alpha
    • 类型:float, optional
    • 说明:混合惩罚项的常数,morning是1,看笔记的得到有关这个参数的精确数学定义。alpha = 0等价于传统最小二乘回归,通过LinearRegression求解。因为数学原因,使用alpha = 0的lasso回归时不推荐的,如果是这样,你应该使用 LinearRegression 。*

    • 参数名:l1_ratio
    • 类型:float
    • 说明:弹性网混合参数,0 <= l1_ratio <= 1,对于 l1_ratio = 0,惩罚项是L2正则惩罚。对于 l1_ratio = 1是L1正则惩罚。对于 0

    属性

    • 参数名:coef_
    • 类型:array, shape (n_features,) | (n_targets, n_features)
    • 说明:参数向量(损失函数表达式中的ww )

    • 参数名:sparse_coef_
    • 类型:scipy.sparse matrix, shape (n_features, 1) | (n_targets, n_features)
    • 说明:sparse_coef_ 是从coef_ 导出的只读属性

    • 参数名:intercept_
    • 类型:float | array, shape (n_targets,)
    • 说明:决策函数中的独立项,即截距

    • 参数名:n_iter_
    • 类型:array-like, shape (n_targets,)
    • 说明:由坐标下降求解器运行的,达到指定公差的迭代次数。

    实例:

    #导入弹性网
    from sklearn.linear_model import ElasticNet
    from sklearn.datasets import make_regression
    
    # 初始化数据,模拟数据
    X, y = make_regression(n_features=2, random_state=0)
    # 实例化弹性网类,设定随机种子,保证每次计算结果都相同
    regr = ElasticNet(random_state=0)
    # 训练弹性网
    regr.fit(X, y)
    # 打印系数,结果是[ 18.83816048  64.55968825]
    print(regr.coef_) 
    # 打印截距,结果是1.45126075617
    print(regr.intercept_) 
    # 打印预测值,结果是[ 1.45126076]
    print(regr.predict([[0, 0]]))

     为了避免不必要的内存复制,应该将fit方法的X参数直接作为一个fortranguous numpy数组传递

    参阅

    • SGDRegressor:采用增量式培训实现弹性净回归。
    • SGDClassifier:用弹性网惩罚实现逻辑回归。
    • (SGDClassifier(loss=”log”, penalty=”elasticnet”)).
  • 相关阅读:
    This counter can increment, decrement or skip ahead by an arbitrary amount
    LUT4/MUXF5/MUXF6 logic : Multiplexer 8:1
    synthesisable VHDL for a fixed ratio frequency divider
    Bucket Brigade FIFO SRL16E ( VHDL )
    srl16e fifo verilog
    DualPort Block RAM with Two Write Ports and Bytewide Write Enable in ReadFirst Mode
    Parametrilayze based on SRL16 shift register FIFO
    stm32 spi sdcard fatfs
    SPI bus master for System09 (2)
    SQLSERVER中的自旋锁
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/11314738.html
Copyright © 2011-2022 走看看