Reputation: 323
I have a pickle object
for RandomForestClassifier in Python
. I want to use this object in Java to make predictions. Is that possible? As I see, a Python pickle object
can be used in Java
in that way but I'm not sure if it works for a machine learning model.
Edit: I figured out that Pickle is just a "serialized object", which was non-sense to think to use in Java. I had to use the Java classifier implementation from DronovIlya instead of using Python object in Java.
Upvotes: 0
Views: 3014
Reputation: 686
We can use cPickle class from jython
https://javadoc.io/doc/org.python/jython-standalone/2.7.1/org/python/modules/cPickle.html
Upvotes: 0
Reputation: 426
Short answer: NO.
Long answer:
According to python documentation:
The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy. Pickling (and unpickling) is alternatively known as “serialization”, “marshalling,” 1 or “flattening”; however, to avoid confusion, the terms used here are “pickling” and “unpickling”
This means that the given byte stream is only syntactically valid in Python only unless you want to write an object transpiler.
You are approaching your problem in the wrong way. ML model is just a set of coefficients/parameters that you have optimized to get a close approximation of your target variable. You should be able to take that set of coefficients/parameters and use it in any language.
Upvotes: 1