-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the possibility to transform the data: normalize/standardize
- Loading branch information
Showing
5 changed files
with
63 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Fri Aug 16 14:44:30 2013 | ||
@author: pietro | ||
""" | ||
|
||
|
||
# | ||
# TRANSFORMATION FUNCTIONS | ||
# | ||
def stdize(df, mean, std): | ||
return (df - mean) / std | ||
|
||
|
||
def normalize(df, xmin, xmax): | ||
return (df - xmin) / (xmax - xmin) | ||
|
||
|
||
def transform(method, data, chk): | ||
if method == 'standardize': | ||
mean, std = chk.mean(), chk.std() | ||
return stdize(data, mean, std), stdize(data, mean, std) | ||
elif method == 'normalize': | ||
xmin, xmax = chk.min(), chk.max() | ||
return normalize(data, xmin, xmax), normalize(chk, xmin, xmax) | ||
elif method == 'nothing': | ||
return data, chk | ||
else: | ||
raise ValueError('method: <%s> not valid' % method) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters