Sha256: ce5194577a8a17f63aa9357c450d60f416a2ec4ddb905f4532e4daf27ffc93f7
Contents?: true
Size: 1.7 KB
Versions: 8
Compression:
Stored size: 1.7 KB
Contents
require 'csv' require_relative 'dataset' module Datasets class Wine < Dataset Record = Struct.new(:label, :alcohol, :malic_acid, :ash, :alcalinity_of_ash, :n_magnesiums, :total_phenols, :total_flavonoids, :total_nonflavanoid_phenols, :total_proanthocyanins, :color_intensity, :hue, :optical_nucleic_acid_concentration, :n_prolines) def initialize super @metadata.id = 'wine' @metadata.name = 'Wine' @metadata.url = 'http://archive.ics.uci.edu/ml/datasets/wine' @metadata.description = -> { read_names } end 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 private def read_names names_path = cache_dir_path + 'wine.names' unless names_path.exist? names_url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.names' download(names_path, names_url) end names_path.read end def open_data data_path = cache_dir_path + 'wine.data' unless data_path.exist? data_url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data' download(data_path, data_url) end CSV.open(data_path, converters: %i[numeric]) do |csv| yield(csv) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems