Getting Started with AiDotNet
This guide will help you install AiDotNet and build your first AI model.
Prerequisites
Before installing AiDotNet, ensure you have:
- .NET 10.0 SDK (or .NET 8.0+) (Download)
- (Optional) NVIDIA GPU with CUDA for GPU acceleration
Installation
NuGet Package Manager
dotnet add package AiDotNet
Package Manager Console (Visual Studio)
Install-Package AiDotNet
PackageReference (csproj)
<PackageReference Include="AiDotNet" Version="*" />
Your First Model
Let's build a simple classification model:
using AiDotNet;
using AiDotNet.Classification;
// Sample data
var features = new double[][]
{
new[] { 5.1, 3.5, 1.4, 0.2 },
new[] { 7.0, 3.2, 4.7, 1.4 },
new[] { 6.3, 3.3, 6.0, 2.5 }
};
var labels = new double[] { 0, 1, 2 };
// Build and train
var result = await new AiModelBuilder<double, double[], double>()
.ConfigureModel(new RandomForestClassifier<double>(nEstimators: 100))
.ConfigurePreprocessing() // Auto-applies StandardScaler
.BuildAsync(features, labels);
// Predict using the result object (facade pattern)
var prediction = result.Predict(new[] { 5.9, 3.0, 5.1, 1.8 });
Console.WriteLine($"Predicted class: {prediction}");
Core Concepts
AiModelBuilder
The AiModelBuilder is the main entry point for building models. It uses a fluent API:
var builder = new AiModelBuilder<T, TInput, TOutput>();
Where:
T- Numeric type (usuallydoubleorfloat)TInput- Input data type (e.g.,double[],Tensor<T>)TOutput- Output type (e.g.,double,int)
Configuration Methods
The builder provides many Configure* methods:
| Method | Purpose |
|---|---|
ConfigureModel() |
Set the ML model/algorithm |
ConfigureOptimizer() |
Set the optimizer (for neural networks) |
ConfigurePreprocessing() |
Add data preprocessing steps |
ConfigurePostprocessing() |
Add output postprocessing |
ConfigureCrossValidation() |
Enable cross-validation |
ConfigureGpuAcceleration() |
Enable GPU training |
Building and Training
Call BuildAsync() with your training data:
var result = await builder.BuildAsync(features, labels);
The result contains:
Model- The trained modelCrossValidationResult- CV metrics (if enabled)TrainingMetrics- Training statistics
Next Steps
- Installation Guide - Detailed installation instructions
- Quick Start Tutorial - Build your first model
- Samples - Browse complete examples
GPU Acceleration
To enable GPU training:
builder.ConfigureGpuAcceleration(new GpuAccelerationConfig
{
Enabled = true,
DeviceId = 0 // Use first GPU
});
Requirements:
- NVIDIA GPU with CUDA support
- CUDA Toolkit 11.8+
- cuDNN 8.6+
Need Help?
- GitHub Issues - Report bugs
- GitHub Discussions - Ask questions