Reputation: 757
I have trained a LinearSVC in a python script named main.py, for training an image classification algorithm. The model looks like this.
lin_clf = svm.LinearSVC()
lin_clf.fit(feature,g)
I need to use this trained model for predicting image classes in another code. How do i export the genereated model i.e. lin_clf to the other code.
Thank you in advance.
Upvotes: 2
Views: 117
Reputation: 1394
I understand that your "other code" is another python script. In this case, you can certainly use the pickle or shelve modules to write lin_clf to disk in main.py, and to read it from disk in the script that will use the model.
Here is an example showing how to write the lin_clf object to disk using shelve:
import shelve
a = shelve.open("output")
a['lin_clf'] = lin_clf
a.close()
Upvotes: 2