Luke Pitman
Luke Pitman

Reputation: 13

Pycharm: Is there a way to run a snippet of code without running the entire file?

I am teaching myself to code Convolutional Neural Networks. In particular I am looking at the "Dogs vs. Cats" challenge (https://medium.com/@mrgarg.rajat/kaggle-dogs-vs-cats-challenge-complete-step-by-step-guide-part-2-e9ee4967b9). I am using PyCharm.

In PyCharm, is there a way of using the trained model to make a prediction on the test data without having to run the entire file each time (and thus retrain the model each time)? Additionally, is there a way to skip the part of the script that prepares the data for input into the CNN? In a similar manner, does PyCharm store variables- can I print individual variables after the script has been run.

Would it be better if I used a different IDLE?

Upvotes: 0

Views: 559

Answers (1)

Shradha
Shradha

Reputation: 2452

You can use sklearn joblib to save the trained model as a pickle and use it later for predictions.

from sklearn.externals import joblib 

# Save the model as a pickle in a file 
joblib.dump(knn, 'filename.pkl') 

# Load the model from the file 
knn_from_joblib = joblib.load('filename.pkl')  

# Use the loaded model to make predictions 
knn_from_joblib.predict(X_test) 

Upvotes: 0

Related Questions