sklearn.ensemble.AdaBoostRegressor?
class sklearn.ensemble.AdaBoostRegressor(base_estimator=None, *, n_estimators=50, learning_rate=1.0, loss='linear', random_state=None)
一個AdaBoost的回歸器。
AdaBoost[1]回歸器是一個元估計器,它首先在原始數據集上擬合一個回歸器,然后在同一數據集上擬合回歸器的額外副本,但是實例的權重會根據當前預測的誤差進行調整。因此,隨后的回歸更側重于困難的案例。
這個類實現的算法稱為AdaBoost.R2 [2]。
在用戶指南中獲取更多內容。
0.14版本中新增內容。
參數 | 說明 |
---|---|
base_estimator | object, default = None 建立增強集成的基礎估計器。如果沒有,那么基礎估計器是 DecisionTreeRegressor(max_depth=3) 。 |
n_estimators | int, default = 50 終止推進的估計器的最大數目。如果完全擬合,學習過程就會提前停止。 |
learning_rate | float, default = 1 學習率通過 learning_rate 縮小每個分類器的貢獻程度。learning_rate 和n_estimators 之間存在權衡關系。 |
loss | {'linear', 'square', exponential}, default = 'linear' 每次增強迭代后,更新權重時,會用到損失函數。 |
random_state | int or RandomState, default = None 控制每個 base_estimator 在每個增強迭代中給定的隨機種子。因此,僅在base_estimator 引入random_state 時使用它。在多個函數調用之間傳遞可重復輸出的整數。見術語表。 |
屬性 | 說明 |
---|---|
base_estimateor_ | estimator 用于增長集成的基礎估計器。 |
extimators_ | list of classsifiers 擬合的次估計器的集合。 |
estimator_weights_ | ndarray of floats 在增強的集合中每個估計器的權重。 |
estimator_errors_ | ndarray of floats 每個估計器在增強集成中的分類誤差。 |
feature_importances_ | ndarray of shape (n_features, ) 基于雜質的特征重要性。 |
另見:
參考文獻
R0c261b7dee9d-1 Y. Freund, R. Schapire, “A Decision-Theoretic Generalization of on-Line Learning and an Application to Boosting”, 1995.
R0c261b7dee9d-2 Drucker, “Improving Regressors using Boosting Techniques”, 1997.
實例:
>>> from sklearn.ensemble import AdaBoostRegressor
>>> from sklearn.datasets import make_regression
>>> X, y = make_regression(n_features=4, n_informative=2,
... random_state=0, shuffle=False)
>>> regr = AdaBoostRegressor(random_state=0, n_estimators=100)
>>> regr.fit(X, y)
AdaBoostRegressor(n_estimators=100, random_state=0)
>>> regr.predict([[0, 0, 0, 0]])
array([4.7972...])
>>> regr.score(X, y)
0.9771...
方法
方法 | 說明 |
---|---|
fit (self, X, y[, sample_weight]) |
自訓練集(X,y)建立一個增強的回歸器 |
get_params (self[, deep]) |
獲得這個估計器的參數 |
predict (self, X) |
預測X的回歸值 |
score (self, X, y[, sample_weight]) |
返回預測的決定系數R^2 |
set_params (self, **params) |
設置當前估計器的參數 |
staged_predict (self, X) |
返回X階段性預測結果 |
staged_score (self, X, y[, sample_weight]) |
返回X,y階段性得分 |
__init__(self, base_estimator=None, *, n_estimators=50, learning_rate=1.0, loss='linear', random_state=None)
初始化的self。請參閱幫助(type(self))以獲得準確的簽名。
property feature_importances_
基于不純的特性重要性。
越高,功能越重要。一個特征的重要性被計算為該特征帶來的標準的(歸一化)總減少量。它也被稱為基尼重要性。
警告: 針對高基數特性(許多唯一值),基于不純的特性重要性可能會引起誤解。作為備選,請參考:sklearn.inspection.permutation_importance
。
返回值 | 說明 |
---|---|
feature_importances_ | ndarray of shape (n_features,) 特征重要性。 |
fit(self, X, y, sample_weight=None)
自訓練集(X,y)建立一個增強的回歸器。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_sample, n_features) 為訓練輸入樣本。稀疏矩陣可以是CSC, CSR, COO, DOK, LIL。COO, DOK和LIL被轉換為CSR。 |
y | array-like of shape (n_samples, ) 目標值(非類標簽)。 |
sample_weight | array-like of shape (n_samples, ), default = None 樣本權重。如果沒有,則將樣本權重初始化為 1 / n_samples 。 |
返回值 | 說明 |
---|---|
self | object |
get_params(self, deep=True)
得到當前估計器的參數。
參數 | 說明 |
---|---|
deep | bool, default = True 如果為真,將返回此估計器的參數以及包含作為估計器的子對象。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 名稱參數及他們所映射的值。 |
predict(self, X)
預測X的分類。
對輸入樣本的預測類別進行計算,作為分類器在集成中的加權平均預測。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 為訓練輸入樣本。稀疏矩陣可以是CSC, CSR, COO, DOK, LIL。COO, DOK和LIL被轉換為CSR。 |
返回值 | 說明 |
---|---|
y | ndarray of shape (n_sample, ) 預測后的回歸值。 |
score(self, 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) 對于一些估計器,這可能會被一個預先計算的內核矩陣或一列通用對象替代,而不是shape= (n_samples, n_samples_fitting),其中n_samples_fitting是用于擬合估計器的樣本數量。 |
y | array-like of shape (n_samples, ) or (n_samples, n_outputs) X的正確值。 |
sample_weight | array-like of shape (n_sample, ), default = None 樣本權重。 |
返回值 | 說明 |
---|---|
score | float self.predict(X)關于 y的決定系數R^2 |
注意:
調用回歸變器的score
時使用的R2 score,與0.23版本的multioutput='uniform_average'中r2_score
的默認值保持一致。這影響了所有多輸出回歸的score
方法(除了MultiOutputRegressor
)。
set_params(self, params)
設置該估計器的參數。
該方法適用于簡單估計器和嵌套對象(如pipline)。后者具有形式為<component>_<parameter>
的參數,這樣就可以更新嵌套對象的每個組件。
參數 | 說明 |
---|---|
**params | dict 估計器參數。 |
返回值 | 說明 |
---|---|
self | object 估計實例。 |
staged_predict(self, X)
返回X階段性的預測。
計算一個輸入樣本的回歸預測值作為分類器在集成中的加權中值進行預測。
該生成器方法在每次增強迭代后生成集成預測,并且因此允許監視,例如確定每次增強后測試集的預測。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_sample, n_features) 訓練輸入樣本。 |
產出 | 說明 |
---|---|
y | generator of ndarray of shape (n_samples, ) 預測后的回歸值。 |
staged_score(self, X, y, sample_weight=None)
返回X,y階段性的分數。
該生成器方法在每次遞增迭代后生成集成分數,因此允許進行監視,比如在每次遞增之后確定測試集上分數。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 為訓練輸入樣本。稀疏矩陣可以是CSC, CSR, COO, DOK, LIL。COO, DOK和LIL被轉換為CSR。 |
y | array-like of shpe (n_sample, ) X的正確標簽。 |
sample_weight | array-like of shape (n_samples, ), default = None 樣本權重。 |
返回值 | 說明 |
---|---|
z | float |