# Scikit predict_proba output interpretation

I am working with scikit-learn library in python. In the code below, I am predicting probability but I don't know how to read the output.

Testing data

from sklearn.ensemble import RandomForestClassifier as RF
from sklearn import cross_validation

X = np.array([[5,5,5,5],[10,10,10,10],[1,1,1,1],[6,6,6,6],[13,13,13,13],[2,2,2,2]])
y = np.array([0,1,1,0,1,2])


Split the dataset

X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.5, random_state=0)


Calculate the probability

clf = RF()
clf.fit(X_train,y_train)
pred_pro = clf.predict_proba(X_test)
print pred_pro


The output

[[ 1.  0.]
[ 1.  0.]
[ 0.  1.]]


The X_test list contains 3 arrays (I have 6 samples and test_size=0,5) so output has 3 too.

But I am predicting 3 values (0,1,2) so why I am getting only 2 elements in each array?

How should I read the output?

I also noticed, when I modify the number of distinct values in y, number of columns in output is always distinct count of y -1.

• Welcome to CrossValidated. Did you see my answer below? If it solved your question, go ahead and mark it as the correct answer. Otherwise, let me know what's missing and I'll try to clear it up for you. – Ben Nov 3 '15 at 21:09

Take a look at y_train. It is array([0, 0, 1]). This means your split didn't pick up the sample where y=2. So, your model has no idea that the class y=2 exists.
• This is correct. If you set y = np.array([0,2,1,0,1,2]) and random_state=2 you'll now see 3 columns of output – tdc Nov 3 '15 at 16:35
• Run clf.classes_. Columns will be in that order. – Ben Nov 4 '15 at 14:26
• Just like this: clf.fit(X_train,y_train).classes_? – HonzaB Nov 5 '15 at 12:45
• I think that'll work but you can just run clf.classes_ after you run clf.fit(X_train,y_train) – Ben Nov 5 '15 at 15:49