Module: Training

Included in:
DataFrame
Defined in:
lib/data_frame/core/training.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#training_set(opts = {}) ⇒ Object

Remove the training set if reset Return cached training_set, if there is one Get the proportion or 80% Get the number of items to choose, n, or a proportion of the items Store and return n random items



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/data_frame/core/training.rb', line 8

def training_set(opts={})
  @training_set = nil if opts[:reset]
  return @training_set if @training_set
  
  items_size = self.items.size
  proportion = opts.fetch(:proportion, 0.8)
  n = opts[:n]
  n ||= (items_size * proportion).to_i
  n = self.items.size if n > items_size
  n = 0 if n < 0
  
  @training_set = []
  while n > @training_set.size
    @training_set << random_next(items_size) while n > @training_set.size
    @training_set.uniq!
  end
  @training_set
end