sklearn.multioutput.RegressorChain?

class sklearn.multioutput.RegressorChain(base_estimator, *, order=None, cv=None, random_state=None)

[源碼]

一種多標簽模型,可將回歸安排到一個鏈中。

每個模型都使用提供給模型的所有可用功能以及鏈中較早的模型的預測,按鏈指定的順序進行預測。

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

0.20版中的新功能。

參數 說明
base_estimator estimator
建立分類器鏈的基礎估計量。
order array-like of shape (n_outputs,) or ‘random’, optional
默認情況下,順序將由標簽矩陣Y中的列順序確定。
order = [0, 1, 2, ..., Y.shape[1] - 1]
可以通過提供整數列表來明確設置鏈的順序。例如,對于長度為5的鏈:
order = [1, 3, 2, 4, 0]
意味著鏈中的第一個模型將對Y矩陣中的第1列進行預測,第二個模型將對第3列進行預測,依此類推。
如果順序是“隨機的”,將使用隨機排序。
cv int, cross-validation generator or an iterable, optional (default=None)
確定是對鏈中以前的估計量的結果使用交叉驗證的預測還是真實的標簽。如果cv為None,則在擬合時使用真實標簽。否則,cv的可能輸入為:
- 整數,用于指定(分層)KFold中的折疊數,
- CV分配器
- 可迭代的數據(訓練,測試)拆分為索引數組。
random_state int, RandomState instance or None, optional (default=None)
如果為order='random',則確定鏈順序的隨機數生成。另外,它控制base_estimator 在每個鏈式迭代中每次給出的隨機種子。因此,僅在base_estimator 暴露時使用random_state。為多個函數調用傳遞可重復輸出的int值。請參閱詞匯表
屬性 說明
estimators_ list
base_estimator的克隆列表。
order_ list
標簽在分類器鏈中的順序。

另見

ClassifierChain

相當于分類

MultioutputRegressor

獨立學習每個輸出,而不是鏈接

方法 說明
fit(X, Y, **fit_params) 使模型擬合數據矩陣X和目標Y。
get_params([deep]) 獲取此估計量的參數。
predict(X) 使用ClassifierChain模型預測數據矩陣X。
score(X, y[, sample_weight]) 返回預測的確定系數R ^ 2。
set_params(**params) 設置此估算器的參數。
__init__(base_estimator, *, order=None, cv=None, random_state=None)

[源碼]

初始化self, 請參閱help(type(self))以獲得準確的說明。

fit(X, Y, **fit_params)

[源碼]

使模型擬合數據矩陣X和目標Y。

參數 說明
X {array-like, sparse matrix}, shape (n_samples, n_features)
輸入數據。
Y array-like, shape (n_samples, n_classes)
目標值。
**fit_params dict of string -> object
fit在回歸鏈的每個步驟傳遞給方法的參數。
返回值 說明
self object
get_params(deep=True)

[源碼]

獲取此估計量的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算器和作為估算器的所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
predict(X)

[源碼]

使用ClassifierChain模型預測數據矩陣X。

參數 說明
X {array-like, sparse matrix}, shape (n_samples, n_features)
輸入數據。
返回值 說明
Y_pred array-like, shape (n_samples, n_classes)
預測值。
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的期望值的恒定模型將獲得0.0的R ^ 2分數。

參數 說明
X array-like of shape (n_samples, n_features)
測試樣本。對于某些估計量,這可能是一個預先計算的核矩陣或泛型對象列表,shape=(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
self.predict(X) wrt. y.的R^2

調用score回歸器時使用的R2得分multioutput='uniform_average'從0.23版開始使用 ,r2_score已與默認值保持一致。這會影響score所有多輸出回歸變量的方法(除外 MultiOutputRegressor)。

set_params(**params)

[源碼]

設置此估算器的參數。

該方法適用于簡單的估計器以及嵌套對象(例如 pipelines)。后者具有形式的參數, <component>__<parameter>以便可以更新嵌套對象的每個組件。

參數 說明
**params dict
估算量參數。
返回值 說明
self object
估算量實例。