javapythonjythonscikit-learn

How can I call scikit-learn classifiers from Java?


I have a classifier that I trained using Python's scikit-learn. How can I use the classifier from a Java program? Can I use Jython? Is there some way to save the classifier in Python and load it in Java? Is there some other way to use it?


Solution

  • You cannot use jython as scikit-learn heavily relies on numpy and scipy that have many compiled C and Fortran extensions hence cannot work in jython.

    The easiest ways to use scikit-learn in a java environment would be to:

    The last approach will be a lot more work if you need to re-implement feature extraction in Java as well.

    Finally you can use a Java library such as Weka or Mahout that implement the algorithms you need instead of trying to use scikit-learn from Java.