13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/treat/workers/learners/classifiers/linear.rb', line 13
def self.classify(entity, options = {})
options = DefaultOptions.merge(options)
dset = options[:training]
prob, items = dset.problem, dset.items
if !@@classifiers[prob]
lparam = LParameter.new
lparam.solver_type = options[:solver_type]
lparam.eps = options[:eps]
lbls = items.map { |it| it[:features][-1] }
exs = items.map { |it| it[:features][0..-2] }.
map { |ary| self.array_to_hash(ary) }
lprob = LProblem.new(lbls, exs, options[:bias])
model = LModel.new(lprob, lparam)
@@classifiers[prob] = model
end
features = prob.export_features(entity, false)
@@classifiers[prob].predict(
self.array_to_hash(features))
end
|