aboutsummaryrefslogtreecommitdiff
path: root/lib/mining
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-01-23 03:40:50 +0700
committerShulhan <ms@kilabit.info>2025-01-23 03:41:10 +0700
commit2a0694d2fa577574b505c4635eb8a824eaf88ddc (patch)
treecce840739c7f59893c3a6a65a1600f9f857c484e /lib/mining
parent605d847b236dde031a2e387e74298d66a27b5e0a (diff)
downloadpakakeh.go-2a0694d2fa577574b505c4635eb8a824eaf88ddc.tar.xz
all: use for-range with numeric
Go 1.22 now support for-range on numeric value.
Diffstat (limited to 'lib/mining')
-rw-r--r--lib/mining/classifier/cart/cart.go2
-rw-r--r--lib/mining/classifier/cm.go12
-rw-r--r--lib/mining/classifier/crf/crf.go8
-rw-r--r--lib/mining/classifier/stats_interface.go12
-rw-r--r--lib/mining/resampling/lnsmote/lnsmote.go8
-rw-r--r--lib/mining/resampling/smote/smote.go8
6 files changed, 25 insertions, 25 deletions
diff --git a/lib/mining/classifier/cart/cart.go b/lib/mining/classifier/cart/cart.go
index 2a26e71e..d72fb929 100644
--- a/lib/mining/classifier/cart/cart.go
+++ b/lib/mining/classifier/cart/cart.go
@@ -250,7 +250,7 @@ func (runtime *Runtime) SelectRandomFeature(claset tabula.ClasetInterface) {
// Select random features excluding feature in `excludeIdx`.
var pickedIdx []int
- for x := 0; x < runtime.NRandomFeature; x++ {
+ for range runtime.NRandomFeature {
idx := numbers.IntPickRandPositive(ncols, false, pickedIdx,
excludeIdx)
pickedIdx = append(pickedIdx, idx)
diff --git a/lib/mining/classifier/cm.go b/lib/mining/classifier/cm.go
index d84f75ff..48cf37b8 100644
--- a/lib/mining/classifier/cm.go
+++ b/lib/mining/classifier/cm.go
@@ -1,6 +1,6 @@
-// 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.
+// SPDX-FileCopyrightText: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package classifier
@@ -152,7 +152,7 @@ func (cm *CM) countNumeric(act, pred int64, actuals, predictions []int64) (
minlen = len(predictions)
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
if actuals[x] != act {
continue
}
@@ -233,7 +233,7 @@ func (cm *CM) GroupIndexPredictions(sampleListID []int,
min = len(predictions)
}
- for x := 0; x < min; x++ {
+ for x := range min {
if actuals[x] == 1 {
if predictions[x] == 1 {
cm.tpListID = append(cm.tpListID, sampleListID[x])
@@ -275,7 +275,7 @@ func (cm *CM) GroupIndexPredictionsStrings(sampleListID []int,
min = len(predictions)
}
- for x := 0; x < min; x++ {
+ for x := range min {
if actuals[x] == "1" {
if predictions[x] == "1" {
cm.tpListID = append(cm.tpListID, sampleListID[x])
diff --git a/lib/mining/classifier/crf/crf.go b/lib/mining/classifier/crf/crf.go
index ceb9b605..91a470cf 100644
--- a/lib/mining/classifier/crf/crf.go
+++ b/lib/mining/classifier/crf/crf.go
@@ -1,6 +1,6 @@
-// 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.
+// SPDX-FileCopyrightText: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package crf implement the cascaded random forest algorithm, proposed by
// Baumann et.al in their paper:
@@ -150,7 +150,7 @@ func (crf *Runtime) Build(samples tabula.ClasetInterface) (e error) {
fmt.Println(tag, "Sample (one row):", samples.GetRow(0))
fmt.Println(tag, "Config:", crf)
- for x := 0; x < crf.NStage; x++ {
+ for range crf.NStage {
forest, e := crf.createForest(samples)
if e != nil {
return e
diff --git a/lib/mining/classifier/stats_interface.go b/lib/mining/classifier/stats_interface.go
index f780d58b..38599d23 100644
--- a/lib/mining/classifier/stats_interface.go
+++ b/lib/mining/classifier/stats_interface.go
@@ -1,6 +1,6 @@
-// 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.
+// SPDX-FileCopyrightText: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package classifier
@@ -15,7 +15,7 @@ func ComputeFMeasures(precisions, recalls []float64) (fmeasures []float64) {
minlen = recallslen
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
f := 2 / ((1 / precisions[x]) + (1 / recalls[x]))
fmeasures = append(fmeasures, f)
}
@@ -38,7 +38,7 @@ func ComputeAccuracies(tp, fp, tn, fn []int64) (accuracies []float64) {
minlen = len(fn)
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
acc := float64(tp[x]+tn[x]) /
float64(tp[x]+fp[x]+tn[x]+fn[x])
accuracies = append(accuracies, acc)
@@ -55,7 +55,7 @@ func ComputeElapsedTimes(start, end []int64) (elaps []int64) {
minlen = len(end)
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
elaps = append(elaps, end[x]-start[x])
}
return
diff --git a/lib/mining/resampling/lnsmote/lnsmote.go b/lib/mining/resampling/lnsmote/lnsmote.go
index 524a4f54..4669446f 100644
--- a/lib/mining/resampling/lnsmote/lnsmote.go
+++ b/lib/mining/resampling/lnsmote/lnsmote.go
@@ -1,6 +1,6 @@
-// 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.
+// SPDX-FileCopyrightText: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package lnsmote implement the Local-Neighborhood algorithm from the paper,
//
@@ -93,7 +93,7 @@ func (in *Runtime) Resampling(dataset tabula.DatasetInterface) (
neighbors := in.FindNeighbors(in.datasetRows, p)
- for y := 0; y < in.NSynthetic; y++ {
+ for range in.NSynthetic {
syn := in.createSynthetic(p, neighbors)
if syn != nil {
diff --git a/lib/mining/resampling/smote/smote.go b/lib/mining/resampling/smote/smote.go
index f2603731..2ba2827c 100644
--- a/lib/mining/resampling/smote/smote.go
+++ b/lib/mining/resampling/smote/smote.go
@@ -1,6 +1,6 @@
-// Copyright 2015 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.
+// SPDX-FileCopyrightText: 2015 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package smote resamples a dataset by applying the Synthetic Minority
// Oversampling TEchnique (SMOTE). The original dataset must fit entirely in
@@ -81,7 +81,7 @@ func (smote *Runtime) populate(instance *tabula.Row, neighbors knn.Neighbors) {
err error
)
- for x := 0; x < smote.NSynthetic; x++ {
+ for range smote.NSynthetic {
// choose one of the K nearest neighbors
randv, err = rand.Int(rand.Reader, randMax)
if err != nil {