mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-31 05:33:47 +00:00
normalize data
This commit is contained in:
parent
015c6cf0c3
commit
28692922d4
15
normalize_data.py
Normal file
15
normalize_data.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Sebastian Raschka, 03/2014
|
||||
|
||||
def normalize_val(x, data_list):
|
||||
"""
|
||||
Normalizes a value to a data list returning a float
|
||||
between 0.0 and 1.0.
|
||||
Returns the original object if value is not a integer or float.
|
||||
|
||||
"""
|
||||
if isinstance(x, float) or isinstance(x, int):
|
||||
numerator = x - min(data_list)
|
||||
denominator = max(data_list) - min(data_list)
|
||||
return numerator/denominator
|
||||
else:
|
||||
return x
|
Loading…
Reference in New Issue
Block a user