sklearn.linear_model.LassoLarsIC?
class sklearn.linear_model.LassoLarsIC(criterion='aic', *, fit_intercept=True, verbose=False, normalize=True, precompute='auto', max_iter=500, eps=2.220446049250313e-16, copy_X=True, positive=False)
使用BIC或AIC進行模型選擇的Lars擬合套索(Lasso)模型
Lasso的優化目標是:
AIC是Akaike信息標準,而BIC是Bayes信息標準。通過在擬合優度和模型復雜度之間進行權衡,這樣的標準對于選擇正則化參數的值很有用。一個好的模型應該在簡單的同時很好地解釋數據。
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
criterion | {‘bic’ , ‘aic’}, default=’aic’ 要使用的標準類型。 |
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矩陣也可以作為參數傳遞。 |
max_iter | int, default=500 要執行的最大迭代次數。可用于提前停止。 |
eps | float, optional Cholesky對角因子計算中的機器精度正則化。對于病態系統,請增加此值。與某些基于迭代優化的算法中的 tol 參數不同,此參數不控制優化的容忍度。默認情況下,使用np.finfo(np.float).eps 。 |
copy_X | bool, default=True 如果 True ,將復制X;否則X可能會被覆蓋。 |
positive | bool, default=False 將系數限制為> =0。請注意,你可能希望刪除默認設置為True時的fit_intercept。在正約束下,對于較小的alpha值,模型系數將不會收斂到普通最小二乘解。通常,逐步Lars-Lasso算法所達到最小alpha值(當fit_path = True, alphas_[alphas_ > 0.].min() )的系數才與坐標下降Lasso估計的解一致。因此,使用LassoLarsIC只對期望達到稀疏解的問題有意義。 |
屬性 | 說明 |
---|---|
coef_ | array-like of shape (n_features,) 參數向量(公式中的w) |
intercept_ | float 決策函數中的截距。 |
alpha_ | float 信息標準選擇的alpha參數 |
n_iter_ | int lars_path運行以查找alpha網格的迭代次數。 |
criteria_like | array-like of shape (n_alphas,) 所有Alpha信息標準(“ aic”,“ bic”)的值。選擇具有最小信息標準的alpha。該值比Eqns. 2.15和2.16中的 n_samples 大1倍(Zou et al, 2007)。 |
另見
注
自由度數的估計為:
“On the degrees of freedom of the lasso” Hui Zou, Trevor Hastie, and Robert Tibshirani Ann. Statist. Volume 35, Number 5 (2007), 2173-2192.
https://en.wikipedia.org/wiki/Akaike_information_criterion https://en.wikipedia.org/wiki/Bayesian_information_criterion
示例
>>> from sklearn import linear_model
>>> reg = linear_model.LassoLarsIC(criterion='bic')
>>> reg.fit([[-1, 1], [0, 0], [1, 1]], [-1.1111, 0, -1.1111])
LassoLarsIC(criterion='bic')
>>> print(reg.coef_)
[ 0. -1.11...]
方法
方法 | 說明 |
---|---|
fit (X, y[, copy_X]) |
使用X,y作為訓練數據擬合模型。 |
get_params ([deep]) |
獲取此估計量的參數。 |
predict (X) |
使用線性模型進行預測。 |
score (X, y[, sample_weight]) |
返回預測的確定系數R ^ 2。 |
set_params (**params) |
設置此估算器的參數。 |
__init__(standard ='aic',*,fit_intercept = True,verbose = False,normalize = True,precompute ='auto',max_iter = 500,eps = 2.220446049250313e-16,copy_X = True,positive = False )
初始化self, 請參閱help(type(self))以獲得準確的說明。
fit(X, y, copy_X=None)
[源碼]
使用X,y作為訓練數據擬合模型。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 訓練數據。 |
y | array-like of shape (n_samples,) 目標值。如有必要,將強制轉換為X的數據類型 |
copy_X | bool, default=None 如果設置了此參數,它將覆蓋實例創建時選擇的copy_X。如果 True ,X將被復制;否則X可能會被覆蓋。 |
返回值 | 說明 |
---|---|
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 估計器實例。 |