I have created sklearn model for predicting ESG Scores. But for imputation reasons my input features matrix X were converted to np.ndarray. I found on apple developers website how to convert them, but there is optional kwargs input_features and output_features.
import coremltools
coreml_model = coremltools.converters.sklearn.convert(model,
["bedroom", "bath", "size"],
"price")
coreml_model.save('HousePricer.mlmodel')
I am wondering is it necessary match names of features in X with value I am sending to convert() method with input_features argument?
I.e.
imputer = KNNImputer()
# Impute missing values in X
X_imputed = imputer.fit_transform(X)
X_imputed
Out:
array([[ 5.00000e+00, 1.80000e+04, 3.27000e+08, ..., -2.20000e+07,
2.64000e+08, 2.64000e+08],
[ 6.00000e+00, 1.32500e+05, 9.00000e+06, ..., 9.38000e+08,
1.90000e+07, 1.90000e+07],
[ 2.00000e+00, 4.00000e+04, 2.37765e+08, ..., -1.88580e+07,
1.78696e+08, 1.78696e+08],
...,
])
So there are no labels now.
The question is how to convert it to Core ML Model now, with no labels for input_features.
Unfortunately I don't have access to macOS to try different approaches and test them.
I would be grateful if you showed not only how to convert but also sample usage of the model with Swift.
(Model based on Random Forest Regressor)
There is dedicated method called
ct.converters.sklearn.convertfor this goal.Here is a full example of the conversion:
Printing
coreml_modelyou get: