diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-23 03:40:50 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-23 03:41:10 +0700 |
| commit | 2a0694d2fa577574b505c4635eb8a824eaf88ddc (patch) | |
| tree | cce840739c7f59893c3a6a65a1600f9f857c484e /lib/mining/classifier | |
| parent | 605d847b236dde031a2e387e74298d66a27b5e0a (diff) | |
| download | pakakeh.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/classifier')
| -rw-r--r-- | lib/mining/classifier/cart/cart.go | 2 | ||||
| -rw-r--r-- | lib/mining/classifier/cm.go | 12 | ||||
| -rw-r--r-- | lib/mining/classifier/crf/crf.go | 8 | ||||
| -rw-r--r-- | lib/mining/classifier/stats_interface.go | 12 |
4 files changed, 17 insertions, 17 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 |
