Class: DataModeler::Framework
- Inherits:
-
Object
- Object
- DataModeler::Framework
- Defined in:
- lib/data_modeler/framework.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) ⇒ Framework
constructor
A new instance of Framework.
-
#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) ⇒ Framework
Returns a new instance of Framework.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/data_modeler/framework.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[:data].delete :save_models @data = load_data config[:data].delete :input_file @out_dir = prepare_output config[:data] @tset_gen = DataModeler::Dataset::Generator.new data, **opts_for(:dataset_gen) @model = DataModeler::Model.selector **opts_for(:learner) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/data_modeler/framework.rb', line 10 def config @config end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/data_modeler/framework.rb', line 10 def data @data end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
10 11 12 |
# File 'lib/data_modeler/framework.rb', line 10 def inputs @inputs end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
10 11 12 |
# File 'lib/data_modeler/framework.rb', line 10 def model @model end |
#nruns ⇒ Object (readonly)
Returns the value of attribute nruns.
10 11 12 |
# File 'lib/data_modeler/framework.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/framework.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/framework.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/framework.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/framework.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/framework.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 50 51 52 53 54 55 56 57 |
# File 'lib/data_modeler/framework.rb', line 35 def run report_interval: 1000 printing = report_interval && report_interval > 0 over_nruns = nruns == Float::INFINITY ? "" : "/#{nruns}" puts "\nStarting @ #{Time.now}\n#{self}" if printing 1.upto(nruns) do |nrun| begin train_set = tset_gen.train(nrun) rescue DataModeler::Dataset::Generator::NoDataLeft break # there's not enough data left for a train+test set pair end puts "\nRun #{nrun}#{over_nruns} -- starting @ #{Time.now}" if printing model.reset puts "-Training" if printing model.train train_set, report_interval: report_interval puts "-Testing" if printing times, test_input, observations = tset_gen.test(nrun).values predictions = model.test test_input puts "-Saving" if printing save_run nrun, model, [times, predictions, observations] puts "Run #{nrun}#{over_nruns} -- ending @ #{Time.now}" if printing end puts "\nDone! @ #{Time.now}" if printing end |
#save_models? ⇒ true|false
Attribute reader for instance variable ‘@save_models`, ending in ’?‘ since it’s a boolean value.
63 64 65 |
# File 'lib/data_modeler/framework.rb', line 63 def save_models? @save_models || false end |
#to_s ⇒ String
68 69 70 |
# File 'lib/data_modeler/framework.rb', line 68 def to_s config.to_s end |