3
I need to normalize the data I have so that it stays between -1 and 1.
I used Standardscaler, but the interval got longer.
What other sklearn library could you use? There are several in sklearn, but I could not, should make life easier, but I believe that I am not knowing how to use.
What I tried was:
df = pd.read_fwf('traco_treino.txt', header=None)
plt.plot(df)
Data in range -4 and 4
After the normalisation attempt:
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(df)
dftrans = scaler.transform(df)
plt.plot(dftrans)
The data is between -10 and 10.
Hello Gomiero, thanks for the help. However, it is not working. My data is a column of values. So I turned it into a dataframe with pandas, so it had two columns. Is that the problem? It only works in a 2D array?
– Klel
The columns of Dataframe are arrays therefore should work smoothly. Check whether the way you are creating the Dataframe is correct and if the data types are ok
– Gomiero
Hello Gomiero, my data are . txt, how could I do? When I create Dataframe, I create a column with indexes from 0 to 2999 (data size is 3000), in addition to txt values.
– Klel
Assuming the data is in a column
'a'
of Dataframe, try to transform the values into an np.array of the column type (eg:dd = dados['a'].values.reshape(-1,1)
). After thereshape
, execute thep.fit(dd)
and theprint(p.transform(dd)
. I believe the problem isreshape
so that the Scaler work– Gomiero
Array 1D does not give, gives error, but it was 2D. I must have done something wrong the other time, now it worked. Thanks!
– Klel