Predict Value using ML.NET (Machine Learning)

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

About chanmingman

Since March 2011 Microsoft Live Spaces migrated to Wordpress (http://www.pcworld.com/article/206455/Microsoft_Live_Spaces_Moves_to_WordPress_An_FAQ.html) till now, I have is over 1 million viewers. This blog is about more than 50% telling you how to resolve error messages, especial for Microsoft products. The blog also has a lot of guidance teaching you how to get stated certain Microsoft technologies. The blog also uses as a help to keep my memory. The blog is never meant to give people consulting services or silver bullet solutions. It is a contribution to the community. Thanks for your support over the years. Ming Man is Microsoft MVP since year 2006. He is a software development manager for a multinational company. With 25 years of experience in the IT field, he has developed system using Clipper, COBOL, VB5, VB6, VB.NET, Java and C #. He has been using Visual Studio (.NET) since the Beta back in year 2000. He and the team have developed many projects using .NET platform such as SCM, and HR based applications. He is familiar with the N-Tier design of business application and is also an expert with database experience in MS SQL, Oracle and AS 400.
This entry was posted in .Net, Cloud, Community, Computers and Internet, Data Platform and tagged . Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.