Skip to content

TheSmallPixel/MultiClassTrainerML

MultiClassTrainerML

Train, evaluate, and serve ML.NET multi-class classifiers behind a thin ASP.NET Core API.

build license dotnet stars

What it solves

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.

30-second example

Start the API:

dotnet run --project src/MultiClassTrainerML.Api

Train, 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.

Install

git clone https://github.com/TheSmallPixel/MultiClassTrainerML.git
cd MultiClassTrainerML
dotnet build

Requires the .NET 10 SDK.

Links

Architecture

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.

Development

dotnet build
dotnet test
dotnet run --project src/MultiClassTrainerML.Api

Roadmap

  • Persist trained model to disk
  • Pluggable trainer selection via configuration
  • OpenAPI / Swagger surface

License

MIT -- see LICENSE.

About

Train, evaluate, and serve ML.NET multi-class classifiers behind a thin ASP.NET Core API.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages