免責事項:この記事はブロガーオリジナル記事ですが、許可ブロガーなく再生してはなりません。
https://blog.csdn.net/qq_21904665/article/details/52315642
ラッソ、しかし維持しつつ:クラス:のリッジ線形回帰モデルの正則行列は、:.クラスとしてのみ少数の非ゼロ重みのそのような組合せのために疎なモデルであるとしてElasticNet L1およびL2を使用して先験的です正則化特性は、我々は、L1とL2の凸組み合わせl1_ratioパラメータ(線形組み合わせの特別なクラス)を調整するために使用できます。
さらに、前記ネットワークは、弾性関連する複数の特徴が有用である場合。ランダム弾性両者のいずれかを選択する傾向が投げ縄ネットワークを好む。
実際には、トレードオフラッソとリッジとの間の利点は、それが中(回転中)サイクル中遺伝リッジの安定性を可能にすることである。
弾性ネットワーク目的は、最小限に抑えることです。
ElasticNetCVクロスバリデーションは、パラメータを設定するために使用することができる alpha
()および l1_ratio
()
-
印刷(__ doc__内の例題)
-
-
numpyのインポートNPとして
-
輸入matplotlib.pyplot PLTなど
-
-
sklearn.linear_modelから輸入lasso_path、enet_path
-
sklearnのからのインポートデータセット
-
-
糖尿病= 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 = '左下')
-
plt.axis( 'タイト')
-
plt.show()