Class: Liblinear::Model

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(file_name) ⇒ Liblinear::Model

Parameters:

  • file_name (String)

Returns:



15
16
17
18
19
# File 'lib/liblinear/model.rb', line 15

def load(file_name)
  model = self.new
  model.load(file_name)
  model
end

.train(problem, parameter) ⇒ Liblinear::Model

Parameters:

Returns:



7
8
9
10
11
# File 'lib/liblinear/model.rb', line 7

def train(problem, parameter)
  model = self.new
  model.train(problem, parameter)
  model
end

Instance Method Details

#biasFloat

Returns:

  • (Float)


59
60
61
# File 'lib/liblinear/model.rb', line 59

def bias
  @model.bias
end

#class_sizeInteger

Returns:

  • (Integer)


44
45
46
# File 'lib/liblinear/model.rb', line 44

def class_size
  @model.nr_class
end

#feature_sizeInteger

Returns:

  • (Integer)


49
50
51
# File 'lib/liblinear/model.rb', line 49

def feature_size
  @model.nr_feature
end

#feature_weightsArray <Float>

Returns:



54
55
56
# File 'lib/liblinear/model.rb', line 54

def feature_weights
  Liblinear::Array::Double.decode(@model.w, feature_size)
end

#labelsArray <Integer>

Returns:



64
65
66
# File 'lib/liblinear/model.rb', line 64

def labels
  Liblinear::Array::Integer.decode(@model.label, class_size)
end

#load(file_name) ⇒ Object

Parameters:

  • file_name (String)


29
30
31
# File 'lib/liblinear/model.rb', line 29

def load(file_name)
  @model = Liblinearswig.load_model(file_name)
end

#probability_model?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/liblinear/model.rb', line 69

def probability_model?
  Liblinearswig.check_probability_model(@model) == 1 ? true : false
end

#regression_model?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/liblinear/model.rb', line 74

def regression_model?
  Liblinearswig.check_regression_model(@model) == 1 ? true : false
end

#save(filename) ⇒ Object

Parameters:

  • filename (String)


39
40
41
# File 'lib/liblinear/model.rb', line 39

def save(filename)
  Liblinearswig.save_model(filename, @model)
end

#swigLiblinear::Model

Returns:



34
35
36
# File 'lib/liblinear/model.rb', line 34

def swig
  @model
end

#train(problem, parameter) ⇒ Object

Parameters:



24
25
26
# File 'lib/liblinear/model.rb', line 24

def train(problem, parameter)
  @model = Liblinearswig.train(problem.swig, parameter.swig)
end