Python Forum

Full Version: Error while writing a code for feature scaling
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am trying to write a code for doing feature scaling but getting an error. Please help me out with this.

def featureScaling(arr):
ndata = []
for e in arr:
x = float((e-min(arr))/(max(arr)-min(arr)))
ndata.append(x)

return ndata

data = [115, 140, 175]
print featureScaling(data)



Ouput i am getting - [0.0, 0.0, 1.0]

Correct Output - [0.0, 0.41, 1.0]
Please fix indentation (use ctrl-shift-v when pasting) and enclose in code tags (BBCODE)