Class: Datasets::Adult

Inherits:
Dataset show all
Defined in:
lib/datasets/adult.rb

Defined Under Namespace

Classes: Record

Instance Attribute Summary

Attributes inherited from Dataset

#metadata

Instance Method Summary collapse

Methods inherited from Dataset

#clear_cache!, #to_table

Constructor Details

#initialize(type: :train) ⇒ Adult

Returns a new instance of Adult.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datasets/adult.rb', line 25

def initialize(type: :train)
  unless [:train, :test].include?(type)
    raise ArgumentError, 'Please set type :train or :test'
  end

  super()
  @type = type
  @metadata.id = "adult-#{@type}"
  @metadata.name = "Adult: #{@type}"
  @metadata.url = "http://archive.ics.uci.edu/ml/datasets/adult"
  @metadata.description = lambda do
    read_names
  end
end

Instance Method Details

#eachObject


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/datasets/adult.rb', line 40

def each
  return to_enum(__method__) unless block_given?

  open_data do |csv|
    csv.each do |row|
      next if row[0].nil?
      record = Record.new(*row)
      yield(record)
    end
  end
end