Class: EasyML::Data::Dataset::Splits::InMemorySplit

Inherits:
Split
  • Object
show all
Includes:
GlueGun::DSL
Defined in:
lib/easy_ml/data/dataset/splits/in_memory_split.rb

Instance Method Summary collapse

Methods inherited from Split

#test, #train, #valid

Methods included from Utils

#append_to_csv, #expand_dir, #null_check

Constructor Details

#initialize(options) ⇒ InMemorySplit

Returns a new instance of InMemorySplit.



9
10
11
12
# File 'lib/easy_ml/data/dataset/splits/in_memory_split.rb', line 9

def initialize(options)
  super
  @data = {}
end

Instance Method Details

#cleanupObject



38
39
40
# File 'lib/easy_ml/data/dataset/splits/in_memory_split.rb', line 38

def cleanup
  @data.clear
end

#read(segment, split_ys: false, target: nil, drop_cols: [], &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/easy_ml/data/dataset/splits/in_memory_split.rb', line 18

def read(segment, split_ys: false, target: nil, drop_cols: [], &block)
  df = @data[segment]
  return nil if df.nil?

  df = sample_data(df) if sample < 1.0
  drop_cols &= df.columns
  df = df.drop(drop_cols) unless drop_cols.empty?

  if block_given?
    if split_ys
      xs, ys = split_features_targets(df, true, target)
      process_block_with_split_ys(block, nil, xs, ys)
    else
      process_block_without_split_ys(block, nil, df)
    end
  else
    split_features_targets(df, split_ys, target)
  end
end

#save(segment, df) ⇒ Object



14
15
16
# File 'lib/easy_ml/data/dataset/splits/in_memory_split.rb', line 14

def save(segment, df)
  @data[segment] = df
end

#split_atObject



42
43
44
# File 'lib/easy_ml/data/dataset/splits/in_memory_split.rb', line 42

def split_at
  @data.keys.empty? ? nil : Time.now
end