ElasticNet#

class cuml.linear_model.ElasticNet(alpha=1.0, *, l1_ratio=0.5, fit_intercept=True, max_iter=1000, tol=0.001, solver='auto', selection='cyclic', output_type=None, verbose=False)[source]#

Linear regression with combined L1 and L2 priors as regularizer.

Parameters:
alphafloat, default=1.0

Constant that multiplies the L1 term. alpha = 0 is equivalent to an ordinary least square, solved by the LinearRegression object. For numerical reasons, using alpha = 0 with the Lasso object is not advised. Given this, you should use the LinearRegression object.

l1_ratiofloat, default=0.5

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_interceptboolean, default=True

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

max_iterint, default=1000

The maximum number of iterations

tolfloat, default=1e-3

The tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol.

solver{‘auto’, ‘cd’, ‘qn’}, default=’auto’

The solver to use.

  • ‘auto’: uses ‘cd’ for dense inputs, and ‘qn’ for sparse inputs

  • ‘cd’: uses coordinate descent. Only supports dense inputs.

  • ‘qn’: uses quasi-newton methods. Supports sparse and dense inputs.

You may find the alternative ‘qn’ algorithm is faster when the number of features is sufficiently large but the sample size is small.

selection{‘cyclic’, ‘random’}, default=’cyclic’

How selections are made when solver="cd". If set to ‘random’, a random coefficient is updated every iteration rather than looping over features sequentially by default. This (setting to ‘random’) often leads to significantly faster convergence especially when tol is higher than 1e-4.

output_type{‘input’, ‘array’, ‘dataframe’, ‘series’, ‘df_obj’, ‘numba’, ‘cupy’, ‘numpy’, ‘cudf’, ‘pandas’}, default=None

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 for more info.

verboseint or boolean, default=False

Sets logging level. It must be one of cuml.common.logger.level_*. See Verbosity Levels for more info.

Attributes:
coef_array, shape (n_features)

The estimated coefficients for the linear regression model.

sparse_coef_sparse matrix, shape (n_targets, n_features)

Sparse representation of the fitted coef_.

intercept_float

The independent term, will be 0 if fit_intercept is False.

n_iter_int

The number of iterations taken by the solver.

Methods

fit(X, y[, sample_weight, convert_dtype])

Fit the model with X and y.

Notes

For additional docs, see scikitlearn’s ElasticNet.

Examples

>>> import cupy as cp
>>> import cudf
>>> from cuml.linear_model import ElasticNet
>>> enet = ElasticNet(alpha = 0.1, l1_ratio=0.5, solver='qn')
>>> X = cudf.DataFrame()
>>> X['col1'] = cp.array([0, 1, 2], dtype = cp.float32)
>>> X['col2'] = cp.array([0, 1, 2], dtype = cp.float32)
>>> y = cudf.Series(cp.array([0.0, 1.0, 2.0], dtype = cp.float32) )
>>> result_enet = enet.fit(X, y)
>>> print(result_enet.coef_)
0    0.445...
1    0.445...
dtype: float32
>>> print(result_enet.intercept_)
0.108433...
>>> X_new = cudf.DataFrame()
>>> X_new['col1'] = cp.array([3,2], dtype = cp.float32)
>>> X_new['col2'] = cp.array([5,5], dtype = cp.float32)
>>> preds = result_enet.predict(X_new)
>>> print(preds)
0    3.674...
1    3.228...
dtype: float32
fit(X, y, sample_weight=None, *, convert_dtype=True) ElasticNet[source]#

Fit the model with X and y.

Parameters:
Xarray-like (device or host) shape = (n_samples, n_features)

Dense matrix. If datatype is other than floats or doubles, then the data will be converted to float which increases memory utilization. Set the parameter convert_dtype to False to avoid this, then the method will throw an error instead. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

yarray-like (device or host) shape = (n_samples, 1)

Dense matrix. If datatype is other than floats or doubles, then the data will be converted to float which increases memory utilization. Set the parameter convert_dtype to False to avoid this, then the method will throw an error instead. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

sample_weightarray-like (device or host) shape = (n_samples,), default=None

The weights for each observation in X. If None, all observations are assigned equal weight. Acceptable dense formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

convert_dtypebool, optional (default = True)

When set to True, the train method will, when necessary, convert y to be the same data type as X if they differ. This will increase memory used for the method.

property sparse_coef_#

Sparse representation of the fitted coef_.