Class: Rumale::Preprocessing::Binarizer
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Preprocessing::Binarizer
- Includes:
- Base::Transformer
- Defined in:
- rumale-preprocessing/lib/rumale/preprocessing/binarizer.rb
Overview
Binarize samples according to a threshold
Instance Attribute Summary
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit ⇒ Binarizer
This method does nothing and returns the object itself.
-
#fit_transform(x, _y = nil) ⇒ Numo::DFloat
The output of this method is the same as that of the transform method.
-
#initialize(threshold: 0.0) ⇒ Binarizer
constructor
Create a new transformer for binarization.
-
#transform(x) ⇒ Numo::DFloat
Binarize each sample.
Constructor Details
#initialize(threshold: 0.0) ⇒ Binarizer
Create a new transformer for binarization.
28 29 30 31 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/binarizer.rb', line 28 def initialize(threshold: 0.0) super() @params = { threshold: threshold } end |
Instance Method Details
#fit ⇒ Binarizer
This method does nothing and returns the object itself. For compatibility with other transformer, this method exists.
39 40 41 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/binarizer.rb', line 39 def fit(_x = nil, _y = nil) self end |
#fit_transform(x, _y = nil) ⇒ Numo::DFloat
The output of this method is the same as that of the transform method. For compatibility with other transformer, this method exists.
58 59 60 61 62 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/binarizer.rb', line 58 def fit_transform(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) fit(x).transform(x) end |
#transform(x) ⇒ Numo::DFloat
Binarize each sample.
47 48 49 50 51 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/binarizer.rb', line 47 def transform(x) x = ::Rumale::Validation.check_convert_sample_array(x) x.class.cast(x.gt(@params[:threshold])) end |