sklearn.linear_model.ARDRegression?
class sklearn.linear_model.ARDRegression(*, n_iter=300, tol=0.001, alpha_1=1e-06, alpha_2=1e-06, lambda_1=1e-06, lambda_2=1e-06, compute_score=False, threshold_lambda=10000.0, fit_intercept=True, normalize=False, copy_X=True, verbose=False)
貝葉斯ARD回歸。
使用ARD先驗擬合回歸模型的權重。回歸模型的權重假定服從高斯分布。還要估計參數lambda(權重分布的精度)和alpha(噪聲分布的精度)。通過迭代過程(證據最大化)進行估算。
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
n_iter | int, default=300 最大迭代次數。 |
tol | float, default=1e-3 如果w收斂,則停止算法。 |
alpha_1 | float, default=1e-6 超參數:高于alpha參數的Gamma分布的形狀參數。 |
alpha_2 | float, default=1e-6 超參數:優先于alpha參數的Gamma分布的反比例參數(速率參數)。 |
lambda_1 | float, default=1e-6 超參數:高于lambda參數的Gamma分布的形狀參數。 |
lambda_2 | float, default=1e-6 超參數:優先于lambda參數的Gamma分布的反比例參數(速率參數)。 |
compute_score | bool, default=False 如果為True,則計算模型每一步的目標函數。 |
threshold_lambda | float, default=10000 從計算中高精度刪除(修剪)權重的閾值。 |
fit_intercept | bool, default=True 是否計算該模型的截距。如果設置為false,則在計算中將不使用截距(即,數據應居中)。 |
normalize | bool, default=Falsefit_intercept 設置為False 時,將忽略此參數。如果為True,則在回歸之前通過減去均值并除以l2-范數來對回歸變量X進行歸一化。如果你希望標準化,請先使用 sklearn.preprocessing.StandardScaler ,然后調用fit 估算器并設置normalize=False 。 |
copy_X | bool, default=True 如果為True,將復制X;否則X可能會被覆蓋。 |
verbose | bool, default=False 擬合模型時的詳細模式。 |
屬性 | 說明 |
---|---|
coef_ | array-like of shape (n_features,) 回歸模型的系數(分布的均值) |
alpha_ | float 估計的噪聲精度。 |
lambda_ | array-like of shape (n_features,) 權重的估計精度。 |
sigma_ | array-like of shape (n_features, n_features) 權重的估計方差-協方差矩陣 |
scores_ | float 若計算,目標函數的值(待最大化) |
intercept_ | float 決策函數中的截距。如果 fit_intercept = False 則設置為0.0 。 |
注
有關示例,請參見examples / linear_model / plot_ard.py。
參考
D. J. C. MacKay, Bayesian nonlinear modeling for the prediction competition, ASHRAE Transactions, 1994.
R. Salakhutdinov, Lecture notes on Statistical Machine Learning, http://www.utstat.toronto.edu/~rsalakhu/sta4273/notes/Lecture2.pdf#page=15 Their beta is our self.alpha_
Their alpha is our self.lambda_
ARD is a little different than the slide: only dimensions/features for which self.lambda_ < self.threshold_lambda
are kept and the rest are discarded.
示例
>>> from sklearn import linear_model
>>> clf = linear_model.ARDRegression()
>>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])
ARDRegression()
>>> clf.predict([[1, 1]])
array([1.])
方法
方法 | 說明 |
---|---|
fit (X, y) |
根據給定的訓練數據和參數擬合ARDRegression模型。 |
get_params ([deep]) |
獲取此估計量的參數。 |
predict (X[, return_std]) |
使用線性模型進行預測。 |
score (X, y[, sample_weight]) |
返回預測的確定系數R ^ 2。 |
set_params (**params) |
設置此估算器的參數。 |
__init__(*,n_iter = 300,tol = 0.001,alpha_1 = 1e-06,alpha_2 = 1e-06,lambda_1 = 1e-06,lambda_2 = 1e-06,compute_score = False,threshold_lambda = 10000.0,fit_intercept = True,normalize = False,copy_X = True,verbose = False )
初始化self, 請參閱help(type(self))以獲得準確的說明。
fit(X, y)
[源碼]
根據給定的訓練數據和參數擬合ARD回歸模型。
迭代程序以最大化證據。
參數 | 說明 |
---|---|
X | array-like, shape [n_samples, n_features] 訓練數據,其中n_samples是樣本數量,n_features是特征數量。 |
y | array-like, shape [n_samples] 目標值(整數)。如有必要,將強制轉換為X的數據類型。 |
返回值 | 說明 |
---|---|
self | returns an instance of self. |
get_params(deep=True)
[源碼]
獲取此估計量的參數。
參數 | 說明 |
---|---|
deep | bool, default=True 如果為True,則將返回此估算器和所包含子對象的參數。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 參數名稱映射到其值。 |
predict(X, return_std=False)
[源碼]
使用線性模型進行預測。
除了預測分布的平均值外,還可以返回其標準偏差。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 樣本數據 |
return_std | bool, default=False 是否返回后驗預測的標準差。 |
返回值 | 說明 |
---|---|
y_mean | array-like of shape (n_samples,) 查詢點的預測分布平均值。 |
y_std | array-like of 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 估計器實例。 |