Class: SvmToolkit::Parameter
- Inherits:
-
Object
- Object
- SvmToolkit::Parameter
- Defined in:
- lib/svm_toolkit/parameter.rb
Overview
Extends the Java Parameter class with some additional methods.
Parameter holds values determining the kernel type and training process.
- svm_type
-
The type of SVM problem being solved.
-
C_SVC, the usual classification task.
-
NU_SVC
-
ONE_CLASS
-
EPSILON_SVR
-
NU_SVR
- kernel_type
-
The type of kernel to use.
-
LINEAR
-
POLY
-
RBF
-
SIGMOID
-
PRECOMPUTED
- degree
-
A parameter in polynomial kernels.
- gamma
-
A parameter in poly/rbf/sigmoid kernels.
- coef0
-
A parameter for poly/sigmoid kernels.
- cache_size
-
For training, in MB.
- eps
-
For training, stopping criterion.
- C
-
For training with C_SVC, EPSILON_SVR, NU_SVR: the cost parameter.
- nr_weight
-
For training with C_SVC.
- weight_label
-
For training with C_SVC.
- weight
-
For training with C_SVC.
- nu
-
For training with NU_SVR, ONE_CLASS, NU_SVC.
- p
-
For training with EPSILON_SVR.
- shrinking
-
training, whether to use shrinking heuristics.
- probability
-
For training, whether to use probability estimates.
Class Method Summary collapse
-
.kernel_name(kernel) ⇒ Object
Return a printable name for the given kernel.
-
.kernels ⇒ Object
Return a list of the available kernels.
Instance Method Summary collapse
-
#cost ⇒ Object
A more readable accessor for the C parameter.
-
#cost=(val) ⇒ Object
A more readable mutator for the C parameter.
-
#initialize(args) ⇒ Parameter
constructor
Constructor sets up values of attributes based on provided map.
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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/svm_toolkit/parameter.rb', line 64 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) 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 |
Class Method Details
.kernel_name(kernel) ⇒ Object
Return a printable name for the given kernel.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/svm_toolkit/parameter.rb', line 100 def self.kernel_name kernel case kernel when Parameter::LINEAR "Linear" when Parameter::POLY "Polynomial" when Parameter::RBF "Radial basis function" when Parameter::SIGMOID "Sigmoid" else "Unknown" end end |
.kernels ⇒ Object
Return a list of the available kernels.
95 96 97 |
# File 'lib/svm_toolkit/parameter.rb', line 95 def self.kernels [Parameter::LINEAR, Parameter::POLY, Parameter::RBF, Parameter::SIGMOID] end |
Instance Method Details
#cost ⇒ Object
A more readable accessor for the C parameter
85 86 87 |
# File 'lib/svm_toolkit/parameter.rb', line 85 def cost self.C end |
#cost=(val) ⇒ Object
A more readable mutator for the C parameter
90 91 92 |
# File 'lib/svm_toolkit/parameter.rb', line 90 def cost= val self.C = val end |