4.柔軟なネットワーク(弾性ネット)

 

免責事項:この記事はブロガーオリジナル記事ですが、許可ブロガーなく再生してはなりません。 https://blog.csdn.net/qq_21904665/article/details/52315642

ラッソ、しかし維持しつつ:クラス:のリッジ線形回帰モデルの正則行列は、:.クラスとしてのみ少数の非ゼロ重みのそのような組合せのために疎なモデルであるとしてElasticNet L1およびL2を使用して先験的です正則化特性は、我々は、L1とL2の凸組み合わせl1_ratioパラメータ(線形組み合わせの特別なクラス)を調整するために使用できます。

さらに、前記ネットワークは、弾性関連する複数の特徴が有用である場合。ランダム弾性両者のいずれかを選択する傾向が投げ縄ネットワークを好む。
実際には、トレードオフラッソとリッジとの間の利点は、それが中(回転中)サイクル中遺伝リッジの安定性を可能にすることである。
弾性ネットワーク目的は、最小限に抑えることです。

\ underset {W} {分\} {\ FRAC {1} {2n_ {サンプル}} || X W  -  Y || _2 ^ 2 + \アルファ\ロー|| W || _1 + \ FRAC {\アルファ(1- \ロー)} {2} || W || _2 ^ 2}

ElasticNetCVクロスバリデーションは、パラメータを設定するために使用することができる  alpha (\アルファ)および  l1_ratio (\ロー

 

  1.  
    印刷(__ doc__内の例題)
  2.  
     
  3.  
    numpyのインポートNPとして
  4.  
    輸入matplotlib.pyplot PLTなど
  5.  
     
  6.  
    sklearn.linear_modelから輸入lasso_path、enet_path
  7.  
    sklearnのからのインポートデータセット
  8.  
     
  9.  
    糖尿病= datasets.load_diabetes()
  10.  
    X = diabetes.data
  11.  
    y = diabetes.target
  12.  
     
  13.  
    X /= X.std(axis= 0) # Standardize data (easier to set the l1_ratio parameter)
  14.  
     
  15.  
    # Compute paths
  16.  
     
  17.  
    eps = 5e-3 # the smaller it is the longer is the path
  18.  
     
  19.  
    print( "Computing regularization path using the lasso...")
  20.  
    alphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps, fit_intercept= False)
  21.  
     
  22.  
    print( "Computing regularization path using the positive lasso...")
  23.  
    alphas_positive_lasso, coefs_positive_lasso, _ = lasso_path(
  24.  
    X, y, eps, positive= True, fit_intercept=False)
  25.  
    print( "Computing regularization path using the elastic net...")
  26.  
    alphas_enet, coefs_enet, _ = enet_path(
  27.  
    X, y, eps=eps, l1_ratio= 0.8, fit_intercept=False)
  28.  
     
  29.  
    print( "Computing regularization path using the positve elastic net...")
  30.  
    alphas_positive_enet, coefs_positive_enet, _ = enet_path(
  31.  
    X, y, eps=eps, l1_ratio= 0.8, positive=True, fit_intercept=False)
  32.  
     
  33.  
    # Display results
  34.  
     
  35.  
    plt.figure( 1)
  36.  
    ax = plt.gca()
  37.  
    ax.set_color_cycle( 2 * ['b', 'r', 'g', 'c', 'k'])
  38.  
    l1 = plt.plot(-np.log10(alphas_lasso), coefs_lasso.T)
  39.  
    l2 = plt.plot(-np.log10(alphas_enet), coefs_enet.T, linestyle= '--')
  40.  
     
  41.  
    plt.xlabel( '-Log(alpha)')
  42.  
    plt.ylabel( 'coefficients')
  43.  
    plt.title( 'Lasso and Elastic-Net Paths')
  44.  
    plt.legend((l1[ -1], l2[-1]), ('Lasso', 'Elastic-Net'), loc='lower left')
  45.  
    plt.axis( 'tight')
  46.  
     
  47.  
     
  48.  
    plt.figure( 2)
  49.  
    ax = plt.gca()
  50.  
    ax.set_color_cycle( 2 * ['b', 'r', 'g', 'c', 'k'])
  51.  
    l1 = plt.plot(-np.log10(alphas_lasso), coefs_lasso.T)
  52.  
    l2 = plt.plot(-np.log10(alphas_positive_lasso), coefs_positive_lasso.T,
  53.  
    linestyle= '--')
  54.  
     
  55.  
    plt.xlabel( '-Log(alpha)')
  56.  
    plt.ylabel( 'coefficients')
  57.  
    plt.title( 'Lasso and positive Lasso')
  58.  
    plt.legend((l1[ -1], l2[-1]), ('Lasso', 'positive Lasso'), loc='lower left')
  59.  
    plt.axis( 'tight')
  60.  
     
  61.  
     
  62.  
    plt.figure( 3)
  63.  
    ax = plt.gca()
  64.  
    ax.set_color_cycle( 2 * ['b', 'r', 'g', 'c', 'k'])
  65.  
    l1 = plt.plot(-np.log10(alphas_enet), coefs_enet.T)
  66.  
    l2 = plt.plot(-np.log10(alphas_positive_enet), coefs_positive_enet.T,
  67.  
    linestyle= '--')
  68.  
     
  69.  
    plt.xlabel( '-Log(alpha)')
  70.  
    plt.ylabel( 'coefficients')
  71.  
    plt.title( 'Elastic-Net and positive Elastic-Net')
  72.  
    plt.legend((l1[ -1], l2[-1]), ('Elastic-Net', 'positive Elastic-Net'),
  73.  
    LOC = '左下')
  74.  
    plt.axis( 'タイト')
  75.  
    plt.show()

おすすめ

転載: www.cnblogs.com/lvdongjie/p/11314743.html