0

I am making a project which is based on machine learning, and it uses a list of parameters as input. There are around 3000 such inputs. The algorithms learns the dataset every time I execute the code.

Is there any way, so that, I just run the program of learning the datasets once and use its parameters every time the code is run again?

Vishesh
  • 30
  • 5
  • i think it's unto you how to code your program and run it. you should be able to run the training once and apply the trained models again and again on real data. – Shiping Mar 27 '17 at 19:37
  • You need to serialize the model that was trained. Probaly the easiest way is to use `pickle` – juanpa.arrivillaga Mar 27 '17 at 19:40

2 Answers2

0

That depends very much on your framework, but all the ones I know of do save those trained weights for you to use as a trained model. You need to look in the documentation for the framework you're using. The term for using a model to predict on new data is prediction, inference, or scoring.

For instance, in Caffe, you use the trained model something like this:

./build/tools/caffe test -model models/alexnet/train_val.prototxt 
    -weights alex_trained_iter_500000.caffemodel -iterations 1000

The critical part here is that caffemodel file used for weights.

Does that help?

Prune
  • 76,765
  • 14
  • 60
  • 81
0

I think what you're looking for is pickling, you can achieve that by doing something like this

Save the classifier to disk (after training)

from sklearn.externals import joblib
joblib.dump(clf, 'filename.pkl') 

Load the classifier

clf = joblib.load('filename.pkl')

You can either run your program once, save the pickle and then continue from there. Or check the existence of the pickle file each time the program runs and train the model if it doesn't exist.

from pathlib import Path

my_file = Path("/path/to/file")
if my_file.is_file():

References:

http://scikit-learn.org/stable/modules/model_persistence.html

How do I check whether a file exists using Python?

Community
  • 1
  • 1
martskins
  • 2,920
  • 4
  • 26
  • 52