ElasticNetRegression class

Implements Elastic Net Regression, a type of regularized linear regression that includes both L1 and L2 penalty terms.

The regularization parameter alpha controls the strength of the penalty terms, and l1Ratio controls the mix between L1 and L2 regularization. When l1Ratio equals 0, the penalty is an L2 penalty, and when it equals 1, the penalty is an L1 penalty.

As of the last update in September 2021, this functionality is not straightforward to implement with simple matrix operations, and typically requires optimization algorithms like coordinate descent or LARS which are not implemented in this code base.

// Example usage:
var A = Matrix.fromList([[1, 2], [3, 4], [5, 6]]);
var b = ColumnMatrix([7, 8, 9]);
var alpha = 0.1;
var l1Ratio = 0.5;
var elasticNet = ElasticNetRegression(A, b, alpha, l1Ratio);

elasticNet.fit();

print(elasticNet.beta);
// Output: Column Matrix of the estimated coefficients

print(elasticNet.residuals);
// Output: Column Matrix of the residuals (difference between observed and predicted responses)
Inheritance

Constructors

ElasticNetRegression(Matrix A, ColumnMatrix b, double alpha, double l1Ratio, {DiagonalMatrix? W, EquationMethod method = EquationMethod.linear})

Properties

A Matrix
The designed or input matrix for the model.
finalinherited
alpha double
final
b ColumnMatrix
The absolute terms or output column matrix for the model.
finalinherited
beta Matrix
Coefficients vector, solved in the fit method.
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
l1Ratio double
final
method EquationMethod
Equation solving method.
getter/setter pairinherited
residuals Matrix
Computes residuals of the fitted model.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
W DiagonalMatrix?
An optional diagonal matrix of weights.
finalinherited

Methods

confidenceLevel() → dynamic
Compute confidence level. Actual implementation depends on the fit and residuals.
inherited
covariance([bool isOnDesignMatrix = true]) Matrix
Compute covariance matrix either of the coefficients or of the residuals.
inherited
detectOutliers(double confidenceLevel) List<int>
Detect outliers in the data using Chauvenet's criterion with a given confidence level.
inherited
errorEllipse() Eigen
Compute error ellipse parameters using eigenvalue decomposition on the covariance matrix.
inherited
fit({LinearSystemMethod linear = LinearSystemMethod.leastSquares, DecompositionMethod decomposition = DecompositionMethod.cholesky}) → void
Fits the model to the data using the chosen method. The method can be either linear or using a matrix decomposition.
override
normal() Matrix
Computes the normal equation matrix.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
predict(Matrix xNew) Matrix
Uses the fitted model to predict new outputs given new inputs xNew.
inherited
standardDeviation() → dynamic
Compute standard deviation of residuals.
inherited
standardError() → dynamic
Compute standard error of residuals, which is the standard deviation divided by the square root of the number of observations.
inherited
toString() String
A string representation of this object.
inherited
unitVariance() → dynamic
Compute unit variance, also known as the mean square error (MSE).
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited