Class: Datasets::LIBSVM::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/datasets/libsvm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, features) ⇒ Record

Returns a new instance of Record.



10
11
12
13
# File 'lib/datasets/libsvm.rb', line 10

def initialize(label, features)
  @label = label
  @features = features
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



9
10
11
# File 'lib/datasets/libsvm.rb', line 9

def features
  @features
end

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/datasets/libsvm.rb', line 8

def label
  @label
end

Instance Method Details

#[](index) ⇒ Object



15
16
17
# File 'lib/datasets/libsvm.rb', line 15

def [](index)
  @features[index]
end

#to_hObject



19
20
21
22
23
24
25
26
27
# File 'lib/datasets/libsvm.rb', line 19

def to_h
  hash = {
    label: @label,
  }
  @features.each_with_index do |feature, i|
    hash[i] = feature
  end
  hash
end

#valuesObject



29
30
31
# File 'lib/datasets/libsvm.rb', line 29

def values
  [@label] + @features
end