In the preceding section, we created our model to classify the messages as spam and non-spam. Now, let's convert that into the Core ML model so that we can use that in an IOS app.
To create a core-ML model, append the following lines to the preceding code and run them. This will create a .mlmodel file:
# importing the library
import coremltools
# convert to fitted model in to coreml model
coreml_model = coremltools.converters.sklearn.convert(text_clf, "message", "spam_or_not")
#set parameters of the model
coreml_model.short_description = "Classify whether message is spam or not"
coreml_model.input_description["message"] = "TFIDF of message to be classified"
coreml_model.output_description["spam_or_not"] = "Whether message is spam or not"
#save the model
coreml_model.save("SpamMessageClassifier.mlmodel")
Now, you can take the generated SpamMessageClassifier.mlmodel file and use this in your Xcode.