Class: Rumale::Pipeline::FeatureUnion
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Pipeline::FeatureUnion
- Defined in:
- rumale-pipeline/lib/rumale/pipeline/feature_union.rb
Overview
FeatureUnion is a class that implements the function concatenating the multi-transformer results.
Instance Attribute Summary collapse
-
#transformers ⇒ Hash
readonly
Return the transformers.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x, y = nil) ⇒ FeatureUnion
Fit the model with given training data.
-
#fit_transform(x, y = nil) ⇒ Numo::DFloat
Fit the model with training data, and then transform them with the learned model.
-
#initialize(transformers:) ⇒ FeatureUnion
constructor
Create a new feature union.
-
#transform(x) ⇒ Numo::DFloat
Transform the given data with the learned model.
Constructor Details
#initialize(transformers:) ⇒ FeatureUnion
Create a new feature union.
34 35 36 37 38 |
# File 'rumale-pipeline/lib/rumale/pipeline/feature_union.rb', line 34 def initialize(transformers:) super() @params = {} @transformers = transformers end |
Instance Attribute Details
#transformers ⇒ Hash (readonly)
Return the transformers
29 30 31 |
# File 'rumale-pipeline/lib/rumale/pipeline/feature_union.rb', line 29 def transformers @transformers end |
Instance Method Details
#fit(x, y = nil) ⇒ FeatureUnion
Fit the model with given training data.
45 46 47 48 |
# File 'rumale-pipeline/lib/rumale/pipeline/feature_union.rb', line 45 def fit(x, y = nil) @transformers.each_value { |t| t.fit(x, y) } self end |
#fit_transform(x, y = nil) ⇒ Numo::DFloat
Fit the model with training data, and then transform them with the learned model.
55 56 57 |
# File 'rumale-pipeline/lib/rumale/pipeline/feature_union.rb', line 55 def fit_transform(x, y = nil) fit(x, y).transform(x) end |
#transform(x) ⇒ Numo::DFloat
Transform the given data with the learned model.
63 64 65 66 |
# File 'rumale-pipeline/lib/rumale/pipeline/feature_union.rb', line 63 def transform(x) z = @transformers.values.map { |t| t.transform(x) } Numo::NArray.hstack(z) end |