title: RandomForestClassifier instance not fitted yet. Call 'fit' with appropriate arguments before using this method
body: <p>I am trying to train a decision tree model, save it, and then reload it when I need it later. However, I keep getting the following error: </p>
  
  <blockquote>
    <p>This DecisionTreeClassifier instance is not fitted yet. Call 'fit'
    with appropriate arguments before using this method.</p>
  </blockquote>
  
  <p>Here is my code: </p>
  
  <pre><code>X_train, X_test, y_train, y_test = train_test_split(data, label, test_size=0.20, random_state=4)
  
  names = ["Decision Tree", "Random Forest", "Neural Net"]
  
  classifiers = [
      DecisionTreeClassifier(),
      RandomForestClassifier(),
      MLPClassifier()
      ]
  
  score = 0
  for name, clf in zip(names, classifiers):
      if name == "Decision Tree":
          clf = DecisionTreeClassifier(random_state=0)
          grid_search = GridSearchCV(clf, param_grid=param_grid_DT)
          grid_search.fit(X_train, y_train_TF)
          if grid_search.best_score_ &gt; score:
              score = grid_search.best_score_
              best_clf = clf
      elif name == "Random Forest":
          clf = RandomForestClassifier(random_state=0)
          grid_search = GridSearchCV(clf, param_grid_RF)
          grid_search.fit(X_train, y_train_TF)
          if grid_search.best_score_ &gt; score:
              score = grid_search.best_score_
              best_clf = clf
  
      elif name == "Neural Net":
          clf = MLPClassifier()
          clf.fit(X_train, y_train_TF)
          y_pred = clf.predict(X_test)
          current_score = accuracy_score(y_test_TF, y_pred)
          if current_score &gt; score:
              score = current_score
              best_clf = clf
  
  
  pkl_filename = "pickle_model.pkl"  
  with open(pkl_filename, 'wb') as file:  
      pickle.dump(best_clf, file)
  
  from sklearn.externals import joblib
  # Save to file in the current working directory
  joblib_file = "joblib_model.pkl"  
  joblib.dump(best_clf, joblib_file)
  
  print("best classifier: ", best_clf, " Accuracy= ", score)
  </code></pre>
  
  <p>Here is how I load the model and test it: </p>
  
  <pre><code>#First method
  with open(pkl_filename, 'rb') as h:
      loaded_model = pickle.load(h) 
  #Second method 
  joblib_model = joblib.load(joblib_file)
  </code></pre>
  
  <p>As you can see, I have tried two ways of saving it but none has worked.</p>
  
  <p>Here is how I tested: </p>
  
  <pre><code>print(loaded_model.predict(test)) 
  print(joblib_model.predict(test)) 
  </code></pre>
  
  <p>You can clearly see that the models are actually <strong>fitted</strong> and if I try with any other models such as SVM, or Logistic regression the method works just fine. </p>