7.LARS lasso 模型
生活随笔
收集整理的這篇文章主要介紹了
7.LARS lasso 模型
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
LassoLars 是一個使用LARS算法實現的lasso模型。和基于坐標下降的實現不同的是,它產生的是精確的解,和一個函數標準系數一樣是精確線性的。
1.1 數學描述
這個算法和逐步回歸很相似,但是除了在每一步包含變量之外,估計的參數沿著每一個對應的殘差的對角方向增長。(待校正)。 并不是給出一個向量結果,而是在LARS的解中包含了一個曲線,用來表示每個參數向量的L1-norm 值的解, 所有系數路徑存在?coef_path_?數組中,大小為(n_features,max_features+1),其中第一列總是0.
import numpy as np import matplotlib.pyplot as pltfrom sklearn import linear_model from sklearn import datasetsdiabetes = datasets.load_diabetes() X = diabetes.data y = diabetes.targetprint("Computing regularization path using the LARS ...") alphas, _, coefs = linear_model.lars_path(X, y, method='lasso', verbose=True)xx = np.sum(np.abs(coefs.T), axis=1) xx /= xx[-1]plt.plot(xx, coefs.T) ymin, ymax = plt.ylim() plt.vlines(xx, ymin, ymax, linestyle='dashed') plt.xlabel('|coef| / max|coef|') plt.ylabel('Coefficients') plt.title('LASSO Path') plt.axis('tight') plt.show()
總結
以上是生活随笔為你收集整理的7.LARS lasso 模型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 6.最小角回归(Least Angle
- 下一篇: 8.正交匹配跟踪 Orthogonal