ZeroInflatedRegression<T>
Models & Types · AiDotNet.Regression
Zero-Inflated regression for count data with excess zeros.
Inheritance: AsyncDecisionTreeRegressionBase<T> → ZeroInflatedRegression<T>
For Beginners
Imagine counting how many times customers visit a store each month:
- Some people NEVER visit (structural zeros) - they live far away or shop elsewhere
- Some people visit sometimes but happened to visit 0 times this month (sampling zeros)
Standard Poisson regression treats all zeros the same, but Zero-Inflated models recognize these two types of zeros:
- The “zero model” predicts WHO are structural zeros (π)
- The “count model” predicts HOW MANY for non-structural-zero people (λ)
Example interpretation:
- “30% of potential customers are ‘never visitors’ (π = 0.3)”
- “Among potential visitors, the average visit rate is 2.5 times/month (λ = 2.5)”
This gives better predictions and allows you to understand both processes.
How It Works
Zero-Inflated models handle count data where there are more zeros than a standard count distribution would predict. They model the data as a mixture: with probability π, the observation is a “structural zero,” and with probability (1-π), it follows a count distribution (Poisson or Negative Binomial).
Reference: Lambert, D. (1992). “Zero-Inflated Poisson Regression, with an Application to Defects in Manufacturing”. Technometrics, 34(1), 1-14.
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 ZeroInflatedRegression<double>())
.ConfigureDataLoader(DataLoaders.FromArrays(features, targets))
.BuildAsync();
Console.WriteLine("Trained ZeroInflatedRegression.");
Constructors
| Constructor | Summary |
|---|---|
ZeroInflatedRegression(ZeroInflatedRegressionOptions options, IRegularization<T, Matrix<T>, Vector<T>> regularization) |
Initializes a new instance of ZeroInflatedRegression. |
Properties
| Property | Summary |
|---|---|
Vector<T> CountCoefficients { get; } |
Gets the count model coefficients. |
Vector<T> ZeroCoefficients { get; } |
Gets the zero-inflation model coefficients. |
int NumberOfTrees { get; } |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |
|
Task TrainAsync(Matrix<T> x, Vector<T> y) |
|
Task<Matrix<T>> PredictPMFAsync(Matrix<T> input, int maxCount) |
Predicts the probability mass function for each sample. |
Task<Vector<T>> PredictAsync(Matrix<T> input) |
|
Task<Vector<T>> PredictConditionalCountAsync(Matrix<T> input) |
Predicts the expected count conditional on not being a structural zero. |
Task<Vector<T>> PredictZeroProbabilityAsync(Matrix<T> input) |
Predicts the probability of being a structural zero for each sample. |