Sha256: 457606415275875f81f6582219a8684f6ac6b9732d5c2220d6ee7f2f8c89c767

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

module EasyML
  module Data
    class Dataset
      module Splits
        class InMemorySplit < Split
          include GlueGun::DSL

          attribute :sample, :float, default: 1.0
          def initialize(options)
            super
            @data = {}
          end

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

          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

          def cleanup
            @data.clear
          end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
easy_ml-0.1.4 lib/easy_ml/data/dataset/splits/in_memory_split.rb
easy_ml-0.1.3 lib/easy_ml/data/dataset/splits/in_memory_split.rb
easy_ml-0.1.2 lib/easy_ml/data/dataset/splits/in_memory_split.rb
easy_ml-0.1.1 lib/easy_ml/data/dataset/splits/in_memory_split.rb