Class: Rumale::SVM::LinearOneClassSVM
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::SVM::LinearOneClassSVM
- Defined in:
- lib/rumale/svm/linear_one_class_svm.rb
Overview
LinearOneClassSVM is a class that provides linear One-class Support Vector Machine in LIBLINEAR with Rumale interface.
Instance Attribute Summary collapse
-
#bias_term ⇒ Float
readonly
Return the bias term (a.k.a. intercept) for LinearOneClassSVM.
-
#weight_vec ⇒ Numo::DFloat
readonly
Return the weight vector for LinearOneClassSVM.
Instance Method Summary collapse
-
#decision_function(x) ⇒ Numo::DFloat
Calculate confidence scores for samples.
-
#fit(x) ⇒ LinearOneClassSVM
Fit the model with given training data.
-
#initialize(nu: 0.05, reg_param: 1.0, tol: 1e-3, verbose: false, random_seed: nil) ⇒ LinearOneClassSVM
constructor
Create a new estimator with linear One-class Support Vector Machine.
-
#marshal_dump ⇒ Hash
Dump marshal data.
-
#marshal_load(obj) ⇒ nil
Load marshal data.
-
#predict(x) ⇒ Numo::Int32
Predict class labels for samples.
Constructor Details
#initialize(nu: 0.05, reg_param: 1.0, tol: 1e-3, verbose: false, random_seed: nil) ⇒ LinearOneClassSVM
Create a new estimator with linear One-class Support Vector Machine.
31 32 33 34 35 36 37 38 39 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 31 def initialize(nu: 0.05, reg_param: 1.0, tol: 1e-3, verbose: false, random_seed: nil) super() @params = {} @params[:nu] = nu.to_f @params[:reg_param] = reg_param.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 ⇒ Float (readonly)
Return the bias term (a.k.a. intercept) for LinearOneClassSVM.
22 23 24 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 22 def bias_term @bias_term end |
#weight_vec ⇒ Numo::DFloat (readonly)
Return the weight vector for LinearOneClassSVM.
18 19 20 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 18 def weight_vec @weight_vec end |
Instance Method Details
#decision_function(x) ⇒ Numo::DFloat
Calculate confidence scores for samples.
60 61 62 63 64 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 60 def decision_function(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) Numo::Liblinear.decision_function(x, liblinear_params, @model) end |
#fit(x) ⇒ LinearOneClassSVM
Fit the model with given training data.
47 48 49 50 51 52 53 54 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 47 def fit(x, _y = nil) x = Rumale::Validation.check_convert_sample_array(x) dummy = Numo::DFloat.ones(x.shape[0]) @model = Numo::Liblinear.train(x, dummy, liblinear_params) @weight_vec = @model[:w].dup @bias_term = @model[:rho] self end |
#marshal_dump ⇒ Hash
Dump marshal data.
78 79 80 81 82 83 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 78 def marshal_dump { params: @params, model: @model, weight_vec: @weight_vec, bias_term: @bias_term } end |
#marshal_load(obj) ⇒ nil
Load marshal data.
87 88 89 90 91 92 93 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 87 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::Int32
Predict class labels for samples.
70 71 72 73 74 |
# File 'lib/rumale/svm/linear_one_class_svm.rb', line 70 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) Numo::Int32.cast(Numo::Liblinear.predict(x, liblinear_params, @model)) end |