Machine Learning Model
Purpose
Provides functionality to make predictions using a Machine Learning model trained with Microsoft’s ML.NET Machine Learning and AI Framework.
Type Name
‘ml_model’
Definition Syntax
[model_file] : [dll_file] : [class_name] : [model_yype]
where:
- ‘model_file’ is the name of the saved ML.NET Pipeline .zip file that contains your model (details below)
- ‘dll_file’ is the name of the .NET Dll file that contains the definition for your ML model input class (details below).
- ‘class_name’ is the fully qualified name of the .NET Class that wraps your ML Model prediction class. (details below).
- ‘model_type’ is the model type. Currently, valid values are ‘regression’ or ‘logistic’. If the model type is regression, the ‘Score’ is returned, if ‘logistic’, the ‘Probability’ is returned.
The Model File should be a .Zip file representing the saved ML.NET Pipeline, as saved with the C# command:
’_mlContext.Model.Save(bestModel, data.Schema, modelSaveFilePath);’
The .DLL File should be a .DLL file created using .NET Core 8.0 or later. This should be the build output of a Visual Studio Class Library project. The DLL library should hold the prediction model class that is used in conjunction with your ML.NET model to create the Prediction Engine, as explained for example in this ML.NET tutorial.
Both the Model file (.zip file) and the .DLL file that contains your Model Input class should be placed in a sub-folder named ‘ml’ inside your Cassandra project Work Folder that you specify when you set your work bench.
You can also use a relative path with more sub-folders but the root path will always be assumed to be the ‘ml’ sub-folder of your project working folder.
The specified Class Name should be the name of the C# class that serves as the Prediction Model for your ML.NET model. This should be a fully qualified class name including the Namespace(s) within which the class resides. Thus this should be a name such as:
‘MLSupport.Roads.RoadPredictionModelNZTA’
The class you specify here should implement the Juno Cassandra Interface ‘IMLPredictionModel’. Contact Lonrix for an example of a C# class that implements this inferface. If you specify a class name that does not implement this interface, an error will be thrown at runtime to inform you of this.
Example
‘models/RutMean_untreated.zip : MLSupport.dll : MLSupport.Roads.RoadPredictionModelNZTA : regression’
In this example, our stored model file is called ‘RutMean_untreated.zip’ and the file is assumed to be in the ‘ml/models/’ sub-folder of our working folder (note in the setup code we only specify the second sub-folder ‘models’ since the ‘ml’ parent sub-folder is implicit).
The prediction model class is assumed to be in the file ‘MLSupport.dll’ which is assumed to reside in the ‘ml’ sub-folder within our working folder. This file should be the build output of a Visual Studio .NET Core 8.0 or later class library project.
For this example, the class that implements the Cassandra Interface ‘IMLPredictionModel’ interface is called ‘RoadPredictionModelNZTA’ and this class is in the Namespace ‘MLSupport.Roads’.
The final parameter ‘regression’ indicates that this is a regression model, and thus we will be calling the ‘GetPredictionRegression()’ method of your prediction model class at runtime. If the model was specified as being ‘logistic’ (i.e. logistic regression), Cassandra would call the ‘GetPredictionProbability’ method of the class.
Further Resources
The use of this function is fairly advanced and assumes you have some experience with Visual Studio and C# projects. Unless you are an experienced .NET programmer, we advise that you consult Lonrix to assist with this function if you would like to use it.
If you would like to learn more about Microsoft’s ML.NET Framework, here are links to some resources:
A Tutorial showing all steps of building and testing a Regression Model.