LassoRegression class

Implements Lasso Regression, a type of regularized linear regression. It includes an L1 penalty term on the size of coefficients which helps to control the magnitude of the coefficients and can produce models with sparse coefficients (many coefficients being zero).

The regularization parameter alpha controls the strength of the penalty term. Larger values of alpha increase the effect of regularization, shrinking coefficients towards zero to prevent overfitting.

// Example usage:
var A = Matrix.fromList([[1, 2], [3, 4], [5, 6]]);
var b = Matrix.column([7, 8, 9]);
var alpha = 0.1;
var lasso = LassoRegression(A, b, alpha);

lasso.fit();

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

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

Constructors

LassoRegression.new(Matrix A, ColumnMatrix b, double alpha, {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
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() num
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() num
Compute standard deviation of residuals.
inherited
standardError() num
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() num
Compute unit variance, also known as the mean square error (MSE).
inherited

Operators

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