sklearn.multioutput.ClassifierChain?
class sklearn.multioutput.ClassifierChain(base_estimator, *, order=None, cv=None, random_state=None)
[源碼]
將二元分類器排列成一個鏈的多標簽模型。
每個模型都使用鏈中指定的所有可用功能,加上鏈中較早的模型的預測,按鏈指定的順序進行預測。
在用戶指南中閱讀更多內容。
版本0.19中的新功能。
參數 | 說明 |
---|---|
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值。請參閱詞匯表。 |
屬性 | 說明 |
---|---|
classes_ | list 長度數組的列表, len(estimators_) 中包含鏈中每個估計量的類標簽。 |
estimators_ | list base_estimator的克隆列表。 |
order_ | list 標簽在分類器鏈中的順序。 |
另見
等效于回歸
MultioutputClassifier
獨立地對每個輸出分類,而不是鏈接。
參考文獻
1 Jesse Read, Bernhard Pfahringer, Geoff Holmes, Eibe Frank, “Classifier Chains for Multi-label Classification”, 2009.
方法 | 說明 |
---|---|
decision_function (X) |
評估鏈中模型的決策功能。 |
fit (X, Y) |
使模型適合數據矩陣X和目標Y。 |
get_params ([deep]) |
獲取此估計量的參數。 |
predict (X) |
使用ClassifierChain模型預測數據矩陣X。 |
predict_proba (X) |
預測概率估計。 |
score (X, y[, sample_weight]) |
返回給定測試數據和標簽上的平均準確度。 |
set_params (**params) |
設置此估算器的參數。 |
__init__(base_estimator, *, order=None, cv=None, random_state=None)
[源碼]
初始化self, 請參閱help(type(self))以獲得準確的說明。
decision_function(X)
[源碼]
評估鏈中模型的決策功能。
參數 | 說明 |
---|---|
X | array-like, shape (n_samples, n_features) |
返回值 | 說明 |
---|---|
Y_decision | array-like, shape (n_samples, n_classes ) 返回鏈中每個模型的樣本決策函數。 |
fit(X, Y)
[源碼]
使模型擬合數據矩陣X和目標Y。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix}, shape (n_samples, n_features) 輸入數據。 |
Y | **array-like, shape (n_samples, n_classes)**目標值。 |
返回值 | 說明 |
---|---|
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) 預測值。 |
predict_proba(X)
[源碼]
預測概率估計。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix}, shape (n_samples, n_features) |
返回值 | 說明 |
---|---|
Y_prob | array-like, shape (n_samples, n_classes) |
score(X, y, sample_weight=None)
[源碼]
返回給定測試數據和標簽上的平均準確度。
在多標簽分類中,這是子集準確性,且是一個苛刻的指標,因為您需要為每個樣本正確預測每個標簽集。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 測試樣本。 |
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.的平均準確度。 |
set_params(**params)
[源碼]
設置此估算器的參數。
該方法適用于簡單的估計器以及嵌套對象(例如 pipelines)。后者具有形式的參數, <component>__<parameter>
以便可以更新嵌套對象的每個組件。
參數 | 說明 |
---|---|
**params | dict 估算量參數。 |
返回值 | 說明 |
---|---|
self | object 估算量實例。 |