coremltools.converters.libsvm.convert

coremltools.converters.libsvm.convert(model, input_names='input', target_name='target', probability='classProbability', input_length='auto')

Convert a LIBSVM model to Core ML format.

Parameters:
model: a libsvm model (C-SVC, nu-SVC, epsilon-SVR, or nu-SVR)

or string path to a saved model.

input_names: str | [str]

Name of the input column(s). If a single string is used (the default) the input will be an array. The length of the array will be inferred from the model, this can be overridden using the ‘input_length’ parameter.

target: str

Name of the output column.

probability: str

Name of the output class probability column. Only used for C-SVC and nu-SVC that have been trained with probability estimates enabled.

input_length: int

Set the length of the input array. This parameter should only be used when the input is an array (i.e. when ‘input_name’ is a string).

Returns:
model: MLModel

Model in Core ML format.

Examples

# Make a LIBSVM model
>>> import svmutil
>>> problem = svmutil.svm_problem([0,0,1,1], [[0,1], [1,1], [8,9], [7,7]])
>>> libsvm_model = svmutil.svm_train(problem, svmutil.svm_parameter())

# Convert using default input and output names
>>> import coremltools
>>> coreml_model = coremltools.converters.libsvm.convert(libsvm_model)

# Save the CoreML model to a file.
>>> coreml_model.save('./my_model.mlmodel')

# Convert using user specified input names
>>> coreml_model = coremltools.converters.libsvm.convert(libsvm_model, input_names=['x', 'y'])