aboutsummaryrefslogtreecommitdiff
path: root/lib/mining/classifier/stats_interface.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-17 05:04:26 +0700
committerShulhan <ms@kilabit.info>2018-09-18 01:50:21 +0700
commit1cae4ca316afa5d177fdbf7a98a0ec7fffe76a3e (patch)
tree5fa83fc0faa31e09cae82ac4d467cf8ba5f87fc2 /lib/mining/classifier/stats_interface.go
parent446fef94cd712861221c0098dcdd9ae52aaed0eb (diff)
downloadpakakeh.go-1cae4ca316afa5d177fdbf7a98a0ec7fffe76a3e.tar.xz
Merge package "github.com/shuLhan/go-mining"
Diffstat (limited to 'lib/mining/classifier/stats_interface.go')
-rw-r--r--lib/mining/classifier/stats_interface.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/mining/classifier/stats_interface.go b/lib/mining/classifier/stats_interface.go
new file mode 100644
index 00000000..a9b60b9a
--- /dev/null
+++ b/lib/mining/classifier/stats_interface.go
@@ -0,0 +1,68 @@
+// Copyright 2016 Mhd Sulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package classifier
+
+//
+// ComputeFMeasures given array of precisions and recalls, compute F-measure
+// of each instance and return it.
+//
+func ComputeFMeasures(precisions, recalls []float64) (fmeasures []float64) {
+ // Get the minimum length of precision and recall.
+ // This is to make sure that we are not looping out of range.
+ minlen := len(precisions)
+ recallslen := len(recalls)
+ if recallslen < minlen {
+ minlen = recallslen
+ }
+
+ for x := 0; x < minlen; x++ {
+ f := 2 / ((1 / precisions[x]) + (1 / recalls[x]))
+ fmeasures = append(fmeasures, f)
+ }
+ return
+}
+
+//
+// ComputeAccuracies will compute and return accuracy from array of
+// true-positive, false-positive, true-negative, and false-negative; using
+// formula,
+//
+// (tp + tn) / (tp + tn + tn + fn)
+//
+func ComputeAccuracies(tp, fp, tn, fn []int64) (accuracies []float64) {
+ // Get minimum length of input, just to make sure we are not looping
+ // out of range.
+ minlen := len(tp)
+ if len(fp) < len(tn) {
+ minlen = len(fp)
+ }
+ if len(fn) < minlen {
+ minlen = len(fn)
+ }
+
+ for x := 0; x < minlen; x++ {
+ acc := float64(tp[x]+tn[x]) /
+ float64(tp[x]+fp[x]+tn[x]+fn[x])
+ accuracies = append(accuracies, acc)
+ }
+ return
+}
+
+//
+// ComputeElapsedTimes will compute and return elapsed time between `start`
+// and `end` timestamps.
+//
+func ComputeElapsedTimes(start, end []int64) (elaps []int64) {
+ // Get minimum length.
+ minlen := len(start)
+ if len(end) < minlen {
+ minlen = len(end)
+ }
+
+ for x := 0; x < minlen; x++ {
+ elaps = append(elaps, end[x]-start[x])
+ }
+ return
+}