Class: Rumale::LinearModel::Lasso
- Inherits:
-
BaseEstimator
- Object
- Base::Estimator
- BaseEstimator
- Rumale::LinearModel::Lasso
- Includes:
- Base::Regressor
- Defined in:
- rumale-linear_model/lib/rumale/linear_model/lasso.rb
Overview
Lasso is a class that implements Lasso Regression with coordinate descent optimization.
Reference
-
Friedman, J., Hastie, T., and Tibshirani, R., “Regularization Paths for Generalized Linear Models via Coordinate Descent,” Journal of Statistical Software, 33 (1), pp. 1–22, 2010.
-
Simon, N., Friedman, J., and Hastie, T., “A Blockwise Descent Algorithm for Group-penalized Multiresponse and Multinomial Regression,” arXiv preprint arXiv:1311.6529, 2013.
Instance Attribute Summary collapse
-
#n_iter ⇒ Integer
readonly
Return the number of iterations performed in coordinate descent optimization.
Attributes inherited from BaseEstimator
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x, y) ⇒ Lasso
Fit the model with given training data.
-
#initialize(reg_param: 1.0, fit_bias: true, bias_scale: 1.0, max_iter: 1000, tol: 1e-4) ⇒ Lasso
constructor
Create a new Lasso regressor.
-
#predict(x) ⇒ Numo::DFloat
Predict values for samples.
Methods included from Base::Regressor
Constructor Details
#initialize(reg_param: 1.0, fit_bias: true, bias_scale: 1.0, max_iter: 1000, tol: 1e-4) ⇒ Lasso
Create a new Lasso regressor.
38 39 40 41 42 43 44 45 46 47 |
# File 'rumale-linear_model/lib/rumale/linear_model/lasso.rb', line 38 def initialize(reg_param: 1.0, fit_bias: true, bias_scale: 1.0, max_iter: 1000, tol: 1e-4) super() @params = { reg_param: reg_param, fit_bias: fit_bias, bias_scale: bias_scale, max_iter: max_iter, tol: tol } end |
Instance Attribute Details
#n_iter ⇒ Integer (readonly)
Return the number of iterations performed in coordinate descent optimization.
28 29 30 |
# File 'rumale-linear_model/lib/rumale/linear_model/lasso.rb', line 28 def n_iter @n_iter end |
Instance Method Details
#fit(x, y) ⇒ Lasso
Fit the model with given training data.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'rumale-linear_model/lib/rumale/linear_model/lasso.rb', line 54 def fit(x, y) x = Rumale::Validation.check_convert_sample_array(x) y = Rumale::Validation.check_convert_target_value_array(y) Rumale::Validation.check_sample_size(x, y) @n_iter = 0 x = (x) if fit_bias? @weight_vec, @bias_term = if single_target?(y) partial_fit(x, y) else partial_fit_multi(x, y) end self end |
#predict(x) ⇒ Numo::DFloat
Predict values for samples.
75 76 77 78 79 |
# File 'rumale-linear_model/lib/rumale/linear_model/lasso.rb', line 75 def predict(x) x = Rumale::Validation.check_convert_sample_array(x) x.dot(@weight_vec.transpose) + @bias_term end |