Class: Rumale::Preprocessing::MaxAbsScaler
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Preprocessing::MaxAbsScaler
- Includes:
- Base::Transformer
- Defined in:
- rumale-preprocessing/lib/rumale/preprocessing/max_abs_scaler.rb
Overview
Normalize samples by scaling each feature with its maximum absolute value.
Instance Attribute Summary collapse
-
#max_abs_vec ⇒ Numo::DFloat
readonly
Return the vector consists of the maximum absolute value for each feature.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x) ⇒ MaxAbsScaler
Calculate the minimum and maximum value of each feature for scaling.
-
#fit_transform(x) ⇒ Numo::DFloat
Calculate the maximum absolute value for each feature, and then normalize samples.
-
#initialize ⇒ MaxAbsScaler
constructor
Creates a new normalizer for scaling each feature with its maximum absolute value.
-
#transform(x) ⇒ Numo::DFloat
Perform scaling the given samples with maximum absolute value for each feature.
Constructor Details
#initialize ⇒ MaxAbsScaler
Creates a new normalizer for scaling each feature with its maximum absolute value.
25 26 27 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_abs_scaler.rb', line 25 def initialize # rubocop:disable Lint/UselessMethodDefinition super() end |
Instance Attribute Details
#max_abs_vec ⇒ Numo::DFloat (readonly)
Return the vector consists of the maximum absolute value for each feature.
22 23 24 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_abs_scaler.rb', line 22 def max_abs_vec @max_abs_vec end |
Instance Method Details
#fit(x) ⇒ MaxAbsScaler
Calculate the minimum and maximum value of each feature for scaling.
35 36 37 38 39 40 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_abs_scaler.rb', line 35 def fit(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) @max_abs_vec = x.abs.max(0) self end |
#fit_transform(x) ⇒ Numo::DFloat
Calculate the maximum absolute value for each feature, and then normalize samples.
48 49 50 51 52 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_abs_scaler.rb', line 48 def fit_transform(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) fit(x).transform(x) end |
#transform(x) ⇒ Numo::DFloat
Perform scaling the given samples with maximum absolute value for each feature.
58 59 60 61 62 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_abs_scaler.rb', line 58 def transform(x) x = ::Rumale::Validation.check_convert_sample_array(x) x / @max_abs_vec end |