1

Is it possible to save a predictive model in Python?

Background: I'm building regression models in SPSS and I need to share those when done. Unfortunately, no one else has SPSS.

Idea: My idea is to make the model in Python, do something XYZ, use another library to convert XYZ into and exe that will pick up a csv file with data and spit out the model fit results on that data. In this way, I can share the model with anyone I want without the need of SPSS or other expensive software

Challenge: I need to find out XYZ, how do I save the instance when the model is built. For example, in case of linear/logistic, it would be the set of coefficients.

PS: I'm using linear/logistic as examples, in reality, I need to share more complex models like SVM etc.

Matt
  • 17,290
  • 7
  • 57
  • 71
dsauce
  • 592
  • 2
  • 14
  • 36
  • You can save/load almost any Python object to/from a file using the standard `cPickle` library. If your model is represented as a Python class with lists and dicts and tuples (or even numpy arrays) in it, this should work. It may not be the most efficient way though. – Eser Aygün Oct 30 '13 at 10:48

2 Answers2

2

Using FOSS (Free & Open Source Software) is great to facilitate collaboration. Consider using R or Sage (which has a Python backbone and includes R) so that you can freely share programs and data. Or even use Sagemath Cloud so that you can work collaboratively in real-time.

rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
2

Yes, this is possible. What you're looking for is scitkit-learn in combination with joblib. A working example of your problem can be found in this question.

Community
  • 1
  • 1
Matt
  • 17,290
  • 7
  • 57
  • 71