This blog article shows you how to predict value using ML.NET, Machine Learning. Readers are required C# knowledge for this. Firstly, create a Console Project in Visual Studio. Select Console App then click Next.
Type in the name of the project, for example, ConAppTaxi, click Next.
For this example, I select .NET 5.0. Click Create.
Right click the Project and select Add. Then select Machine Learning Model…
Here I use the default name MLModel1.mbconfig. Click Add.
We like to predict the value so we choose Value prediction for the scenario.
Sudden version of Visual Studio might pop up error. I believe is a bug, just click Close.
Select Local (CPU). Click Next step.
Click Browse… to browse the data file. I have downloaded from the link How do I get sample datasets and learn more?
Once browsed to the data. Select the Column to predict, here I have chosen fare_amount because we want to predict fare. Click on Advanced data options (I do this to ignore some of the columns).
I have ignored the first 3 columns. Then click Save. Click Next step.
Put the training time you want to train the model. I normally put 60.
After training the model you can then click Predict to test on the production. Click Next step.
Copy the codee
Paste to Program.cs as the following.
static void Main(string[] args)
{
//Load sample data
var sampleData = new MLModel1.ModelInput()
{
//Vendor_id = @”CMT”,
//Rate_code = 1F,
//Passenger_count = 1F,
Trip_time_in_secs = 474F,
Trip_distance = 1.5F,
Payment_type = @”CRD”,
};
//Load model and predict output
var result = MLModel1.Predict(sampleData);
Console.WriteLine(“The predicted fare is {0}”, result.Score);
}
You can run the program and see the predicted result.
Source code download: ML.NET/ConAppTaxi at master · chanmmn/ML.NET (github.com)
Video: https://youtu.be/tjNx9nT9aLQ
Reference: https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/?WT.mc_id=DP-MVP-36769