Train, evaluate, and serve ML.NET multi-class classifiers behind a thin ASP.NET Core API.
Microsoft.ML samples are notebook-style and don't show how to expose a model lifecycle (train -> evaluate -> predict) over HTTP. This repo is the smallest end-to-end example: one controller, one trainer, one client.
Start the API:
dotnet run --project src/MultiClassTrainerML.ApiTrain, then predict:
# Train on a batch of {Label: uint, Features: float[20]} rows.
curl -X POST http://localhost:5000/api/Learn \
-H "Content-Type: application/json" \
-d '[{"Label":1,"Features":[0.1,0.2, /* 18 more floats */]}, ...]'
# Predict on new rows -- returns [{Label, PredictedLabel}, ...].
curl -X POST http://localhost:5000/api/Test \
-H "Content-Type: application/json" \
-d '[{"Label":0,"Features":[0.3,0.4, /* 18 more floats */]}]'A runnable C# client lives in samples/MultiClassTrainerML.SampleClient.
git clone https://github.com/TheSmallPixel/MultiClassTrainerML.git
cd MultiClassTrainerML
dotnet buildRequires the .NET 10 SDK.
src/MultiClassTrainerML.Api ASP.NET Core minimal-host service
Controllers/ApiController.cs /api/{Get, Learn, Test}
Services/IDataService.cs public train/test/evaluate contract
Services/DataService.cs singleton holding model + training view
Services/Pipeline.cs SDCA Maximum Entropy multi-class pipeline
Data/{TrainData, ModelOutput}.cs request and prediction shapes
samples/MultiClassTrainerML.SampleClient console client driving the API
tests/MultiClassTrainerML.Tests xUnit + WebApplicationFactory
The default trainer is SdcaMaximumEntropy with ConvergenceTolerance = 0.05 and 30 iterations. Swap it in Services/Pipeline.cs.
State is kept in-process in a singleton DataService. Calls are serialised by a SemaphoreSlim, so the service is safe for one trainer at a time -- it is not a multi-tenant model server.
dotnet build
dotnet test
dotnet run --project src/MultiClassTrainerML.Api- Persist trained model to disk
- Pluggable trainer selection via configuration
- OpenAPI / Swagger surface
MIT -- see LICENSE.