sklearn.linear_model.lars_path?
sklearn.linear_model.lars_path(X, y, Xy=None, *, Gram=None, max_iter=500, alpha_min=0, method='lar', copy_X=True, eps=2.220446049250313e-16, copy_Gram=True, verbose=0, return_path=True, return_n_iter=False, positive=False)
[源碼]
使用LARS算法計算最小角度回歸或套索(Lasso)路徑[1]
在method=“ lars”的情況下優化目標是:
在method=“ lars”的情況下,僅以隱式方程的形式知道目標函數(請參見[1]中的討論)
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
X | None or array-like of shape (n_samples, n_features) 輸入數據。注意,如果X為None,則必須指定Gram矩陣,即不能為None或False。 |
y | None or array-like of shape (n_samples,) 輸入目標。 |
Xy | array-like of shape (n_samples,) or (n_samples, n_targets), default=None Xy = np.dot(XT,y)可以預先計算。僅當預先計算了Gram矩陣時才有用。 |
Gram | None, ‘auto’, array-like of shape (n_features, n_features), default=None 預計算的Gram矩陣(X'* X),如果設為 'auto' ,則從給定的X預計算Gram矩陣,如果樣本多于特征。 |
max_iter | int, default=500 要執行的最大迭代次數,設置為無窮大,沒有限制。 |
alpha_min | float, default=0 沿路徑的最小相關性。它對應于Lasso中的正則化參數alpha參數。 |
method | {‘lar’, ‘lasso’}, default=’lar’ 指定返回的模型。 'lar' 為Least Angle Regression,'lasso' 為Lasso。 |
copy_X | bool, default=True 如果 False ,則覆蓋X 。 |
eps | float, optional Cholesky對角因子計算中的機器精度正則化。對于條件非常差的系統,可以增加這個值。默認情況下,使用 np.finfo(np.float).eps 。 |
copy_Gram | bool, default=True 如果 False ,則覆蓋Gram 。 |
verbose | int, default=0 控制輸出的詳細程度。 |
return_path | bool, default=True 如果 return_path==True 則返回整個路徑,否則僅返回路徑的最后一點。 |
return_n_iter | bool, default=False 是否返回迭代次數。 |
positive | bool, default=False 將系數限制為> =0。僅在方法“Lasso”中允許使用這個選項。請注意,對于較小的alpha值,模型系數不會收斂到普通最小二乘解。通常,逐步Lars-Lasso算法所達到的系數只有最小的alpha值(當fit_path = True時, alphas_[alphas_ > 0.].min() )才與坐標下降lasso_path函數的解一致。 |
返回值 | 說明 |
---|---|
alphas | array-like of shape (n_alphas + 1,) 每次迭代的最大協方差(絕對值)。 n_alphas 是max_iter 、n_features 或節點中的路徑的數alpha >= alpha_min ,較小的那個。 |
active | array-like of shape (n_alphas,) 路徑末尾的活動變量的索引。 |
coefs | array-like of shape (n_features, n_alphas + 1) 沿著路徑的系數 |
n_iter | int 運行的迭代次數。僅當return_n_iter設置為True時才返回。 |
另見:
lasso_path_gram
參考
1 “Least Angle Regression”, Efron et al. http://statweb.stanford.edu/~tibs/ftp/lars.pdf
2 Wikipedia entry on the Least-angle regression 3 [Wikipedia entry on the Lasso](https://en.wikipedia.org/wiki/Lasso_(statistics)