Class: Rumale::SVM::SVR
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::SVM::SVR
- Includes:
- Base::Regressor
- Defined in:
- lib/rumale/svm/svr.rb
Overview
SVR is a class that provides Kernel Epsilon-Support Vector Regressor in LIBSVM with Rumale interface.
Instance Method Summary collapse
-
#duel_coef ⇒ Numo::DFloat
Return the coefficients of the support vector in decision function.
-
#fit(x, y) ⇒ SVR
Fit the model with given training data.
-
#initialize(reg_param: 1.0, epsilon: 0.1, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0, shrinking: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil) ⇒ SVR
constructor
Create a new regressor with Kernel Epsilon-Support Vector Regressor.
-
#intercept ⇒ Numo::DFloat
Return the intercepts in decision function.
-
#marshal_dump ⇒ Hash
Dump marshal data.
-
#marshal_load(obj) ⇒ nil
Load marshal data.
-
#n_support ⇒ Integer
Return the number of support vectors.
-
#predict(x) ⇒ Numo::DFloat
Predict values for samples.
-
#support ⇒ Numo::Int32
Return the indices of support vectors.
-
#support_vectors ⇒ Numo::DFloat
Return the support_vectors.
Constructor Details
#initialize(reg_param: 1.0, epsilon: 0.1, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0, shrinking: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil) ⇒ SVR
Create a new regressor with Kernel Epsilon-Support Vector Regressor.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rumale/svm/svr.rb', line 32 def initialize(reg_param: 1.0, epsilon: 0.1, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0, shrinking: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil) super() @params = {} @params[:reg_param] = reg_param.to_f @params[:epsilon] = epsilon.to_f @params[:kernel] = kernel @params[:degree] = degree.to_i @params[:gamma] = gamma.to_f @params[:coef0] = coef0.to_f @params[:shrinking] = shrinking @params[:cache_size] = cache_size.to_f @params[:tol] = tol.to_f @params[:verbose] = verbose @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i end |
Instance Method Details
#duel_coef ⇒ Numo::DFloat
Return the coefficients of the support vector in decision function.
111 112 113 |
# File 'lib/rumale/svm/svr.rb', line 111 def duel_coef @model[:sv_coef] end |
#fit(x, y) ⇒ SVR
Fit the model with given training data.
55 56 57 58 59 60 61 62 |
# File 'lib/rumale/svm/svr.rb', line 55 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 = precomputed_kernel? ? add_index_col(x) : x @model = Numo::Libsvm.train(xx, y, libsvm_params) self end |
#intercept ⇒ Numo::DFloat
Return the intercepts in decision function.
117 118 119 |
# File 'lib/rumale/svm/svr.rb', line 117 def intercept @model[:rho] end |
#marshal_dump ⇒ Hash
Dump marshal data.
78 79 80 81 |
# File 'lib/rumale/svm/svr.rb', line 78 def marshal_dump { params: @params, model: @model } end |
#marshal_load(obj) ⇒ nil
Load marshal data.
85 86 87 88 89 |
# File 'lib/rumale/svm/svr.rb', line 85 def marshal_load(obj) @params = obj[:params] @model = obj[:model] nil end |
#n_support ⇒ Integer
Return the number of support vectors.
105 106 107 |
# File 'lib/rumale/svm/svr.rb', line 105 def n_support support.size end |
#predict(x) ⇒ Numo::DFloat
Predict values for samples.
69 70 71 72 73 74 |
# File 'lib/rumale/svm/svr.rb', line 69 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 = precomputed_kernel? ? add_index_col(x) : x Numo::Libsvm.predict(xx, libsvm_params, @model) end |
#support ⇒ Numo::Int32
Return the indices of support vectors.
93 94 95 |
# File 'lib/rumale/svm/svr.rb', line 93 def support @model[:sv_indices] end |
#support_vectors ⇒ Numo::DFloat
Return the support_vectors.
99 100 101 |
# File 'lib/rumale/svm/svr.rb', line 99 def support_vectors precomputed_kernel? ? del_index_col(@model[:SV]) : @model[:SV] end |