title: Reusing model fitted by cross_val_score in sklearn using joblib
body: <p>I created the following function in python:</p>
  
  <pre><code>def cross_validate(algorithms, data, labels, cv=4, n_jobs=-1):
      print "Cross validation using: "
      for alg, predictors in algorithms:
          print alg
          print
          # Compute the accuracy score for all the cross validation folds. 
          scores = cross_val_score(alg, data, labels, cv=cv, n_jobs=n_jobs)
          # Take the mean of the scores (because we have one for each fold)
          print scores
          print("Cross validation mean score = " + str(scores.mean()))
  
          name = re.split('\(', str(alg))
          filename = str('%0.5f' %scores.mean()) + "_" + name[0] + ".pkl"
          # We might use this another time 
          joblib.dump(alg, filename, compress=1, cache_size=1e9)  
          filenameL.append(filename)
          try:
              move(filename, "pkl")
          except:
              os.remove(filename) 
  
          print 
      return
  </code></pre>
  
  <p>I thought that in order to do cross validation, sklearn had to fit your function.</p>
  
  <p>However, when I try to use it later (f is the pkl file I saved above in <code>joblib.dump(alg, filename, compress=1, cache_size=1e9))</code>:</p>
  
  <pre><code>alg = joblib.load(f)  
  predictions = alg.predict_proba(train_data[predictors]).astype(float)
  </code></pre>
  
  <p>I get no error in the first line (so it looks like the load is working), but then it tells me <code>NotFittedError: Estimator not fitted, call</code>fit<code>before exploiting the model.</code> on the following line.</p>
  
  <p>What am I doing wrong? Can't I reuse the model fitted to calculate the cross-validation? I looked at <a href="https://stackoverflow.com/questions/20483893/keep-the-fitted-parameters-when-using-a-cross-val-score-in-scikits-learn">Keep the fitted parameters when using a cross_val_score in scikits learn</a> but either I don't understand the answer, or it is not what I am looking for. What I want is to save the whole model with joblib so that I can the use it later without re-fitting.</p>