# ML.NET — Cross-Platform Machine Learning Framework for .NET > An open-source machine learning framework by Microsoft that lets .NET developers build, train, and deploy custom ML models without leaving the .NET ecosystem. ## Install Save as a script file and run: # ML.NET — Cross-Platform Machine Learning for .NET ## Quick Use ```bash dotnet add package Microsoft.ML ``` ```csharp var ctx = new MLContext(); var data = ctx.Data.LoadFromTextFile("houses.csv", hasHeader: true, separatorChar: ','); var pipeline = ctx.Transforms.Concatenate("Features", "Size", "Rooms") .Append(ctx.Regression.Trainers.Sdca(labelColumnName: "Price")); var model = pipeline.Fit(data); ``` ## Introduction ML.NET is Microsoft's open-source machine learning framework for .NET developers. It enables classification, regression, anomaly detection, recommendation, and time-series forecasting directly in C# or F# applications without requiring Python or external ML services. ## What ML.NET Does - Trains custom ML models for classification, regression, clustering, anomaly detection, and ranking - Provides AutoML for automatic model selection and hyperparameter tuning - Imports pre-trained ONNX and TensorFlow models for inference in .NET apps - Offers a visual Model Builder tool in Visual Studio for code-free ML development - Runs inference on CPU with no GPU requirement for deployment scenarios ## Architecture Overview ML.NET uses a pipeline-based architecture where data transformations and trainers are chained together. Data flows through an IDataView abstraction that supports lazy evaluation and streaming for large datasets. The framework wraps native libraries for performance-critical operations while exposing a managed C# API. ## Self-Hosting & Configuration - Install via NuGet: `dotnet add package Microsoft.ML` - Add domain-specific packages like `Microsoft.ML.Vision` or `Microsoft.ML.TimeSeries` as needed - Use Model Builder in Visual Studio for guided model training - Deploy trained models as part of ASP.NET Core APIs or Azure Functions - Export models in the ML.NET `.zip` format or consume ONNX models directly ## Key Features - Native .NET integration with no Python dependency for training or inference - AutoML automatically selects the best algorithm and hyperparameters - ONNX model import enables using models trained in PyTorch or TensorFlow - Scales from desktop apps to cloud services with the same codebase - Supports .NET 6+ on Windows, Linux, and macOS ## Comparison with Similar Tools - **scikit-learn** — Python-native with larger algorithm library; ML.NET stays within the .NET ecosystem - **PyTorch/TensorFlow** — Deep learning focused with GPU support; ML.NET targets traditional ML with CPU inference - **Accord.NET** — Older .NET ML library; ML.NET has stronger Microsoft backing and active development - **ONNX Runtime** — Pure inference engine; ML.NET adds training, data pipelines, and AutoML on top ## FAQ **Q: Does ML.NET require a GPU?** A: No, ML.NET runs on CPU. For deep learning with GPU, import ONNX or TensorFlow models. **Q: Can I use ML.NET in production?** A: Yes, ML.NET is used in production at Microsoft for features in Bing, PowerPoint, and Excel. **Q: What data formats does ML.NET support?** A: CSV, TSV, Parquet, SQL databases, and in-memory IEnumerable collections. **Q: How does AutoML work?** A: AutoML tries multiple algorithms and hyperparameter combinations, then returns the best-performing pipeline. ## Sources - https://github.com/dotnet/machinelearning - https://learn.microsoft.com/dotnet/machine-learning --- Source: https://tokrepo.com/en/workflows/asset-bcdbac82 Author: Script Depot