3

Can anybody tell me how i can remove the below warning? I want to normalize a set of integer values by min-max normalization technique but i am getting this warning and don't know how to solve it? (X is a column of integer values starting from 0 to 127)

Here is the code:

X = df.iloc[:,0]
mms = MinMaxScaler()
a=X.reshape(-1, 1)
b=mms.fit_transform(a)
sns.set(color_codes=True)
np.random.seed(sum(map(ord, "distributions")))
ax=sns.distplot(b);
ax.set(xlabel='frequency', ylabel='Probability')
plt.show()

And here is the warning:

DataConversionWarning: Data with input dtype int64 was converted to float64 by MinMaxScaler. warnings.warn(msg, DataConversionWarning)
Grr
  • 15,553
  • 7
  • 65
  • 85
Shelly
  • 817
  • 3
  • 11
  • 16
  • 3
    If you want to scale integers, there is nothing you can do. Either you accept this auto-cast, or do it yourself earlier (either when reading in, or using array.astype()). The latter will have no warning then, but it results in the same behaviour. – sascha Apr 21 '17 at 17:07
  • 1
    @sascha can you clarify what you mean by using array.astype()? Where should i add this change? – Shelly Apr 21 '17 at 17:12
  • Did you consider googling the numpy docs with astype()? It's just some call to change the type. – sascha Apr 21 '17 at 17:52

1 Answers1

2

MinMaxScaler() works using float numbers, so it will automatically convert your np.array of type np.int to np.float and inform you about it. If you don't want to see this warning, do the conversion explicitly beforehand:

b = mms.fit_transform(a.astype(np.float))
Victor Deleau
  • 875
  • 5
  • 17
Jorge
  • 2,181
  • 1
  • 19
  • 30