Skip to content

Commit 275a4b3

Browse files
committed
feat(metric): add kurtosis
1 parent 1c72df3 commit 275a4b3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

neuralnetlib/metrics.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,22 @@ def regularized_incomplete_beta(a: float, b: float, x: float) -> float:
572572

573573
result = np.exp(ln_term) * sum_term / a
574574
return result
575+
576+
577+
def kurtosis(x: np.ndarray) -> float:
578+
if x.ndim != 1:
579+
raise ValueError("Input array must be 1D.")
580+
if x.size < 2:
581+
raise ValueError("Array must have at least 2 elements.")
582+
583+
n = x.size
584+
mean = np.mean(x)
585+
deviations = x - mean
586+
m2 = np.mean(deviations**2)
587+
m4 = np.mean(deviations**4)
588+
589+
if m2 == 0:
590+
raise ValueError("Array must have variance greater than 0.")
591+
592+
kurt = (n * m4) / (m2**2) - 3
593+
return kurt

0 commit comments

Comments
 (0)