[英]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.