Class: Rumale::Pipeline::Pipeline
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Pipeline::Pipeline
- Defined in:
- rumale-pipeline/lib/rumale/pipeline/pipeline.rb
Overview
Pipeline is a class that implements the function to perform the transformers and estimators sequencially.
Instance Attribute Summary collapse
-
#steps ⇒ Hash
readonly
Return the steps.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#decision_function(x) ⇒ Numo::DFloat
Call the decision_function method of last estimator after applying all transforms.
-
#fit(x, y) ⇒ Pipeline
Fit the model with given training data.
-
#fit_predict(x, y = nil) ⇒ Numo::NArray
Call the fit_predict method of last estimator after applying all transforms.
-
#fit_transform(x, y = nil) ⇒ Numo::NArray
Call the fit_transform method of last estimator after applying all transforms.
-
#initialize(steps:) ⇒ Pipeline
constructor
Create a new pipeline.
-
#inverse_transform(z) ⇒ Numo::DFloat
Call the inverse_transform method in reverse order.
-
#predict(x) ⇒ Numo::NArray
Call the predict method of last estimator after applying all transforms.
-
#predict_log_proba(x) ⇒ Numo::DFloat
Call the predict_log_proba method of last estimator after applying all transforms.
-
#predict_proba(x) ⇒ Numo::DFloat
Call the predict_proba method of last estimator after applying all transforms.
-
#score(x, y) ⇒ Float
Call the score method of last estimator after applying all transforms.
-
#transform(x) ⇒ Numo::DFloat
Call the transform method of last estimator after applying all transforms.
Constructor Details
#initialize(steps:) ⇒ Pipeline
Create a new pipeline.
30 31 32 33 34 35 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 30 def initialize(steps:) super() validate_steps(steps) @params = {} @steps = steps end |
Instance Attribute Details
#steps ⇒ Hash (readonly)
Return the steps.
24 25 26 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 24 def steps @steps end |
Instance Method Details
#decision_function(x) ⇒ Numo::DFloat
Call the decision_function method of last estimator after applying all transforms.
72 73 74 75 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 72 def decision_function(x) trans_x = apply_transforms(x) last_estimator.decision_function(trans_x) end |
#fit(x, y) ⇒ Pipeline
Fit the model with given training data.
42 43 44 45 46 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 42 def fit(x, y) trans_x = apply_transforms(x, y, fit: true) last_estimator&.fit(trans_x, y) self end |
#fit_predict(x, y = nil) ⇒ Numo::NArray
Call the fit_predict method of last estimator after applying all transforms.
53 54 55 56 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 53 def fit_predict(x, y = nil) trans_x = apply_transforms(x, y, fit: true) last_estimator.fit_predict(trans_x) end |
#fit_transform(x, y = nil) ⇒ Numo::NArray
Call the fit_transform method of last estimator after applying all transforms.
63 64 65 66 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 63 def fit_transform(x, y = nil) trans_x = apply_transforms(x, y, fit: true) last_estimator.fit_transform(trans_x, y) end |
#inverse_transform(z) ⇒ Numo::DFloat
Call the inverse_transform method in reverse order.
117 118 119 120 121 122 123 124 125 126 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 117 def inverse_transform(z) itrans_z = z @steps.keys.reverse_each do |name| transformer = @steps[name] next if transformer.nil? itrans_z = transformer.inverse_transform(itrans_z) end itrans_z end |
#predict(x) ⇒ Numo::NArray
Call the predict method of last estimator after applying all transforms.
81 82 83 84 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 81 def predict(x) trans_x = apply_transforms(x) last_estimator.predict(trans_x) end |
#predict_log_proba(x) ⇒ Numo::DFloat
Call the predict_log_proba method of last estimator after applying all transforms.
90 91 92 93 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 90 def predict_log_proba(x) trans_x = apply_transforms(x) last_estimator.predict_log_proba(trans_x) end |
#predict_proba(x) ⇒ Numo::DFloat
Call the predict_proba method of last estimator after applying all transforms.
99 100 101 102 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 99 def predict_proba(x) trans_x = apply_transforms(x) last_estimator.predict_proba(trans_x) end |
#score(x, y) ⇒ Float
Call the score method of last estimator after applying all transforms.
133 134 135 136 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 133 def score(x, y) trans_x = apply_transforms(x) last_estimator.score(trans_x, y) end |
#transform(x) ⇒ Numo::DFloat
Call the transform method of last estimator after applying all transforms.
108 109 110 111 |
# File 'rumale-pipeline/lib/rumale/pipeline/pipeline.rb', line 108 def transform(x) trans_x = apply_transforms(x) last_estimator.nil? ? trans_x : last_estimator.transform(trans_x) end |