Class: SVMLight::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/svmredlight/model.rb

Overview

A model is the product of training a SVM, once created it can take documents as inputs and act of them (by for instance classifying them). Models can also be read from files created by svm_learn.

Constant Summary collapse

TYPES =
[:classification]

Class Method Summary collapse

Class Method Details

.new(type, documents_and_lables, learn_params, kernel_params, alphas = nil) ⇒ Object

Learns a model from a set of labeled documents.

Parameters:

  • type, (Symbol)

    what kind of model is this, classification, regression, etc. for now the only valid value is classification.

  • documents_and_lables (Array)

    documents and labels is an array of arrays where each inner array must have two elements, the first, a Document and the second a classification (normally +1 and -1)

  • learn_params (Hash)

    each key of learn_params is a string it that maps to a field of the LEARN_PARM struct in SVMLight

  • kernel_params (Hash)

    each key of kernel_params is a string it that maps to a field of the KERNEL_PARM struct in SVMLight

  • alphas (Array|Nil) (defaults to: nil)

    an array of alpha values

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/svmredlight/model.rb', line 14

def self.new(type, documents_and_lables, learn_params, kernel_params, alphas = nil )
  raise ArgumentError, "Supporte types are (for now) #{TYPES}" unless TYPES.include? type

  learn_classification(documents_and_lables, learn_params, kernel_params, false, alphas)
end