Implementation:Scikit learn Scikit learn OrthogonalMatchingPursuit
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Sparse Approximation |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for sparse signal approximation using the Orthogonal Matching Pursuit algorithm provided by scikit-learn.
Description
OrthogonalMatchingPursuit (OMP) implements a greedy algorithm for selecting features in sparse linear regression. At each step, OMP selects the feature most correlated with the current residual, then performs an orthogonal projection to update the residual. The algorithm is parameterized by either the number of non-zero coefficients desired or a tolerance on the squared norm of the residual. The module also provides OrthogonalMatchingPursuitCV for cross-validated selection of the number of non-zero coefficients.
Usage
Use OrthogonalMatchingPursuit when you need a fast, greedy approach to sparse signal recovery, when you know approximately how many features should be active, or when you need sparse approximation of a signal from a dictionary of atoms. It is widely used in compressed sensing and signal processing applications.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/linear_model/_omp.py
Signature
class OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel):
def __init__(
self,
*,
n_nonzero_coefs=None,
tol=None,
fit_intercept=True,
precompute="auto",
):
Import
from sklearn.linear_model import OrthogonalMatchingPursuit
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| n_nonzero_coefs | int | No | Desired number of non-zero entries in the solution (default=None, auto-set to 10% of n_features or 1) |
| tol | float | No | Maximum squared norm of the residual; overrides n_nonzero_coefs if set (default=None) |
| fit_intercept | bool | No | Whether to calculate the intercept (default=True) |
| precompute | bool or 'auto' | No | Whether to use precomputed Gram and Xy matrices (default='auto') |
Outputs
| Name | Type | Description |
|---|---|---|
| coef_ | ndarray of shape (n_features,) or (n_targets, n_features) | Parameter vector |
| intercept_ | float or ndarray of shape (n_targets,) | Independent term in decision function |
| n_iter_ | int or array-like | Number of active features across every target |
| n_nonzero_coefs_ | int or None | The resolved number of non-zero coefficients |
Usage Examples
Basic Usage
from sklearn.linear_model import OrthogonalMatchingPursuit
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=100, n_features=50, n_informative=5, noise=5, random_state=42)
model = OrthogonalMatchingPursuit(n_nonzero_coefs=5)
model.fit(X, y)
print("Non-zero coefficients:", (model.coef_ != 0).sum())
print("Score:", model.score(X, y))