Class: Rumale::Preprocessing::MaxAbsScaler
- Inherits:
-
Object
- Object
- Rumale::Preprocessing::MaxAbsScaler
- Includes:
- Base::BaseEstimator, Base::Transformer
- Defined in:
- 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 included from Base::BaseEstimator
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.
-
#marshal_dump ⇒ Hash
Dump marshal data.
-
#marshal_load(obj) ⇒ nil
Load marshal data.
-
#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.
23 24 25 26 |
# File 'lib/rumale/preprocessing/max_abs_scaler.rb', line 23 def initialize @params = {} @max_abs_vec = nil end |
Instance Attribute Details
#max_abs_vec ⇒ Numo::DFloat (readonly)
Return the vector consists of the maximum absolute value for each feature.
20 21 22 |
# File 'lib/rumale/preprocessing/max_abs_scaler.rb', line 20 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.
34 35 36 37 38 |
# File 'lib/rumale/preprocessing/max_abs_scaler.rb', line 34 def fit(x, _y = nil) check_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.
46 47 48 49 |
# File 'lib/rumale/preprocessing/max_abs_scaler.rb', line 46 def fit_transform(x, _y = nil) check_sample_array(x) fit(x).transform(x) end |
#marshal_dump ⇒ Hash
Dump marshal data.
62 63 64 65 |
# File 'lib/rumale/preprocessing/max_abs_scaler.rb', line 62 def marshal_dump { params: @params, max_abs_vec: @max_abs_vec } end |
#marshal_load(obj) ⇒ nil
Load marshal data.
69 70 71 72 73 |
# File 'lib/rumale/preprocessing/max_abs_scaler.rb', line 69 def marshal_load(obj) @params = obj[:params] @max_abs_vec = obj[:max_abs_vec] nil end |
#transform(x) ⇒ Numo::DFloat
Perform scaling the given samples with maximum absolute value for each feature.
55 56 57 58 |
# File 'lib/rumale/preprocessing/max_abs_scaler.rb', line 55 def transform(x) check_sample_array(x) x / @max_abs_vec end |