Class: Libsvm::Parameter
- Inherits:
-
Object
- Object
- Libsvm::Parameter
- Defined in:
- lib/jrb-libsvm/parameter.rb
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Parameter
constructor
Constructor sets up values of attributes based on provided map.
- #label_weights ⇒ Object
- #label_weights=(v) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Parameter
Constructor sets up values of attributes based on provided map. Valid keys with their default values:
-
:svm_type = Parameter::C_SVC, for the type of SVM
-
:kernel_type = Parameter::LINEAR, for the type of kernel
-
:cost = 1.0, for the cost or C parameter
-
:gamma = 0.0, for the gamma parameter in kernel
-
:degree = 1, for polynomial kernel
-
:coef0 = 0.0, for polynomial/sigmoid kernels
-
:eps = 0.001, for stopping criterion
-
:nr_weight = 0, for C_SVC
-
:nu = 0.5, used for NU_SVC, ONE_CLASS and NU_SVR. Nu must be in (0,1]
-
:p = 0.1, used for EPSILON_SVR
-
:shrinking = 1, use the shrinking heuristics
-
:probability = 0, use the probability estimates
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jrb-libsvm/parameter.rb', line 29 def initialize args={} super() self.svm_type = args.fetch(:svm_type, Parameter::C_SVC) self.kernel_type = args.fetch(:kernel_type, Parameter::LINEAR) self.C = args.fetch(:cost, 1.0) self.gamma = args.fetch(:gamma, 0.0) self.degree = args.fetch(:degree, 1) self.coef0 = args.fetch(:coef0, 0.0) self.eps = args.fetch(:eps, 0.001) self.nr_weight = args.fetch(:nr_weight, 0) self.nu = args.fetch(:nu, 0.5) self.p = args.fetch(:p, 0.1) self.shrinking = args.fetch(:shrinking, 1) self.probability = args.fetch(:probability, 0) self.cache_size = args.fetch(:cache_size, 1) unless self.nu > 0.0 and self.nu <= 1.0 raise ArgumentError "Invalid value of nu #{self.nu}, should be in (0,1]" end end |
Instance Method Details
#label_weights ⇒ Object
6 7 8 |
# File 'lib/jrb-libsvm/parameter.rb', line 6 def label_weights Hash[self.weight_label.zip(self.weight)] end |
#label_weights=(v) ⇒ Object
9 10 11 12 13 |
# File 'lib/jrb-libsvm/parameter.rb', line 9 def label_weights=v self.nr_weight = v.keys.size self.weight_label = v.keys.to_java :int self.weight = v.values.to_java :double end |