SLearner<T>
Models & Types · AiDotNet.CausalInference
Implements the S-Learner (Single-model learner) for treatment effect estimation.
Inheritance: CausalModelBase<T> → SLearner<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
S-Learner is the simplest meta-learner. It trains a single model that predicts outcomes using both covariates AND the treatment indicator as features. Treatment effects are estimated by comparing predictions with treatment=1 vs treatment=0.
How It Works
How it works:
- Train a single model: Y = f(X, T) where T is the treatment indicator
- For each subject, predict Y₁ = f(X, T=1) and Y₀ = f(X, T=0)
- Treatment effect τ(X) = Y₁ - Y₀
Pros and Cons:
- Pro: Simple, uses all data efficiently
- Pro: Works with any supervised learning method
- Con: May underestimate heterogeneous treatment effects if treatment has small signal
- Con: Regularization may shrink treatment effect toward zero
When to use:
- When you have limited data and can’t afford separate models
- When treatment effects are expected to be relatively homogeneous
- As a baseline to compare against more complex learners
Reference: Künzel et al., “Metalearners for Estimating Heterogeneous Treatment Effects” (2019)
Example
var covariates = new Matrix<double>(new double[,]
{
{ 45, 1 }, { 52, 0 }, { 38, 1 }, { 61, 0 }, { 47, 1 }, { 55, 0 }
});
var treatment = new Vector<int>(new int[] { 0, 1, 0, 1, 0, 1 }); // who was treated
var outcome = new Vector<double>(new double[] { 3.1, 7.2, 2.8, 8.0, 3.4, 7.6 });
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new SLearner<double>(lambda: 0.01))
.Build(covariates, treatment, outcome);
// One effect per person, over the covariates alone.
Vector<double> cate = result.EstimateTreatmentEffect(covariates);
Constructors
| Constructor | Summary |
|---|---|
SLearner(double lambda) |
Creates a new S-Learner. |
SLearner(int maxIterations) |
Creates a new S-Learner. |
Properties
| Property | Summary |
|---|---|
double Lambda { get; } |
Gets the L2 regularization strength. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
|
ValueTuple<T, T> EstimateATE(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) |
|
ValueTuple<T, T> EstimateATT(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) |
|
Vector<T> EstimateCATEPerIndividual(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) |
|
Vector<T> EstimateTreatmentEffect(Matrix<T> features) |
Estimates the Conditional Average Treatment Effect (CATE). |
Vector<T> Predict(Matrix<T> input) |
Standard prediction — returns the predicted outcome for each input row. |
Vector<T> PredictControl(Matrix<T> features) |
Predicts outcome under control. |
Vector<T> PredictTreated(Matrix<T> features) |
Predicts outcome under treatment. |
Vector<T> PredictTreatmentEffect(Matrix<T> x) |
|
void Fit(Matrix<T> features, Vector<T> treatment, Vector<T> outcome) |
Fits the S-Learner model. |