Core ML supports models converted from scikit-learn. The coremltools documentation has an example of converting a scikit-learn model. Here is the code from that documentation:
from sklearn.linear_model import LinearRegression import pandas as pd # Load data data = pd.read_csv('houses.csv') # Train a model model = LinearRegression() model.fit(data[["bedroom", "bath", "size"]], data["price"]) # Convert and save the scikit-learn model import coremltools coreml_model = coremltools.converters.sklearn.convert(model, ["bedroom", "bath", "size"], "price") coreml_model.save('HousePricer.mlmodel')
Hope this helps!
Pickle is a Python protocol that is used to seralize arbitary Python code and classes. You should be able to write code to load the scikit-learn model from your pickle file (that code is usually custom to your model) and then you can convert the scikit-learn model to CoreML format using coremltools.
I know how to convert a model to a Core ML model but what I can't figure out is how to write code to load the scikit-learn model from the pickle file. The model I am using comes from this tutorial: http://radimrehurek.com/data_science_python/
At the end of the tutorial: I load the model with this command:
svm_detector_reloaded = cPickle.load(open('sms_spam_detector.pkl'))
What I don't know is how to take this file and turn it into a Scikit-Learn file. Thanks!
Did you ever have any success with this? I also have created a custom model, saved in a pickle file. I now want to bring that file over to COREML so that I can deploy it in a Vision app.