0

I am trying tune my random forest classifier to maximize the recall . How can I can plot Probability vs Recall in Pandas dataframe.

My current code to print the classification report

from sklearn import metrics
predicted_randomforest = fit_rf.predict_proba(df1)
predictions=pd.DataFrame(predicted_randomforest)
predictions['outcome'] = np.where(predictions[0]>=0.85,0,1)
print(metrics.confusion_matrix(Y_test, predictions['outcome']))
print(np.mean(predictions['outcome'] == Y_test) )
target_names=['Business','Resi']
print(classification_report(Y_test,predictions['outcome'],target_names=target_names))

Output

               precision    recall  f1-score   support

   Business       1.00      0.96      0.98     76742
       Resi       0.73      0.97      0.83      8442

avg / total       0.97      0.96      0.96     85184

I want plot Probability in x -axis and recall value in Y- axis.Any help is appreciated.

Rahul rajan
  • 1,186
  • 4
  • 18
  • 32
  • I'm not sure about your goal? Do you mind to sketch the plot are you looking for? Maybe this [question](https://stackoverflow.com/q/35572000/4819376) could offer you some insight. – rpanai Feb 05 '18 at 11:28
  • @user32185, I want to plot how each change probability ( 0 to 1) class 0 is affecting the change the recall of class 1. In short I want to plot Probabilty values on x - axis and recall value of class 1 in Y axis ( 0 to 1). – Rahul rajan Feb 05 '18 at 11:35
  • It might be worth checking sklearn's roc_curve() - it returns true positve and false positive rate and also probability thresholds and you can plot these. You would need to invoke the .predict_proba() method of your classifier first in order to calculate predicted probabilities and then pass them to roc_curve along with y_test. – KRKirov Feb 05 '18 at 12:42
  • @KRKirov,I have already calculated predict_proba . its der in the code – Rahul rajan Feb 05 '18 at 12:44
  • 1
    OK, so you have done the first step. Have you checked the documentation for roc_curve. This might be close to what you are trying to achieve. http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html – KRKirov Feb 05 '18 at 13:17

0 Answers0