# CD

### *class* cuml.solvers.CD(, loss='squared_loss', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, output_type=None, verbose=False)

Coordinate Descent (CD) is a very common optimization algorithm that
minimizes along coordinate directions to find the minimum of a function.

cuML’s CD algorithm accepts a numpy matrix or a cuDF DataFrame as the
input dataset.algorithm The CD algorithm currently works with linear
regression and ridge, lasso, and elastic-net penalties.

* **Parameters:**
  **loss**
  : Only ‘squared_loss’ is supported right now.
    ‘squared_loss’ uses linear regression in its predict step.

  **alpha: float (default = 0.0001)**
  : The constant value which decides the degree of regularization.
    ‘alpha = 0’ is equivalent to an ordinary least square, solved by the
    LinearRegression object.

  **l1_ratio: float (default = 0.15)**
  : The ElasticNet mixing parameter, with 0 <= l1_ratio <= 1. For
    l1_ratio = 0 the penalty is an L2 penalty.
    For l1_ratio = 1 it is an L1 penalty. For 0 < l1_ratio < 1,
    the penalty is a combination of L1 and L2.

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

  **max_iter**
  : The number of times the model should iterate through the entire
    dataset during training

  **tol**
  : The tolerance for the optimization: if the updates are smaller than tol,
    solver stops.

  **shuffle**
  : If set to ‘True’, a random coefficient is updated every iteration rather
    than looping over features sequentially by default.
    This (setting to ‘True’) often leads to significantly faster convergence
    especially when tol is higher than 1e-4.

  **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:**
  **coef_**

### Methods

| [`fit`](#cuml.solvers.CD.fit)(self, X, y[, sample_weight])   | Fit the model with X and y.   |
|-------------------------------------------------------------------------------------|-------------------------------|
| [`predict`](#cuml.solvers.CD.predict)(self, X)                   | Predicts the y for X.         |

### Examples

```pycon
>>> import cupy as cp
>>> import cudf
>>> from cuml.solvers import CD
```

```pycon
>>> cd = CD(alpha=0.0)
```

```pycon
>>> X = cudf.DataFrame()
>>> X['col1'] = cp.array([1,1,2,2], dtype=cp.float32)
>>> X['col2'] = cp.array([1,2,2,3], dtype=cp.float32)
```

```pycon
>>> y = cudf.Series(cp.array([6.0, 8.0, 9.0, 11.0], dtype=cp.float32))
```

```pycon
>>> cd.fit(X,y)
CD(alpha=0.0)
>>> print(cd.coef_)
0 1.001...
1 1.998...
dtype: float32
>>> print(cd.intercept_)
3.00...
>>> X_new = cudf.DataFrame()
>>> X_new['col1'] = cp.array([3,2], dtype=cp.float32)
>>> X_new['col2'] = cp.array([5,5], dtype=cp.float32)
```

```pycon
>>> preds = cd.predict(X_new)
>>> print(preds)
0 15.997...
1 14.995...
dtype: float32
```

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

#### fit(self, X, y, sample_weight=None) → 'CD'[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/solvers/cd.pyx#L306)

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 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.

<!-- !! 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/solvers/cd.pyx#L331)

Predicts the y 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 !! -->

#### 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 !! -->
