Files
fn_registry/functions/datascience/min_max_scale.go
T
egutierrez fc734029c1 feat: 15 funciones datascience — estadística, DSP e IO de datos
12 funciones puras con implementación real:
Standardize, MinMaxScale, Clip, RollingWindow, ZipSlices, GroupBy,
Histogram, Pearson, Autocorrelation, FFT (Cooley-Tukey), DetectOutliers, Impute

3 funciones impuras (stubs):
LoadCSV, LoadParquet, FetchDataFrame

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 02:23:36 +01:00

34 lines
580 B
Go

package datascience
import "math"
// MinMaxScale escala los valores al rango [0, 1] usando min-max normalización.
// Si min == max, retorna un slice de ceros.
func MinMaxScale(data []float64) []float64 {
n := len(data)
if n == 0 {
return []float64{}
}
minVal := math.Inf(1)
maxVal := math.Inf(-1)
for _, v := range data {
if v < minVal {
minVal = v
}
if v > maxVal {
maxVal = v
}
}
rang := maxVal - minVal
result := make([]float64, n)
if rang == 0 {
return result
}
for i, v := range data {
result[i] = (v - minVal) / rang
}
return result
}