def z_score(x, axis=None): if not isinstance(x, R.Tensor): x = R.Tensor(x) if axis is not None: mean = R.mean(x, axis=axis) std = R.std(x, axis=axis) else: mean = R.mean(x) std = R.std(x) return R.div(R.sub(x, mean), std)
def start_info(self, X): """ Calculate mean and standard deviation """ for feature in zip(*X): yield {'std': R.std(feature), 'mean': R.mean(features)}
def standardize(x): """ Standardize an array """ if not isinstance(x, R.Tensor): x = R.Tensor(x) mean = R.mean(x) std = R.std(x) return R.div(R.sub(x, mean), std)
def stat_info(self, X): """ Calculate mean and standard deviation """ for feature in zip(*X): feature = R.Tensor(list(feature), name = 'feature') std = R.std(feature) mean = R.mean(feature) yield { 'std': std, 'mean': mean }