Sha256: c7484e54ac618d694aae988ac41610209a7641436a9df2e804a746ba90a93c10
Contents?: true
Size: 876 Bytes
Versions: 2
Compression:
Stored size: 876 Bytes
Contents
module Training #:nodoc: # 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 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 protected def random_next(n) self.items[rand(n)] end end class DataFrame include Training end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
davidrichards-data_frame-0.0.19 | lib/data_frame/core/training.rb |
davidrichards-data_frame-0.0.20 | lib/data_frame/core/training.rb |