4
$\begingroup$

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?

Code:

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

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

| improve this question | | | | |
$\endgroup$
4
$\begingroup$

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
drive.mount('ndrive')
#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.
| improve this answer | | | | |
$\endgroup$
  • $\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$ – Dibakor Barua Jun 27 '19 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$ – vipin bansal Jun 27 '19 at 6:57
  • $\begingroup$ i thought only models could be saved using pickle. Tried it out and it worked. Thanks $\endgroup$ – Dibakor Barua Jun 28 '19 at 12:09
  • $\begingroup$ Welcome and all the best. $\endgroup$ – vipin bansal Jun 28 '19 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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