sklearn.linear_model.LassoLars?
class sklearn.linear_model.LassoLars(alpha=1.0, *, fit_intercept=True, verbose=False, normalize=True, precompute='auto', max_iter=500, eps=2.220446049250313e-16, copy_X=True, fit_path=True, positive=False, jitter=None, random_state=None)
套索模型與最小角度回歸,也稱為拉爾斯擬合
它是一個用L1先驗作為正則化器訓練的線性模型。
Lasso的優化目標是:
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
alpha | float, default=1.0 乘以懲罰項的常數。默認為1.0。 alpha = 0 等同于由LinearRegression 對象求解的普通最小二乘。由于數字原因,不建議alpha = 0 與LassoLars對象一起使用。并且你應該首選LinearRegression對象。 |
fit_intercept | bool, default=True 是否計算模型的截距。如果為 False ,則在計算中將不使用截距(即假定數據已經中心化)。 |
verbose | bool or int, default=False 設置日志的詳細程度。 |
normalize | bool, default=Falsefit_intercept 設置為False 時,將忽略此參數。如果為True,則在回歸之前通過減去均值并除以l2-范數來對回歸變量X進行歸一化。如果你希望標準化,請先使用 sklearn.preprocessing.StandardScaler ,然后調用fit 估算器并設置normalize=False 。 |
precompute | bool, ‘auto’ or array-like, default=’auto’ 是否使用預先計算的Gram矩陣來加快計算速度。Gram矩陣也可以作為參數傳遞。對于稀疏輸入,此選項始終是 True 以保持稀疏性。 |
max_iter | int, default=500 要執行的最大迭代次數。 |
eps | float, optional Cholesky對角因子計算中的機器精度正則化。對于病態系統,請增加此值。與某些基于迭代優化的算法中的 tol 參數不同,此參數不控制優化的容忍度。默認情況下,使用np.finfo(np.float).eps 。 |
copy_X | bool, default=True 如果 True ,將復制X;否則X可能會被覆蓋。 |
fit_path | bool, default=True 如果為True,則完整路徑將存儲在 coef_path_ 屬性中。如果針對一個大問題或多個目標計算解決方案,設置fit_path 為False 會導致加速,尤其是對于較小的alpha。 |
positive | bool, default=False 將系數限制為> =0。請注意,你可能希望刪除默認設置為True時的fit_intercept。在正約束下,對于較小的alpha值,模型系數將不會收斂到普通最小二乘解。通常,逐步Lars-Lasso算法所達到最小alpha值(當fit_path = True, alphas_[alphas_ > 0.].min() )的系數才與坐標下降Lasso估計的解一致。 |
jitter | float, default=None 要添加到 y 值的均勻噪聲參數的上限 ,以滿足模型一次計算的假設。可能會對穩定性有所幫助。 |
random_state | int, RandomState instance or None (default) 確定噪聲的隨機數生成模式。為多個函數調用傳遞一個整數來實現重復輸出。請參閱詞匯表。如果 jitter 為None則忽略此參數。 |
屬性 | 說明 |
---|---|
alphas_ | array-like of shape (n_alphas + 1,)|list of n_targets such arrays 每次迭代的最大協方差(絕對值)。 n_alphas 是max_iter 、n_features 或路徑中相關性大于alpha 的節點數,以較小者為準。 |
active_ | list, length = n_alphas|list of n_targets such lists 路徑末尾的活動變量的索引。 |
coef_path_ | array-like of shape (n_features, n_alphas + 1) or list 如果傳遞了一個列表,那么它應該是一個長度為n_targets的數組。沿路徑的系數的變化值。如果 fit_path 參數為False ,則此參數不可用。 |
coef_ | array-like of shape (n_features,) or (n_targets, n_features) 參數向量(目標公式中的w)。 |
intercept_ | float or array-like of shape (n_targets,) 目標函數中的截距。 |
n_iter_ | array-like or int lars_path為每個目標查找alpha網格所花費的迭代次數。 |
另見
示例
>>> from sklearn import linear_model
>>> clf = linear_model.Lasso(alpha=0.1)
>>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])
Lasso(alpha=0.1)
>>> print(clf.coef_)
[0.85 0. ]
>>> print(clf.intercept_)
0.15...>>> from sklearn import linear_model
>>> reg = linear_model.LassoLars(alpha=0.01)
>>> reg.fit([[-1, 1], [0, 0], [1, 1]], [-1, 0, -1])
LassoLars(alpha=0.01)
>>> print(reg.coef_)
[ 0. -0.963257...]
方法
方法 | 說明 |
---|---|
fit (X, y[, Xy]) |
使用X,y作為訓練數據擬合模型。 |
get_params ([deep]) |
獲取此估計器的參數。 |
predict (X) |
使用線性模型進行預測。 |
score (X, y[, sample_weight]) |
返回預測的確定系數R ^ 2。 |
set_params (**params) |
設置此估算器的參數。 |
__init__(alpha=1.0, *, fit_intercept=True, verbose=False, normalize=True, precompute='auto', max_iter=500, eps=2.220446049250313e-16, copy_X=True, fit_path=True, positive=False, jitter=None, random_state=None)
[源碼]
初始化self, 請參閱help(type(self))以獲得準確的說明。
fit(X, y, Xy=None)
[源碼]
使用X,y作為訓練數據擬合模型。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 訓練數據。 |
y | array-like of shape (n_samples,) or (n_samples, n_targets) 目標值。 |
Xy | array-like of shape (n_samples,) or (n_samples, n_targets), default=None Xy = np.dot(XT,y)可以預先計算。僅當預先計算了Gram矩陣時才有用。 |
返回值 | 說明 |
---|---|
self | object 返回估計器實例 |
get_params(deep=True)
獲取此估計量的參數。
參數 | 說明 |
---|---|
deep | bool, default=True 如果為True,則將返回此估算器和所包含子對象的參數。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 參數名稱映射到其值。 |
predict(X)
[源碼]
使用線性模型進行預測。
參數 | 說明 |
---|---|
X | array_like or sparse matrix, shape (n_samples, n_features) 樣本數據 |
返回值 | 說明 |
---|---|
C | array, shape (n_samples,) 返回預測值。 |
score(X, y, sample_weight=None)
[源碼]
返回預測的確定系數R ^ 2。
系數R ^ 2定義為(1- u / v),其中u是殘差平方和((y_true-y_pred)** 2).sum(),而v是總平方和((y_true- y_true.mean())** 2).sum()。可能的最高得分為1.0,并且也可能為負(因為該模型可能會更差)。一個常數模型總是預測y的期望值,而不考慮輸入特征,得到的R^2得分為0.0。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 測試樣本。對于某些估計量,這可以是預先計算的內核矩陣或通用對象列表,形狀為(n_samples,n_samples_fitted),其中n_samples_fitted是用于擬合估計器的樣本數。 |
y | array-like of shape (n_samples,) or (n_samples, n_outputs) X的真實值。 |
sample_weight | array-like of shape (n_samples,), default=None 樣本權重。 |
返回值 | 說明 |
---|---|
score | float 預測值與真實值的R^2。 |
注
調用回歸器中的score
時使用的R2分數,multioutput='uniform_average'
從0.23版開始使用 ,與r2_score
默認值保持一致。這會影響多輸出回歸的score
方法( MultiOutputRegressor
除外)。
set_params(**params)
[源碼]
設置此估計器的參數。
該方法適用于簡單的估計器以及嵌套對象(例如管道)。后者具有形式為 <component>__<parameter>
的參數,這樣就可以更新嵌套對象的每個組件。
參數 | 說明 |
---|---|
**params | dict 估計器參數。 |
返回值 | 說明 |
---|---|
self | object 估計器實例。 |