Module: Training

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#test_set(opts = {}) ⇒ Object



31
32
33
34
35
# File 'lib/data_frame/core/training.rb', line 31

def test_set(opts={})
  @test_set = nil if opts[:reset]
  return @test_set if @test_set
  @test_set = self.items.exclusive_not(self.training_set)
end

#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
26
27
28
# File 'lib/data_frame/core/training.rb', line 8

def training_set(opts={})
  if opts[:reset]
    @training_set = nil 
    @test_set = nil
  end
  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