Class: DataModeler::Base
- Inherits:
-
Object
- Object
- DataModeler::Base
- Defined in:
- lib/data_modeler/base.rb
Overview
Base class, core of the DataModeler framework.
-
Initializes the system based on the config
-
Runs over the data training and testing models
-
Results and models are saved to the file system
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#nruns ⇒ Object
readonly
Returns the value of attribute nruns.
-
#out_dir ⇒ Object
readonly
Returns the value of attribute out_dir.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
-
#test_size ⇒ Object
readonly
Returns the value of attribute test_size.
-
#train_size ⇒ Object
readonly
Returns the value of attribute train_size.
-
#tset_gen ⇒ Object
readonly
Returns the value of attribute tset_gen.
Instance Method Summary collapse
-
#initialize(config) ⇒ Base
constructor
A new instance of Base.
-
#run(report_interval: 1000) ⇒ void
Main control: up to
nruns(or until end of data) loop train-test-save. -
#save_models? ⇒ true|false
Attribute reader for instance variable ‘@save_models`, ending in ’?‘ since it’s a boolean value.
- #to_s ⇒ String
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/data_modeler/base.rb', line 14 def initialize config @config = config @inputs = config[:tset][:input_series].map! &:to_sym @targets = config[:tset][:target_series].map! &:to_sym @train_size = config[:tset][:train_size] @test_size = config[:tset][:test_size] @nruns = config[:tset][:nruns] ||= Float::INFINITY # terminates with data @save_models = config[:results].delete :save_models @data = load_data config[:data] @out_dir = prepare_output config[:results] @tset_gen = DataModeler::DatasetGen.new data, **opts_for(:datasetgen) @model = DataModeler::Models.selector **opts_for(:learner) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def config @config end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def data @data end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def inputs @inputs end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def model @model end |
#nruns ⇒ Object (readonly)
Returns the value of attribute nruns.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def nruns @nruns end |
#out_dir ⇒ Object (readonly)
Returns the value of attribute out_dir.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def out_dir @out_dir end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def targets @targets end |
#test_size ⇒ Object (readonly)
Returns the value of attribute test_size.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def test_size @test_size end |
#train_size ⇒ Object (readonly)
Returns the value of attribute train_size.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def train_size @train_size end |
#tset_gen ⇒ Object (readonly)
Returns the value of attribute tset_gen.
10 11 12 |
# File 'lib/data_modeler/base.rb', line 10 def tset_gen @tset_gen end |
Instance Method Details
#run(report_interval: 1000) ⇒ void
saves model, preds and obs to the file sistem at the end of each run
This method returns an undefined value.
Main control: up to nruns (or until end of data) loop train-test-save
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/data_modeler/base.rb', line 35 def run report_interval: 1000 1.upto(nruns) do |nrun; predictions, observations| # block-local variables begin train_set = tset_gen.train(nrun) rescue DataModeler::DatasetGen::NoDataLeft # will check if there's enough data for both train&test break end model.reset model.train train_set, report_interval: report_interval times, test_input, observations = tset_gen.test(nrun).values predictions = model.test test_input save_run nrun, model, [times, predictions, observations] end end |
#save_models? ⇒ true|false
Attribute reader for instance variable ‘@save_models`, ending in ’?‘ since it’s a boolean value.
55 56 57 |
# File 'lib/data_modeler/base.rb', line 55 def save_models? @save_models || false end |
#to_s ⇒ String
60 61 62 |
# File 'lib/data_modeler/base.rb', line 60 def to_s config.to_s end |