Issue
I have simple code below. I want to normalize all data together like one column. But I have so:
from sklearn.preprocessing import MinMaxScaler
data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]
scaler = MinMaxScaler()
print(data)
print(scaler.fit_transform(data))
[[-1, 2],
[-0.5, 6],
[0, 10],
[1, 18]]
[[0. 0. ]
[0.25 0.25]
[0.5 0.5 ]
[1. 1. ]]
Python separate columns and separately normalize it. And so we have the same values in two columns. In principle I would able to merge first and second columns in one and split after. But I don't thing that idea are the best.
Any ideas are welcome...
UPDATE:
I don't want normalized data per column. I want so.
from sklearn.preprocessing import MinMaxScaler
data = [[-1], [-0.5], [0], [1], [2], [6], [10], [18]]
scaler = MinMaxScaler()
print(data)
print(scaler.fit_transform(data))
[[-1], [-0.5], [0], [1], [2], [6], [10], [18]]
[[0. ]
[0.02631579]
[0.05263158]
[0.10526316]
[0.15789474]
[0.36842105]
[0.57894737]
[1. ]]
But I still want it will be two columns.
Like this:
[[0. , 0.15789474]
[0.02631579, 0.36842105]
[0.05263158, 0.57894737]
[0.10526316, 1. ]]
Solution
In your case, instead of using sklearn module, you should simply apply the min-max scaler transformation formula :
import numpy as np
data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]
print(data)
print((data-np.min(data))/(np.max(data)-np.min(data)))
[[-1, 2], [-0.5, 6], [0, 10], [1, 18]]
[[0. 0.15789474]
[0.02631579 0.36842105]
[0.05263158 0.57894737]
[0.10526316 1. ]]
Answered By - Lue Mar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.