coremltools

Use Core ML to integrate machine learning models into your app. Core ML provides a unified representation for all models. Your app uses Core ML APIs and user data to make predictions, and to train or fine-tune models, all on the user’s device.

Core ML optimizes on-device performance by leveraging the CPU, GPU, and Neural Engine while minimizing its memory footprint and power consumption. Running a model strictly on the user’s device removes any need for a network connection, which helps keep the user’s data private and your app responsive.

Scikit-learn

You can convert a scikit-learn pipeline, classifier, or regressor to Core ML format.

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 as ct
coreml_model = ct.converters.sklearn.convert(
  model, ["bedroom", "bath", "size"], "price")
coreml_model.save('HousePricer.mlmodel')
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 as ct

coreml_model = ct.converters.sklearn.convert(
  model, ["bedroom", "bath", "size"], "price")

For more information, see the API reference.

Updated 5 months ago


Scikit-learn


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.