
Whenever we talk about machine learning, AI, we always hear about Python and R languages for leveraging these concepts. Though there are other languages like Scala, Ruby, Julia, do you know that you can achieve your machine learning and AI goals using the .NET Framework?
I’ve worked on the .NET, leveraging C# as code behind language, for the better half of my life. Trust me, it’s a powerful framework, especially when combined with C#. And there was no reason for Microsoft to miss the machine learning bandwagon.
Let’s take a look at how you can utilize machine learning in your .NET projects. But before moving forward, you need to know that you will require Visual Studio 2019 build 16.6.1 and later to do so.
Download & Installation
Go to Programs and Feature in Control Panel
Then, select Visual Studio 2019 and click Change.

Once the Modifying dialog window opens, go to the Individual tab and search for ML. Then select ML.NET Model Builder (Preview)

Then click the Modify button in the bottom-right corner to install the component.
Once the installation is done, start Visual Studio 2019 and go to Tools > Options > Environment > Preview Features. From the list on your right, check Enable ML.NET Model Builder, and click OK.

Now you’re ready to start building your machine learning models.
Sample Project
Let’s create our first machine learning project in Visual Studio.
Start Visual Studio 2019, and create a simple Console App using .NET Framework and the C# language. Let’s name it HelloML.

Then, right-click the project name and go to Add > Machine Learning.

This will start a wizard asking about what scenario you want to achieve using machine learning capabilities. You have a choice of:
- Text Classification
- Value Prediction
- Image Classification
- Recommendation
- Object Detection
For this sample application, lets select Value Prediction, as I have a dataset readily available which I used in my Apartment Pricing: Advance Regression Techniques series.
Click the Scenario, and it will take you to the next screen showing you compute power of your workstation. Click the Next Step button to continue.

Next is a screen to upload your data. From Input dropdown, select File. And then browse your CSV dataset file. You can also choose SQL for this if your data reside in the database.
In the Column to predict field, select the column from the dataset which you want to predict. In the Input Columns field, select the fields you want to train your model to predict the price.
You can also preview your data here. Click the Next Step button to proceed.

Now you can tell how much you want to train your model. You can select this by defining the number of seconds. As per Microsoft, 0 – 10 MB dataset requires to be trained for 10 seconds, and 10 – 100 MB data for 10 minutes. Let’s keep the default value and move forward.
Click Start Training to proceed with model training. The training process will continue for exactly the number of seconds you have defined above.

It will also tell you which machine learning models are trained for your prediction.

Click the Next Step button to move forward.
The next step in the wizard is to evaluate your trained model. ML builder provides you an easy to use interface to test your model by filling in sample data.
The wizard prefilled the data for you to test, but you can provide your sample data and click Predict. This will give you your prediction, in our case, predicted price.

Once you are satisfied with your model, click Next Step to proceed to code generation.
The code generation steps allow you to generate the code for you, which you can utilize in your custom solution.

Click Add to Solution to add the code to your solution file. Visual Studio will create two more projects in your solution, one for the actual model, and another for unit testing.

Conclusion
Now all you need is an idea of an application that can consume your created machine learning model, and you’re ready to take the world, using your favorite Visual Studio and the C# language.
Leave a Reply