Class: Rumale::Pipeline::Pipeline
- Inherits:
-
Object
- Object
- Rumale::Pipeline::Pipeline
- Includes:
- Base::BaseEstimator
- Defined in:
- 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 included from Base::BaseEstimator
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.
-
#marshal_dump ⇒ Hash
Dump marshal data.
-
#marshal_load(obj) ⇒ nil
Load marshal data.
-
#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 'lib/rumale/pipeline/pipeline.rb', line 30 def initialize(steps:) check_params_type(Hash, steps: steps) validate_steps(steps) @params = {} @steps = steps end |
Instance Attribute Details
#steps ⇒ Hash (readonly)
Return the steps.
24 25 26 |
# File '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.
75 76 77 78 79 |
# File 'lib/rumale/pipeline/pipeline.rb', line 75 def decision_function(x) check_sample_array(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 47 |
# File 'lib/rumale/pipeline/pipeline.rb', line 42 def fit(x, y) check_sample_array(x) 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.
54 55 56 57 58 |
# File 'lib/rumale/pipeline/pipeline.rb', line 54 def fit_predict(x, y = nil) check_sample_array(x) 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.
65 66 67 68 69 |
# File 'lib/rumale/pipeline/pipeline.rb', line 65 def fit_transform(x, y = nil) check_sample_array(x) 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.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rumale/pipeline/pipeline.rb', line 125 def inverse_transform(z) check_sample_array(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 |
#marshal_dump ⇒ Hash
Dump marshal data.
149 150 151 152 |
# File 'lib/rumale/pipeline/pipeline.rb', line 149 def marshal_dump { params: @params, steps: @steps } end |
#marshal_load(obj) ⇒ nil
Load marshal data.
156 157 158 159 160 |
# File 'lib/rumale/pipeline/pipeline.rb', line 156 def marshal_load(obj) @params = obj[:params] @steps = obj[:steps] nil end |
#predict(x) ⇒ Numo::NArray
Call the predict method of last estimator after applying all transforms.
85 86 87 88 89 |
# File 'lib/rumale/pipeline/pipeline.rb', line 85 def predict(x) check_sample_array(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.
95 96 97 98 99 |
# File 'lib/rumale/pipeline/pipeline.rb', line 95 def predict_log_proba(x) check_sample_array(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.
105 106 107 108 109 |
# File 'lib/rumale/pipeline/pipeline.rb', line 105 def predict_proba(x) check_sample_array(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.
141 142 143 144 145 |
# File 'lib/rumale/pipeline/pipeline.rb', line 141 def score(x, y) check_sample_array(x) 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.
115 116 117 118 119 |
# File 'lib/rumale/pipeline/pipeline.rb', line 115 def transform(x) check_sample_array(x) trans_x = apply_transforms(x) last_estimator.nil? ? trans_x : last_estimator.transform(trans_x) end |