I have a scikit learn RandomForestClassifier that returns 0s and 1s:
X = [ [2,1,1,1], [2,0,2,1], [3,1,1,1] , [3,1,1,1], [3,1,1,1] ]
y = [ 0, 1, 1, 1, 1 ]
rf = RandomForestClassifier(n_estimators=200, max_depth=5)
rf.fit(X, y)
X_test = [ [2, 0, 1, 0], [2,1,1,1] , [3,1,1,1] ]
y_result = rf.predict(X_test)
I can rerun the classifier and get probabilities instead of values replacing with
y_result = rf.predict_proba(X_test)
But how can I get from scikit learn BOTH the result and the probability?
If I cannot get both results in the same run, does it make sense to run the probability and have a threshold, say 0.7, that if the probability is greater than the threshold then the result is 1 ?
predict
andpredict_proba
yourself. $\endgroup$random_state
parameters to set the seed. Another option would be to fork the source code and simply add an extra return argument to thepredict
method since it already callspredict_proba
under the hood. $\endgroup$predict_proba
once and have a threshold, say 0.7, that if the probability is greater than the threshold then the result is X, else is Y? Isn't the 0.7 what's under the hood inpredict
? $\endgroup$predict
they are not using a threshold but are simply selecting the class with the highest score, whether that be 0.7 or 0.2. $\endgroup$