lib/libmf/model.rb in libmf-0.2.6 vs lib/libmf/model.rb in libmf-0.3.0
- old
+ new
@@ -33,11 +33,18 @@
def save_model(path)
status = FFI.mf_save_model(model, path)
raise Error, "Cannot save model" if status != 0
end
+ alias_method :save, :save_model
+ def self.load(path)
+ model = Model.new
+ model.load_model(path)
+ model
+ end
+
def load_model(path)
@model = FFI.mf_load_model(path)
raise Error, "Cannot open model" if @model.null?
end
@@ -61,9 +68,37 @@
_factors(model[:p], rows, format)
end
def q_factors(format: nil)
_factors(model[:q], columns, format)
+ end
+
+ def rmse(data)
+ FFI.calc_rmse(create_problem(data), model)
+ end
+
+ def mae(data)
+ FFI.calc_mae(create_problem(data), model)
+ end
+
+ def gkl(data)
+ FFI.calc_gkl(create_problem(data), model)
+ end
+
+ def logloss(data)
+ FFI.calc_logloss(create_problem(data), model)
+ end
+
+ def accuracy(data)
+ FFI.calc_accuracy(create_problem(data), model)
+ end
+
+ def mpr(data, transpose)
+ FFI.calc_mpr(create_problem(data), model, transpose)
+ end
+
+ def auc(data, transpose)
+ FFI.calc_auc(create_problem(data), model, transpose)
end
private
def _factors(ptr, n, format)