SuperLearner<T>
Models & Types · AiDotNet.Regression
Super Learner (Stacking) ensemble for optimal model combination.
Inheritance: NonLinearRegressionBase<T> → SuperLearner<T>
For Beginners
Super Learner is an ensemble technique that:
- Takes multiple different models (your “library” of algorithms)
- Uses cross-validation to see how well each model predicts
- Learns the best way to combine their predictions
- Creates a final model that’s at least as good as the best individual model
Key advantage: You don’t have to choose which model is best - Super Learner figures that out automatically and combines them optimally.
Example usage:
- Add a linear model (handles linear relationships)
- Add a random forest (handles interactions)
- Add a neural network (handles complex patterns)
- Super Learner learns to use each when appropriate
How It Works
Super Learner combines multiple base models using cross-validated predictions to train an optimal meta-learner. It’s proven to perform at least as well as the best single base learner (oracle inequality).
Example
using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.Regression;
using AiDotNet.Tensors.LinearAlgebra;
double[][] features =
{
new[] { 1.0, 2.0 }, new[] { 2.0, 3.0 }, new[] { 3.0, 4.0 },
new[] { 4.0, 5.0 }, new[] { 5.0, 6.0 }, new[] { 6.0, 7.0 }
};
double[] targets = { 3.0, 5.0, 7.0, 9.0, 11.0, 13.0 };
var result = await new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new SuperLearner<double>())
.ConfigureDataLoader(DataLoaders.FromArrays(features, targets))
.BuildAsync();
Console.WriteLine("Trained SuperLearner.");
Constructors
| Constructor | Summary |
|---|---|
SuperLearner() |
Initializes a new instance with a default base model. |
SuperLearner(IEnumerable<IFullModel<T, Matrix<T>, Vector<T>>> baseModels, SuperLearnerOptions options, IRegularization<T, Matrix<T>, Vector<T>> regularization) |
Initializes a new instance of Super Learner. |
Properties
| Property | Summary |
|---|---|
bool SupportsParameterInitialization { get; } |
SuperLearner is an ensemble that doesn’t support optimizer parameter injection. |
Methods
| Method | Summary |
|---|---|
IEnumerable<int> GetActiveFeatureIndices() |
Returns all features since the ensemble uses sub-models on all features. |
ModelMetadata<T> GetModelMetadata() |
|
Vector<T> GetCVPerformance() |
Gets the cross-validation performance (MSE) of each base model. |
Vector<T> GetMetaWeights() |
Gets the meta-learner weights for each base model. |
Vector<T> GetModelContributions() |
Gets the contribution of each base model based on weights. |
Vector<T> Predict(Matrix<T> input) |
|
void AddBaseModel(IFullModel<T, Matrix<T>, Vector<T>> model) |
Adds a base model to the library. |
void Train(Matrix<T> x, Vector<T> y) |