2

I've got a trained scikit-learn classifier (Python) and I need to use it into a Java program. I know that I can store my python classifier (clf) as follow:

joblib.dump(clf, 'my_model.pkl', compress=_)

I also know that there is the python-weka-wrapper library with wich we can use weka classifiers in python, but I would to operate in the opposite way. I need a way to load my *.pkl file into a java program, create another classifier (for example using weka API) and initialize it with info contained in this file. Is there a way to do that?

Stefano Sandonà
  • 619
  • 3
  • 9
  • 18

1 Answers1

0

One way to do this is to create a new Weka classifier that only implements the prediction API. The classifier provide a prediction API call that passes along the data to an indirectly executed a Python script that returns predicted results. See http://weka.wikispaces.com/Making+predictions and http://weka.sourceforge.net/doc.stable/weka/classifiers/evaluation/Prediction.html

Kwame
  • 752
  • 7
  • 19
  • Thanks for the reply but I need to use the classifier in an Android application so I can't execute a python script. In http://stackoverflow.com/questions/12738827/how-can-i-call-scikit-learn-classifiers-from-java discussion, someone suggests to "make the python program output the raw numerical parameters learnt at fit time (typically as an array of floating point values) and reimplement the predict function in java". How could I reimplement the predict function from raw datas of classifier? Have you got an idea? – Stefano Sandonà Jul 09 '15 at 21:10