Ejemplo n.º 1
0
 def fit(self, x: np.ndarray, groups: np.ndarray = None):
     if groups is not None:
         group_index = group_mapping(groups)
         self.mean = aggregate(group_index, x, 'mean')
         self.std = aggregate(group_index, x, 'std', self.ddof)
         self.labels = np.unique(groups)
     else:
         self.mean = simple_mean(x, axis=0)
         self.std = simple_std(x, axis=0, ddof=self.ddof)
Ejemplo n.º 2
0
def standardize(x: np.ndarray, groups: np.ndarray = None, ddof=1) -> np.ndarray:
    if groups is not None:
        groups = group_mapping(groups)
        mean_values = transform(groups, x, 'mean')
        std_values = transform(groups, x, 'std', ddof)

        return (x - mean_values) / np.maximum(std_values, 1e-8)
    else:
        return (x - simple_mean(x, axis=0)) / np.maximum(simple_std(x, axis=0, ddof=ddof), 1e-8)
Ejemplo n.º 3
0
def winsorize_normal(x: np.ndarray,
                     num_stds: int = 3,
                     groups: np.ndarray = None) -> np.ndarray:
    if groups is not None:
        groups = group_mapping(groups)
        mean_values = transform(groups, x, 'mean')
        std_values = transform(groups, x, 'std')
        res = mask_values_2d(x, mean_values, std_values, num_stds)
    else:
        std_values = simple_std(x, axis=0)
        mean_values = simple_mean(x, axis=0)
        res = mask_values_1d(x, mean_values, std_values, num_stds)
    return res
Ejemplo n.º 4
0
def winsorize_normal(x: np.ndarray,
                     num_stds: int = 3,
                     ddof=1,
                     groups: np.ndarray = None,
                     method: str = 'flat',
                     interval: float = 0.5) -> np.ndarray:
    if groups is not None:
        groups = group_mapping(groups)
        mean_values = transform(groups, x, 'mean')
        std_values = transform(groups, x, 'std', ddof)
        if method == 'flat':
            res = mask_values_2d(x, mean_values, std_values, num_stds)
        else:
            res = interp_values_2d(x, groups, mean_values, std_values,
                                   num_stds, interval)
    else:
        std_values = simple_std(x, axis=0, ddof=ddof)
        mean_values = simple_mean(x, axis=0)
        if method == 'flat':
            res = mask_values_1d(x, mean_values, std_values, num_stds)
        else:
            res = interp_values_1d(x, mean_values, std_values, num_stds,
                                   interval)
    return res
Ejemplo n.º 5
0
 def fit(self, x: np.ndarray):
     self.mean_ = simple_mean(x, axis=0)
     self.std_ = simple_std(x, axis=0, ddof=self.ddof_)