Machine Learning for .NET
ML.NET is a cross-platform open-source machine learning framework which makes machine learning accessible to .NET developers.
ML.NET allows .NET developers to develop their own models and infuse custom machine learning into their applications, using .NET, even without prior expertise in developing or tuning machine learning models.
ML.NET was originally developed in Microsoft Research, and evolved into a significant framework over the last decade and is used across many product groups in Microsoft like Windows, Bing, PowerPoint, Excel and more.
ML.NET enables machine learning tasks like classification (for example: support text classification, sentiment analysis) and regression (for example, price-prediction).
Along with these ML capabilities, this first release of ML.NET also brings the first draft of .NET APIs for training models, using models for predictions, as well as the core components of this framework such as learning algorithms, transforms, and ML data structures.
Installation
ML.NET runs on Windows, Linux, and macOS using .NET Core, or Windows using .NET Framework. 64 bit is supported on all platforms. 32 bit is supported on Windows, except for TensorFlow, LightGBM, and ONNX related functionality.
The current release is 0.8. Check out the release notes and blog post to see what's new.
First, ensure you have installed .NET Core 2.1 or later. ML.NET also works on the .NET Framework 4.6.1 or later, but 4.7.2 or later is recommended.
Once you have an app, you can install the ML.NET NuGet package from the .NET Core CLI using:
dotnet add package Microsoft.ML
or from the NuGet package manager:
Install-Package Microsoft.ML
Or alternatively, you can add the Microsoft.ML package from within Visual Studio's NuGet package manager or via Paket.
Daily NuGet builds of the project are also available in our MyGet feed:
Building
To build ML.NET from source please visit our developers guide.
x64 Debug | x64 Release | |
---|---|---|
Linux | ||
macOS | ||
Windows |
Contributing
We welcome contributions! Please review our contribution guide.
Community
Please join our community on Gitter
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.
Examples
Here's an example of code to train a model to predict sentiment from text samples. (You can find a sample of the legacy API here):
var mlContext = new MLContext();
var reader = mlContext.Data.TextReader(new TextLoader.Arguments
{
Column = new[] {
new TextLoader.Column("SentimentText", DataKind.Text, 1),
new TextLoader.Column("Label", DataKind.Bool, 0),
},
HasHeader = true,
Separator = ","
});
var data = reader.Read(dataPath);
var learningPipeline = mlContext.Transforms.Text.FeaturizeText("SentimentText", "Features")
.Append(mlContext.BinaryClassification.Trainers.FastTree());
var model = learningPipeline.Fit(data);
Now from the model we can make inferences (predictions):
var predictionFunc = model.MakePredictionFunction<SentimentData, SentimentPrediction>(mlContext);
var prediction = predictionFunc.Predict(new SentimentData
{
SentimentText = "Today is a great day!"
});
Console.WriteLine("prediction: " + prediction.Prediction);
A cookbook that shows how to use these APIs for a variety of existing and new scenarios can be found here.
Samples
We have a repo of samples that you can look at.
License
ML.NET is licensed under the MIT license.
.NET Foundation
ML.NET is a .NET Foundation project.
There are many .NET related projects on GitHub.
- .NET home repo - links to 100s of .NET projects, from Microsoft and the community.