日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

4.弹性网络( Elastic Net)

發(fā)布時間:2025/4/16 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 4.弹性网络( Elastic Net) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

ElasticNet 是一種使用L1和L2先驗作為正則化矩陣的線性回歸模型.這種組合用于只有很少的權(quán)重非零的稀疏模型,比如:class:Lasso, 但是又能保持:class:Ridge 的正則化屬性.我們可以使用 l1_ratio 參數(shù)來調(diào)節(jié)L1和L2的凸組合(一類特殊的線性組合)。
當(dāng)多個特征和另一個特征相關(guān)的時候彈性網(wǎng)絡(luò)非常有用。Lasso 傾向于隨機選擇其中一個,而彈性網(wǎng)絡(luò)更傾向于選擇兩個.
在實踐中,Lasso 和 Ridge 之間權(quán)衡的一個優(yōu)勢是它允許在循環(huán)過程(Under rotate)中繼承 Ridge 的穩(wěn)定性.
彈性網(wǎng)絡(luò)的目標(biāo)函數(shù)是最小化:
minw12nsamples||Xw?y||22+αρ||w||1+α(1?ρ)2||w||22
ElasticNetCV 可以通過交叉驗證來用來設(shè)置參數(shù) α(α)l1ratio(ρ)

print(__doc__)import numpy as np import matplotlib.pyplot as pltfrom sklearn.linear_model import lasso_path, enet_path from sklearn import datasetsdiabetes = datasets.load_diabetes() X = diabetes.data y = 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()

總結(jié)

以上是生活随笔為你收集整理的4.弹性网络( Elastic Net)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。