[+] Add stddev to scientific utils

This commit is contained in:
Azalea (on HyDEV-Daisy)
2022-08-25 23:16:48 -04:00
parent fb57ec06ae
commit f990731261
2 changed files with 12 additions and 4 deletions
+1
View File
@@ -1,6 +1,7 @@
""" """
Natual language processing utils Natual language processing utils
""" """
from __future__ import annotations
def camel_split(camel: str) -> list[str]: def camel_split(camel: str) -> list[str]:
+11 -4
View File
@@ -3,9 +3,7 @@ Importing this file requires numpy, matplotlib, and numba
""" """
from __future__ import annotations from __future__ import annotations
import time
from dataclasses import dataclass from dataclasses import dataclass
from typing import Callable
import numpy as np import numpy as np
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
@@ -23,13 +21,21 @@ class Statistics:
maximum: float maximum: float
count: int count: int
total: float total: float
stddev: float
def get_metric_6(self) -> tuple[float, float, float, float, float, float]: def get_metric_6(self) -> tuple[float, float, float, float, float, float]:
return self.mean, self.median, self.minimum, self.maximum, self.lower_quartile, self.upper_quartile return self.mean, self.median, self.minimum, self.maximum, self.lower_quartile, self.upper_quartile
def print(self, dec: int = 2):
print(f'> Mean: {round(self.mean, dec)}, Median: {round(self.median, dec)}')
print(f'> Min: {round(self.minimum, dec)}, Max: {round(self.maximum, dec)}')
print(f'> Q1: {round(self.lower_quartile, dec)}, Q3: {round(self.upper_quartile, dec)}')
print(f'> StdDev: {round(self.stddev, dec)}, IQR: {round(self.iqr, dec)}')
print(f'> N: {self.count}')
@njit(cache=True) @njit(cache=True)
def _calc_col_stats_helper(col: np.ndarray) -> tuple[float, float, float, float, float, float, float, int, float]: def _calc_col_stats_helper(col: np.ndarray) -> tuple[float, float, float, float, float, float, float, int, float, float]:
q1 = np.quantile(col, 0.25) q1 = np.quantile(col, 0.25)
q3 = np.quantile(col, 0.75) q3 = np.quantile(col, 0.75)
return ( return (
@@ -41,7 +47,8 @@ def _calc_col_stats_helper(col: np.ndarray) -> tuple[float, float, float, float,
float(np.min(col)), float(np.min(col)),
float(np.max(col)), float(np.max(col)),
len(col), len(col),
float(np.sum(col)) float(np.sum(col)),
float(np.std(col))
) )