I'm following this example on the scikit-learn website to perform a multioutput classification with a Random Forest model.
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=5, n_features=5, n_informative=2, n_classes=2, random_state=1)
y2 = shuffle(y1, random_state=1)
Y = np.vstack((y1, y2)).T
forest = RandomForestClassifier(n_estimators=10, random_state=1)
multi_target_forest = MultiOutputClassifier(forest, n_jobs=-1)
multi_target_forest.fit(X, Y).predict(X)
print(multi_target_forest.predict_proba(X))
From this predict_proba
I get a 2 5x2 arrays:
[array([[ 0.8, 0.2],
[ 0.4, 0.6],
[ 0.8, 0.2],
[ 0.9, 0.1],
[ 0.4, 0.6]]), array([[ 0.6, 0.4],
[ 0.1, 0.9],
[ 0.2, 0.8],
[ 0.9, 0.1],
[ 0.9, 0.1]])]
I was really expecting a n_sample
by n_classes
matrix. I'm struggling to understand how this relates to the probability of the classes present.
The docs for predict_proba
states:
array of shape = [n_samples, n_classes], or a list of n_outputs such arrays if n_outputs > 1.
The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
I'm guessing I have the latter in the description, but I'm still struggling to understand how this relates to my class probabilities.
Furthermore, when I attempt to access the classes_
attribute for the forest
model I get an AttributeError
and this attribute does not exist on the MultiOutputClassifier
. How can I relate the classes to the output?
print(forest.classes_)
AttributeError: 'RandomForestClassifier' object has no attribute 'classes_'