简体   繁体   English

AttributeError:“ MultiOutputClassifier”对象没有属性“ classes_”

[英]AttributeError: 'MultiOutputClassifier' object has no attribute 'classes_'

I want to get prediction probabilities for each class of each output. 我想获得每个输出的每个类的预测概率。 But the classes_ attribute does not exist on the MultiOutputClassifier . classes_属性上不存在MultiOutputClassifier

How can I relate the classes to the output ? 如何将类与输出关联?

from sklearn.datasets import make_classification
from sklearn.multioutput import MultiOutputClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.utils import shuffle
import numpy as np

X, y1 = make_classification(n_samples=16, n_features=8, n_informative=4, n_classes=4, random_state=1)
y2 = shuffle(y1, random_state=1)
Y = np.vstack((y1, y2)).T

forest = RandomForestClassifier(n_estimators=16, random_state=1)
multi_target_forest = MultiOutputClassifier(forest, n_jobs=-1)
multi_target_forest.fit(X, Y).predict(X)

multi_target_forest.predict_proba(X)
multi_target_forest.classes_

AttributeError: 'MultiOutputClassifier' object has no attribute 'classes_' AttributeError:“ MultiOutputClassifier”对象没有属性“ classes_”

Use estimators_ attribute of MultiOutputClassifier to access the estimator attributes. 使用estimators_的属性MultiOutputClassifier访问估计属性。

Try this! 尝试这个!

['y_{} class_{}'.format(idx,klass) for idx,forest in enumerate(multi_target_forest.estimators_) \
                                    for klass in forest.classes_]


#output:
['y_0 class_0',
 'y_0 class_1',
 'y_0 class_2',
 'y_0 class_3',
 'y_1 class_0',
 'y_1 class_1',
 'y_1 class_2',
 'y_1 class_3']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:'LinearSVC'对象没有属性'classes_' - AttributeError: 'LinearSVC' object has no attribute 'classes_' Scikit learn 的 AttributeError: 'LabelEncoder' 对象没有属性 'classes_'? - Scikit learn's AttributeError: 'LabelEncoder' object has no attribute 'classes_'? 'LinearSVC'对象没有属性'classes_' - 'LinearSVC' object has no attribute 'classes_' SupervisedDBNClassification' object 没有属性 'classes_' - SupervisedDBNClassification' object has no attribute 'classes_' 加载 KerasClassifier 后,在运行 predict() 时出现错误“KerasClassifier”对象没有属性“classes_” - After loading KerasClassifier, on running predict() get error 'KerasClassifier' object has no attribute 'classes_' Python 类( AttributeError: '' object has no attribute '') - Python Classes ( AttributeError: '' object has no attribute '') AttributeError: 'NumpyArrayIterator' object 没有属性 'classes' - AttributeError: 'NumpyArrayIterator' object has no attribute 'classes' IronPython - 带有自定义类的“AttributeError:object has no attribute” - IronPython - “AttributeError: object has no attribute” with custom classes AttributeError: 'AttributeError' object 没有属性 'To' - AttributeError: 'AttributeError' object has no attribute 'To' AttributeError:对象没有属性 - AttributeError: object has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM