Class: Datasets::Communities
- Defined in:
- lib/datasets/communities.rb
Defined Under Namespace
Classes: Record
Instance Attribute Summary
Attributes inherited from Dataset
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize ⇒ Communities
constructor
A new instance of Communities.
Methods inherited from Dataset
Constructor Details
#initialize ⇒ Communities
Returns a new instance of Communities.
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/datasets/communities.rb', line 138 def initialize super() @metadata.id = "communities" @metadata.name = "Communities" @metadata.url = "https://archive.ics.uci.edu/ml/datasets/communities+and+crime" @metadata.licenses = ["CC-BY-4.0"] @metadata.description = lambda do read_names end end |
Instance Method Details
#each ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/datasets/communities.rb', line 149 def each return to_enum(__method__) unless block_given? open_data do |csv| csv.each do |row| row = row.collect.with_index do |column, i| if column == "?" nil else case i when 3 # communityname # when 124 # LemasGangUnitDeploy # 0 means NO, 1 means YES, 0.5 means Part Time else column = Float(column) end column end end record = Record.new(*row) yield(record) end end end |