Files
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

39 lines
697 B
Go

package datascience
import "math"
// DetectOutliers devuelve un []bool donde true indica que el valor es un outlier
// según z-score. Un valor es outlier si |z-score| > threshold.
func DetectOutliers(data []float64, threshold float64) []bool {
n := len(data)
if n == 0 {
return []bool{}
}
var sum float64
for _, v := range data {
sum += v
}
mean := sum / float64(n)
var sqSum float64
for _, v := range data {
d := v - mean
sqSum += d * d
}
stddev := math.Sqrt(sqSum / float64(n))
result := make([]bool, n)
if stddev == 0 {
return result
}
for i, v := range data {
z := (v - mean) / stddev
if z < 0 {
z = -z
}
result[i] = z > threshold
}
return result
}