Class: Rumale::Preprocessing::KernelCalculator
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Preprocessing::KernelCalculator
- Includes:
- Base::Transformer
- Defined in:
- rumale-preprocessing/lib/rumale/preprocessing/kernel_calculator.rb
Overview
KernelCalculator is a class that calculates the kernel matrix with training data.
Instance Attribute Summary collapse
-
#components ⇒ Numo::DFloat
readonly
Returns the training data for calculating kernel matrix.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x) ⇒ KernelCalculator
Fit the model with given training data.
-
#fit_transform(x) ⇒ Numo::DFloat
Fit the model with training data, and then transform them with the learned model.
-
#initialize(kernel: 'rbf', gamma: 1, degree: 3, coef: 1) ⇒ KernelCalculator
constructor
Create a new transformer that transforms feature vectors into a kernel matrix.
-
#transform(x) ⇒ Numo::DFloat
Transform the given data with the learned model.
Constructor Details
#initialize(kernel: 'rbf', gamma: 1, degree: 3, coef: 1) ⇒ KernelCalculator
Create a new transformer that transforms feature vectors into a kernel matrix.
37 38 39 40 41 42 43 44 45 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/kernel_calculator.rb', line 37 def initialize(kernel: 'rbf', gamma: 1, degree: 3, coef: 1) super() @params = { kernel: kernel, gamma: gamma, degree: degree, coef: coef } end |
Instance Attribute Details
#components ⇒ Numo::DFloat (readonly)
Returns the training data for calculating kernel matrix.
29 30 31 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/kernel_calculator.rb', line 29 def components @components end |
Instance Method Details
#fit(x) ⇒ KernelCalculator
Fit the model with given training data.
52 53 54 55 56 57 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/kernel_calculator.rb', line 52 def fit(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) @components = x.dup self end |
#fit_transform(x) ⇒ Numo::DFloat
Fit the model with training data, and then transform them with the learned model.
64 65 66 67 68 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/kernel_calculator.rb', line 64 def fit_transform(x, y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) fit(x, y).transform(x) end |
#transform(x) ⇒ Numo::DFloat
Transform the given data with the learned model.
74 75 76 77 78 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/kernel_calculator.rb', line 74 def transform(x) x = ::Rumale::Validation.check_convert_sample_array(x) kernel_mat(x, @components) end |