Class: Libmf::Model
- Inherits:
-
Object
- Object
- Libmf::Model
- Defined in:
- lib/libmf/model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #accuracy(data) ⇒ Object
- #auc(data, transpose) ⇒ Object
- #bias ⇒ Object
- #columns ⇒ Object
- #cv(data, folds: 5) ⇒ Object
- #factors ⇒ Object
- #fit(data, eval_set: nil) ⇒ Object
- #gkl(data) ⇒ Object
-
#initialize(**options) ⇒ Model
constructor
A new instance of Model.
- #load_model(path) ⇒ Object
- #logloss(data) ⇒ Object
- #mae(data) ⇒ Object
- #mpr(data, transpose) ⇒ Object
- #p_factors(format: nil) ⇒ Object
- #predict(row, column) ⇒ Object
- #q_factors(format: nil) ⇒ Object
- #rmse(data) ⇒ Object
- #rows ⇒ Object
- #save_model(path) ⇒ Object (also: #save)
Constructor Details
#initialize(**options) ⇒ Model
Returns a new instance of Model.
3 4 5 |
# File 'lib/libmf/model.rb', line 3 def initialize(**) @options = end |
Class Method Details
Instance Method Details
#accuracy(data) ⇒ Object
91 92 93 |
# File 'lib/libmf/model.rb', line 91 def accuracy(data) FFI.calc_accuracy(create_problem(data), model) end |
#auc(data, transpose) ⇒ Object
99 100 101 |
# File 'lib/libmf/model.rb', line 99 def auc(data, transpose) FFI.calc_auc(create_problem(data), model, transpose) end |
#bias ⇒ Object
63 64 65 |
# File 'lib/libmf/model.rb', line 63 def bias model[:b] end |
#columns ⇒ Object
55 56 57 |
# File 'lib/libmf/model.rb', line 55 def columns model[:n] end |
#cv(data, folds: 5) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/libmf/model.rb', line 26 def cv(data, folds: 5) problem = create_problem(data) # TODO update fork to differentiate between bad parameters and zero error res = FFI.mf_cross_validation(problem, folds, param) raise Error, "cv failed" if res == 0 res end |
#factors ⇒ Object
59 60 61 |
# File 'lib/libmf/model.rb', line 59 def factors model[:k] end |
#fit(data, eval_set: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/libmf/model.rb', line 7 def fit(data, eval_set: nil) train_set = create_problem(data) @model = if eval_set eval_set = create_problem(eval_set) FFI.mf_train_with_validation(train_set, eval_set, param) else FFI.mf_train(train_set, param) end raise Error, "fit failed" if @model.null? nil end |
#gkl(data) ⇒ Object
83 84 85 |
# File 'lib/libmf/model.rb', line 83 def gkl(data) FFI.calc_gkl(create_problem(data), model) end |
#load_model(path) ⇒ Object
46 47 48 49 |
# File 'lib/libmf/model.rb', line 46 def load_model(path) @model = FFI.mf_load_model(path) raise Error, "Cannot open model" if @model.null? end |
#logloss(data) ⇒ Object
87 88 89 |
# File 'lib/libmf/model.rb', line 87 def logloss(data) FFI.calc_logloss(create_problem(data), model) end |
#mae(data) ⇒ Object
79 80 81 |
# File 'lib/libmf/model.rb', line 79 def mae(data) FFI.calc_mae(create_problem(data), model) end |
#mpr(data, transpose) ⇒ Object
95 96 97 |
# File 'lib/libmf/model.rb', line 95 def mpr(data, transpose) FFI.calc_mpr(create_problem(data), model, transpose) end |
#p_factors(format: nil) ⇒ Object
67 68 69 |
# File 'lib/libmf/model.rb', line 67 def p_factors(format: nil) _factors(model[:p], rows, format) end |
#predict(row, column) ⇒ Object
22 23 24 |
# File 'lib/libmf/model.rb', line 22 def predict(row, column) FFI.mf_predict(model, row, column) end |
#q_factors(format: nil) ⇒ Object
71 72 73 |
# File 'lib/libmf/model.rb', line 71 def q_factors(format: nil) _factors(model[:q], columns, format) end |
#rmse(data) ⇒ Object
75 76 77 |
# File 'lib/libmf/model.rb', line 75 def rmse(data) FFI.calc_rmse(create_problem(data), model) end |
#rows ⇒ Object
51 52 53 |
# File 'lib/libmf/model.rb', line 51 def rows model[:m] end |