Class: ML::Data::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/data/parser.rb

Overview

Parser for traing/testing data

Instance Method Summary collapse

Instance Method Details

#parse_supervised(filename) ⇒ Hash

Parse the vector file with supervised result

Parameters:

  • filename (String)

    filename of the input data

Returns:

  • (Hash)

    map from data to supervised result



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/data/parser.rb', line 9

def parse_supervised filename
  result = {}
  lines = IO.readlines(filename)

  lines.each do |line|
    splitted = line.split.map(&:to_f)
    result[splitted[1..-1] + [1.0]] = splitted[0]
  end

  result
end

#parse_unsupervised(filename) ⇒ Array

Parse the vector file

Parameters:

  • filename (String)

    filename of the input data

Returns:

  • (Array)

    array of vectors



25
26
27
28
# File 'lib/data/parser.rb', line 25

def parse_unsupervised filename
  lines = IO.readlines(filename)
  lines.map {|line| line.split.map(&:to_f) }
end