I have to execute GridSearchCV() cell every time I reload the page and it takes a lot of time. Is there a caching mechanism which stores the GridSearchCV result so that I can use it without executing the cell on the reload?


 neigh_clf = KNeighborsClassifier()
 grid_search = GridSearchCV(neigh_clf, param_grid, cv=5,verbose=3,n_jobs=-1)
 grid_search.fit(X_train, y_train)

I am trying to save grid_search object here so that I can retrieve best_params_ value after reload


1 Answer 1


We can save the trained model or any other file via Google Colaboratory.

How I'm using it?

I have mapped my Google Drive with Google Colaboratory notebook and saved trained model as a pickle file in it. You can create a file and save your data in it.

How to integrate Google Drive with Google Colaboratory notebook?

#Add and execute below mentioned line of code in Google colaboratory notebook cell.
from google.colab import drive
#Once you execute these two lines, it will ask you to authorize it. Please follow the steps as visible on the Google Colaboratory Notebook.

That's it :).

Few important points:

  1. Now you can run usual linux command to browse the directories.
  2. By default it mapped to content folder and you can create sub directories in it.
  3. You can visit these sub-directories via Google-Drive application as well.
  • $\begingroup$ I have updated the description with the code. I am trying to save grid_search object so that I can retrieve best_params_ object. Pickle doesnot work for grid_search and pickling neigh_clf doesnt give me best_params_ $\endgroup$ Jun 27, 2019 at 5:47
  • $\begingroup$ I'm not sure if I understood that part clearly, but using pickle you can dump anything you want. For example: f1 = open("attribute.pkl","wb") pk.dump(grid_search.best_params_, f1), or event best KNN model i.e. f2 = open("Knn.pkl","wb") pk.dump(grid_search.estimator, f2) $\endgroup$ Jun 27, 2019 at 6:57
  • $\begingroup$ i thought only models could be saved using pickle. Tried it out and it worked. Thanks $\endgroup$ Jun 28, 2019 at 12:09
  • $\begingroup$ Welcome and all the best. $\endgroup$ Jun 28, 2019 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.