Lasso
The Lasso (Least Absolute Shrinkage and Selection Operator) is a linear regression model with an penalty that induces sparsity — it drives some coefficients exactly to zero, effectively performing feature selection.
Objective Function
where is the number of samples and controls the regularization strength.
This formulation matches scikit-learn's Lasso.
Coordinate Descent Algorithm
Skigen solves the Lasso via coordinate descent with soft-thresholding. At each iteration, the algorithm optimizes one coefficient at a time while holding all others fixed.
Define the partial residual correlation:
where denotes all columns except . The closed-form update for coordinate is:
where is the soft-thresholding operator.
In practice, is computed efficiently using the running residual :
The algorithm cycles over all features until convergence (maximum coefficient change ) or max_iter iterations.
Sparsity and Feature Selection
The penalty produces sparse solutions: at convergence, any coefficient whose partial correlation does not exceed is set exactly to zero. This makes Lasso a natural tool for feature selection in high-dimensional settings.
When to Use
- Feature selection: When you expect many features to be irrelevant.
- Sparse signals: When the true underlying model involves only a few non-zero coefficients.
- For correlated features, consider ElasticNet, which combines and penalties for stability.
Constructor
Skigen::Lasso<Scalar> model(Scalar alpha = 1, bool fit_intercept = true,
int max_iter = 1000, Scalar tol = 1e-4);
| Parameter | Default | Description |
|---|---|---|
alpha | 1 | Regularization strength () |
fit_intercept | true | Whether to center the data and compute an intercept |
max_iter | 1000 | Maximum coordinate descent iterations |
tol | 1e-4 | Convergence tolerance on coefficient updates |
Methods
| Method | Description |
|---|---|
fit(X, y) | Fit the model via coordinate descent |
predict(X) | Predict |
score(X, y) | Return the coefficient of determination |
Fitted Attributes
| Accessor | Type | Description |
|---|---|---|
coef() | RowVectorType | Estimated coefficients (typically sparse) |
intercept() | Scalar | Intercept term |
Example
#include <Skigen/LinearModel>
Skigen::Lasso model(/*alpha=*/0.1);
model.fit(X, y);
std::cout << "Non-zero coefs: "
<< (model.coef().array().abs() > 1e-10).count() << "\n";
For full parameter details and method signatures, see the auto-generated Lasso API Reference.