sklearn.linear_model.Lars?

class sklearn.linear_model.Lars(*, fit_intercept=True, verbose=False, normalize=True, precompute='auto', n_nonzero_coefs=500, eps=2.220446049250313e-16, copy_X=True, fit_path=True, jitter=None, random_state=None)

[源碼]

最小角度回歸模型,又稱LAR。

用戶指南中閱讀更多內容。

參數 說明
fit_intercept bool, default=True
是否計算此模型的截距。如果設置為False,則在計算中將不使用截距(即,數據應居中)。
verbose bool or int, default=False
詳細程度
normalize bool, default=True
fit_intercept設置為False 時,將忽略此參數。如果為True,則在回歸之前通過減去均值并除以l2-范數來對回歸變量X進行歸一化。如果你希望標準化,請先使用 sklearn.preprocessing.StandardScaler,然后調用fit 估算器并設置normalize=False
precompute bool, ‘auto’ or array-like , default=’auto’
是否使用預先計算的Gram矩陣來加快計算速度。Gram矩陣也可以作為參數傳遞。
n_nonzero_coefs int, default=500
非零系數的目標數量。使用np.inf時無限制。
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_pathFalse會導致加速,尤其是對于較小的alpha。
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_alphasn_nonzero_coefsn_features,以較小者為準。
active_ list, length = n_alphas|list of n_targets such lists
路徑末尾的活動變量的索引。
coef_path_ array-like of shape (n_features, n_alphas + 1)|list of n_targets such arrays
沿路徑的系數的變化值。如果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
>>> reg = linear_model.Lars(n_nonzero_coefs=1)
>>> reg.fit([[-11], [00], [11]], [-1.11110-1.1111])
Lars(n_nonzero_coefs=1)
>>> print(reg.coef_)
0. -1.11...]

方法

方法 說明
fit(X, y[, Xy]) 使用X,y作為訓練數據擬合模型。
get_params([deep]) 獲取此估計器的參數。
predict(X) 使用線性模型進行預測。
score(X, y[, sample_weight]) 返回預測的確定系數R ^ 2。
set_params(**params) 設置此估算器的參數。
__init__(*, fit_intercept=True, verbose=False, normalize=True, precompute='auto', n_nonzero_coefs=500, eps=2.220446049250313e-16, copy_X=True, fit_path=True, 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
估計器實例。