Module: Libsvm::CoreExtensions::Collection

Included in:
Array, Hash
Defined in:
lib/libsvm.rb

Instance Method Summary collapse

Instance Method Details

#to_exampleArray<Libsvm::Node>

Note:

In an upcoming major release this core extension will become no longer included in Hash and Array, but rather be optional.

Converts this collection into an array of feature.

{ 1 => 0.4, 3 => 0.5, 5 => 0.9 }.to_example
# => [#<Libsvm::Node: index=1, value=0.4>, #<Libsvm::Node: index=3, value=0.5>, #<Libsvm::Node: index=5, value=0.9>]
{ 1 => 0.4, 3 => 0.5, 5 => 0.9 }.to_example
# => [#<Libsvm::Node: index=1, value=0.4>, #<Libsvm::Node: index=3, value=0.5>, #<Libsvm::Node: index=5, value=0.9>]
[0.4, 0.5, 0.9].to_example
# => [#<Libsvm::Node: index=0, value=0.4>, #<Libsvm::Node: index=1, value=0.5>, #<Libsvm::Node: index=2, value=0.9>]
[ [1, 0.4], [3, 0.5], [5, 0.9] ].to_example
# => [#<Libsvm::Node: index=1, value=0.4>, #<Libsvm::Node: index=3, value=0.5>, #<Libsvm::Node: index=5, value=0.9>]

An array of features is the type used for classification and model learning.

Returns:



36
37
38
# File 'lib/libsvm.rb', line 36

def to_example
  Node.features(self)
end