def test_normalize_unnormalize_without_dataset(self, stats): result_normalized, _ = MainTransformer.normalize(None, {}, inplace=False) result_unnormalize = MainTransformer.unnormalize(None, {}, inplace=False) assert result_normalized is None and result_unnormalize is None
def test_normalize_and_unnormalize(self, stats): copied_dataset = pandas.DataFrame({ 'TestColumn': [1.0, 2.0, 3.0], 'TestColumn2': [5.0, 6.0, 7.0] }) unnormalized_dataset = copied_dataset.copy() normalized, statistics = MainTransformer.normalize(copied_dataset, inplace=False, stats=stats) if stats is None: mean_one = np.mean(copied_dataset['TestColumn']) std_one = np.std(copied_dataset['TestColumn']) mean_two = np.mean(copied_dataset['TestColumn2']) std_two = np.std(copied_dataset['TestColumn2']) else: mean_one = stats['TestColumn']['mean'] std_one = stats['TestColumn']['std'] mean_two = stats['TestColumn2']['mean'] std_two = stats['TestColumn2']['std'] copied_dataset['TestColumn'] -= mean_one copied_dataset['TestColumn2'] -= mean_two copied_dataset['TestColumn'] /= std_one copied_dataset['TestColumn2'] /= std_two manual_stats = { 'TestColumn': { 'mean': mean_one, 'std': std_one }, 'TestColumn2': { 'mean': mean_two, 'std': std_two } } assert copied_dataset.equals(normalized) assert statistics == manual_stats MainTransformer.unnormalize(normalized, statistics, inplace=True) print(unnormalized_dataset) print(normalized) assert unnormalized_dataset.equals(normalized)