Class: Libffm::Model

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

Instance Method Summary collapse

Constructor Details

#initialize(eta: 0.2, lambda: 0.00002, nr_iters: 15, k: 4, normalization: true, auto_stop: false) ⇒ Model

Returns a new instance of Model.



3
4
5
6
7
8
9
10
11
12
# File 'lib/libffm/model.rb', line 3

def initialize(eta: 0.2, lambda: 0.00002, nr_iters: 15, k: 4, normalization: true, auto_stop: false)
  @eta = eta
  @lambda = lambda
  @nr_iters = nr_iters
  @k = k
  @normalization = normalization
  @auto_stop = auto_stop

  @model = nil
end

Instance Method Details

#fit(data, eval_set: nil) ⇒ Object



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

def fit(data, eval_set: nil)
  Dir.mktmpdir do |dir|
    @model = Ext.fit(data, eval_set || "", File.join(dir, ""), @eta, @lambda, @nr_iters, @k, @normalization, @auto_stop)
    add_finalizer(@model)
  end
end

#load_model(path) ⇒ Object



30
31
32
33
# File 'lib/libffm/model.rb', line 30

def load_model(path)
  @model = Ext.load_model(path)
  add_finalizer(@model)
end

#predict(data) ⇒ Object



21
22
23
24
# File 'lib/libffm/model.rb', line 21

def predict(data)
  raise "Not fit" unless @model
  Ext.predict(@model, data)
end

#save_model(path) ⇒ Object



26
27
28
# File 'lib/libffm/model.rb', line 26

def save_model(path)
  Ext.save_model(@model, path)
end