dislib.regression.Lasso¶
ADMM Lasso
@Authors: Aleksandar Armacki and Lidija Fodor @Affiliation: Faculty of Sciences, University of Novi Sad, Serbia
This work is supported by the I-BiDaaS project, funded by the European Commission under Grant Agreement No. 780787.
-
class
dislib.regression.lasso.base.
Lasso
(lmbd=0.001, rho=1, max_iter=100, atol=0.0001, rtol=0.01, verbose=False)[source]¶ Bases:
sklearn.base.BaseEstimator
Lasso represents the Least Absolute Shrinkage and Selection Operator (Lasso) for regression analysis, solved in a distributed manner with ADMM.
Parameters: - lmbd (float, optional (default=1e-3)) – The regularization parameter for Lasso regression.
- rho (float, optional (default=1)) – The penalty parameter for constraint violation.
- max_iter (int, optional (default=100)) – The maximum number of iterations of ADMM.
- atol (float, optional (default=1e-4)) – The absolute tolerance used to calculate the early stop criterion for ADMM.
- rtol (float, optional (default=1e-2)) – The relative tolerance used to calculate the early stop criterion for ADMM.
- verbose (boolean, optional (default=False)) – Whether to print information about the optimization process.
Variables: - coef (ds-array, shape=(1, n_features)) – Parameter vector.
- n_iter (int) – Number of iterations run by ADMM.
- converged (boolean) – Whether ADMM converged.
See also
ADMM
-
fit
(x, y)[source]¶ Fits the model with training data. Optimization is carried out using ADMM.
Parameters: - x (ds-array, shape=(n_samples, n_features)) – Training samples.
- y (ds-array, shape=(n_samples, 1)) – Class labels of x.
Returns: self
Return type:
-
fit_predict
(x)[source]¶ Fits the model and predicts using the same data.
Parameters: x (ds-array, shape=(n_samples, n_features)) – Training samples. Returns: y – Predicted values. Return type: ds-array, shape=(n_samples, 1)
-
load_model
(filepath, load_format='json')[source]¶ Loads a model from a file. The model is reinstantiated in the exact same state in which it was saved, without any of the code used for model definition or fitting. :Parameters: * filepath (str) – Path of the saved the model
- load_format (str, optional (default=’json’)) – Format used to load the model.
Examples
>>> from dislib.regression import lasso >>> import dislib as ds >>> lasso2 = Lasso() >>> lasso2.load_model("./lasso_model") >>> y_pred_lasso = lasso2.predict(ds.array(X_test, (25, 100)))
-
predict
(x)[source]¶ Predict using the linear model.
Parameters: x (ds-array, shape=(n_samples, n_features)) – Samples. Returns: y – Predicted values. Return type: ds-array, shape=(n_samples, 1)
-
save_model
(filepath, overwrite=True, save_format='json')[source]¶ Saves a model to a file. The model is synchronized before saving and can be reinstantiated in the exact same state, without any of the code used for model definition or fitting. :Parameters: * filepath (str) – Path where to save the model
- overwrite (bool, optional (default=True)) – Whether any existing model at the target location should be overwritten.
- save_format (str, optional (default=’json)) – Format used to save the models.
Examples
>>> from dislib.regression import lasso >>> import numpy as np >>> import dislib as ds >>> lasso = Lasso(lmbd=0.1, max_iter=50) >>> lasso.fit(ds.array(X_train, (5, 100)), ds.array(y_train, (5, 1))) >>> lasso.save_model("./lasso_model")