Exporting ML.NET models
Recall that machine learning models take time to train, even if you know the exact model trainer and hyperparameters you intend to use.
Once a model is trained, the model takes only a small fraction of the training time to generate its predictions. Thankfully, we can take our trained models in ML.NET and export them to a file. This is done via the Save
method on the context’s model catalog, as shown by the following code:
context.Model.Save(model: model, inputSchema: split.TrainSet.Schema, filePath: "MyModel.zip");
This code takes an ITransformer
(here, that’s the model
variable) and saves it to the disk. ML.NET also needs to know the format or schema of the data the model takes in. Thankfully, we have this schema in our DataFrame, as well as both partitions of our train/test split. Here, we’re using the Schema from the TrainSet
for convenience, but all three should...