# Lars

### *class* cuml.linear_model.Lars(, fit_intercept=True, copy_X=True, fit_path=True, n_nonzero_coefs=500, eps=None, precompute='auto', verbose=False, output_type=None)

Least Angle Regression

Least Angle Regression (LAR or LARS) is a model selection algorithm. It
builds up the model using the following algorithm:

1. We start with all the coefficients equal to zero.
2. At each step we select the predictor that has the largest absolute
   correlation with the residual.
3. We take the largest step possible in the direction which is equiangular
   with all the predictors selected so far. The largest step is determined
   such that using this step a new predictor will have as much correlation
   with the residual as any of the currently active predictors.
4. Stop if `max_iter` reached or all the predictors are used, or if the
   correlation between any unused predictor and the residual is lower than
   a tolerance.

The solver is based on [[1]](#r88c80e68f5c6-1). The equations referred in the comments
correspond to the equations in the paper.

#### NOTE
This algorithm assumes that the offset is removed from `X` and
`y`, and each feature is normalized:

$$
sum_i y_i = 0, sum_i x_{i,j} = 0,sum_i x_{i,j}^2=1             for j=0..n_{col}-1
$$

* **Parameters:**
  **fit_intercept**
  : If True, Lars tries to correct for the global mean of y.
    If False, the model expects that you have centered the data.

  **copy_X**
  : The solver permutes the columns of X. Set `copy_X` to True to prevent
    changing the input data.

  **fit_path**
  : Whether to return all the coefficients along the regularization path
    in the `coef_path_` attribute.

  **precompute**
  : Whether to precompute the gram matrix. The user can provide the gram
    matrix as an argument.

  **n_nonzero_coefs**
  : The maximum number of coefficients to fit. This gives an upper limit of
    how many features we select for prediction. This number is also an
    upper limit of the number of iterations.

  **verbose**
  : Sets logging level. It must be one of `cuml.common.logger.level_*`.
    See [Verbosity Levels](../../cuml/index.html.md#verbosity-levels) for more info.

  **output_type**
  : Return results and set estimator attributes to the indicated output
    type. If None, the output type set at the module level
    (`cuml.global_settings.output_type`) will be used. See
    [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration) for more info.
* **Attributes:**
  **alphas_**
  : The maximum correlation at each step.

  **active_**
  : The indices of the active variables at the end of the path.

  **beta_**
  : The active regression coefficients (same as `coef_` but zeros omitted).

  **coef_path_**
  : The coefficients along the regularization path. Stored only if
    `fit_path` is True. Note that we only store coefficients for indices
    in the active set (i.e. `coef_path_[:,-1] == coef_[active_]`)

  **coef_**
  : The estimated coefficients for the regression model.

  **intercept_**
  : The independent term. If `fit_intercept_` is False, will be 0.

  **n_iter_**
  : The number of iterations taken by the solver.

### Methods

| [`fit`](#cuml.linear_model.Lars.fit)(self, X, y)   | Fit the model with X and y.   |
|--------------------------------------------------------------------|-------------------------------|
| [`predict`](#cuml.linear_model.Lars.predict)(self, X)  | Predicts `y` values for `X`.  |

### Notes

For additional information, see [scikitlearn’s OLS documentation](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lars.html).

### References

<!-- !! processed by numpydoc !! -->

#### fit(self, X, y) → 'Lars'[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/linear_model/lars.pyx#L200)

Fit the model with X and y.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **y**
  : Dense matrix with any dtype.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### predict(self, X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/linear_model/lars.pyx#L332)

Predicts `y` values for `X`.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **preds**
  : Predicted values
    <br/>
    For more information on how to configure cuML’s output type,
    refer to: [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration).

<!-- !! processed by numpydoc !! -->

#### score(X, y, sample_weight=None, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/mixins.py#L66)

Scoring function for regression estimators

Returns the coefficient of determination R^2 of the prediction.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **y**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **sample_weight**
  : The weights for each observation in X. If None, all observations
    are assigned equal weight.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **score**
  : R^2 of self.predict(X) wrt. y.

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->
