title: How to get the prediction probabilities using cross validation in scikit-learn
body: <p>I am using <strong><code>RandomForestClassifier</code></strong> as follows using cross validation for a binary classification (class labels are <code>0</code> and <code>1</code>).</p>
  
  <pre class="lang-py prettyprint-override"><code>from sklearn.ensemble import RandomForestClassifier
  from sklearn.model_selection import StratifiedKFold, cross_val_score
  
  clf=RandomForestClassifier(random_state = 42, class_weight="balanced")
  k_fold = StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
  accuracy = cross_val_score(clf, X, y, cv=k_fold, scoring = 'accuracy')
  print("Accuracy: " + str(round(100*accuracy.mean(), 2)) + "%")
  f1 = cross_val_score(clf, X, y, cv=k_fold, scoring = 'f1_weighted')
  print("F Measure: " + str(round(100*f1.mean(), 2)) + "%")
  </code></pre>
  
  <p>Now I want to order my data using prediction probabilities of class <code>1</code> with <code>cross validation</code> results. For that I tried the following two ways.</p>
  
  <pre class="lang-py prettyprint-override"><code>pred = clf.predict_proba(X)[:,1]
  print(pred)
  
  probs = clf.predict_proba(X)
  best_n = np.argsort(probs, axis=1)[:,-6:]
  </code></pre>
  
  <p>I get the following error </p>
  
  <blockquote>
    <p><strong>NotFittedError</strong>: This RandomForestClassifier instance is not fitted
    yet. Call 'fit' with appropriate arguments before using this method.</p>
  </blockquote>
  
  <p>for both the situations.</p>
  
  <p>I am just wondering where I am making things wrong.</p>
  
  <p>I am happy to provide more details if needed.</p>