Class: Liblinear::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/liblinear/example.rb

Class Method Summary collapse

Class Method Details

.array_to_hash(example_array) ⇒ Hash

Parameters:

Returns:

  • (Hash)

20
21
22
23
24
25
26
# File 'lib/liblinear/example.rb', line 20

def array_to_hash(example_array)
  example_hash = {}
  example_array.size.times do |index|
    example_hash[index + 1] = example_array[index]
  end
  example_hash
end

.max_feature_id(examples) ⇒ Integer

Parameters:

Returns:

  • (Integer)

6
7
8
9
10
11
12
13
14
15
16
# File 'lib/liblinear/example.rb', line 6

def max_feature_id(examples)
  max_feature_id = 0
  examples.each do |example|
    if example.is_a?(::Hash)
      max_feature_id = [max_feature_id, example.keys.max].max if example.size > 0
    else
      max_feature_id = [max_feature_id, example.size].max
    end
  end
  max_feature_id
end