<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from base import Task <EOL> from percept . fields . base import List , Complex <EOL> import numpy as np <EOL> from percept . conf . base import settings <EOL> from percept . utils . models import RegistryCategories <EOL> from percept . tests . framework import NormalizationTester <EOL> import os <EOL> from percept . utils . input import DataFormats <EOL> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> class Normalize ( Task ) : <EOL> """<STR_LIT>""" <EOL> column_means = List ( ) <EOL> column_stdevs = List ( ) <EOL> category = RegistryCategories . preprocessors <EOL> tester = NormalizationTester <EOL> test_cases = [ { '<STR_LIT>' : os . path . abspath ( os . path . join ( settings . PACKAGE_PATH , '<STR_LIT>' ) ) , '<STR_LIT>' : DataFormats . csv } ] <EOL> data = Complex ( ) <EOL> help_text = "<STR_LIT>" <EOL> def train ( self , data , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . data = data <EOL> for i in xrange ( <NUM_LIT:0> , data . shape [ <NUM_LIT:1> ] ) : <EOL> column_mean = np . mean ( data . icol ( i ) ) <EOL> column_stdev = np . std ( data . icol ( i ) ) <EOL> self . column_means += [ column_mean ] <EOL> self . column_stdevs += [ column_stdev ] <EOL> self . data = self . predict ( data ) <EOL> def predict ( self , test_data , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if test_data . shape [ <NUM_LIT:1> ] != self . data . shape [ <NUM_LIT:1> ] : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> for i in xrange ( <NUM_LIT:0> , test_data . shape [ <NUM_LIT:1> ] ) : <EOL> test_data . loc [ : , i ] = test_data . icol ( i ) - self . column_means [ i ] <EOL> if int ( self . column_stdevs [ i ] ) != <NUM_LIT:0> : <EOL> test_data . loc [ : , i ] = test_data . icol ( i ) / self . column_stdevs [ i ] <EOL> return test_data </s>
