Class: Rumale::SVM::LinearSVR
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::SVM::LinearSVR
- Includes:
- Base::Regressor
- Defined in:
- lib/rumale/svm/linear_svr.rb
Overview
LinearSVR is a class that provides Support Vector Regressor in LIBLINEAR with Rumale interface.
Instance Attribute Summary collapse
-
#bias_term ⇒ Numo::DFloat
readonly
Return the bias term (a.k.a. intercept) for LinearSVR.
-
#weight_vec ⇒ Numo::DFloat
readonly
Return the weight vector for LinearSVR.
Instance Method Summary collapse
-
#fit(x, y) ⇒ LinearSVR
Fit the model with given training data.
-
#initialize(loss: 'squared_epsilon_insensitive', dual: true, reg_param: 1.0, epsilon: 0.1, fit_bias: true, bias_scale: 1.0, tol: 1e-3, verbose: false, random_seed: nil) ⇒ LinearSVR
constructor
Create a new regressor with Support Vector Regressor.
-
#marshal_dump ⇒ Hash
Dump marshal data.
-
#marshal_load(obj) ⇒ nil
Load marshal data.
-
#predict(x) ⇒ Numo::DFloat
Predict values for samples.
Constructor Details
#initialize(loss: 'squared_epsilon_insensitive', dual: true, reg_param: 1.0, epsilon: 0.1, fit_bias: true, bias_scale: 1.0, tol: 1e-3, verbose: false, random_seed: nil) ⇒ LinearSVR
Create a new regressor with Support Vector Regressor.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rumale/svm/linear_svr.rb', line 41 def initialize(loss: 'squared_epsilon_insensitive', dual: true, reg_param: 1.0, epsilon: 0.1, fit_bias: true, bias_scale: 1.0, tol: 1e-3, verbose: false, random_seed: nil) super() @params = {} @params[:loss] = loss == 'epsilon_insensitive' ? 'epsilon_insensitive' : 'squared_epsilon_insensitive' @params[:dual] = dual @params[:reg_param] = reg_param.to_f @params[:epsilon] = epsilon.to_f @params[:fit_bias] = fit_bias @params[:bias_scale] = bias_scale.to_f @params[:tol] = tol.to_f @params[:verbose] = verbose @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i end |
Instance Attribute Details
#bias_term ⇒ Numo::DFloat (readonly)
Return the bias term (a.k.a. intercept) for LinearSVR.
25 26 27 |
# File 'lib/rumale/svm/linear_svr.rb', line 25 def bias_term @bias_term end |
#weight_vec ⇒ Numo::DFloat (readonly)
Return the weight vector for LinearSVR.
21 22 23 |
# File 'lib/rumale/svm/linear_svr.rb', line 21 def weight_vec @weight_vec end |
Instance Method Details
#fit(x, y) ⇒ LinearSVR
Fit the model with given training data.
61 62 63 64 65 66 67 68 69 |
# File 'lib/rumale/svm/linear_svr.rb', line 61 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) xx = fit_bias? ? (x) : x @model = Numo::Liblinear.train(xx, y, liblinear_params) @weight_vec, @bias_term = weight_and_bias(@model[:w]) self end |
#marshal_dump ⇒ Hash
Dump marshal data.
84 85 86 87 88 89 |
# File 'lib/rumale/svm/linear_svr.rb', line 84 def marshal_dump { params: @params, model: @model, weight_vec: @weight_vec, bias_term: @bias_term } end |
#marshal_load(obj) ⇒ nil
Load marshal data.
93 94 95 96 97 98 99 |
# File 'lib/rumale/svm/linear_svr.rb', line 93 def marshal_load(obj) @params = obj[:params] @model = obj[:model] @weight_vec = obj[:weight_vec] @bias_term = obj[:bias_term] nil end |
#predict(x) ⇒ Numo::DFloat
Predict values for samples.
75 76 77 78 79 80 |
# File 'lib/rumale/svm/linear_svr.rb', line 75 def predict(x) raise "#{self.class.name}##{__method__} expects to be called after training the model with the fit method." unless trained? x = Rumale::Validation.check_convert_sample_array(x) xx = fit_bias? ? (x) : x Numo::Liblinear.predict(xx, liblinear_params, @model) end |