且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python pandas标准化列以进行回归

更新时间:2023-01-31 12:08:55

我认为您正在寻找

I think you are looking for the sklearn.preprocessing.MinMaxScaler. That will allow you to scale to a given range.

因此,您的情况应该是:

So in your case it would be:

scaler = preprocessing.MinMaxScaler(feature_range=(0,1))
df['scaled_event_counts'] = scaler.fit_transform(df['Event_Counts'])

要缩放整个df:

scaled_df = scaler.fit_transform(df)
print(scaled_df)
[[ 0.          0.99722347  0.          1.        ]
 [ 1.          1.          1.          0.        ]
 [ 1.          0.          0.          1.        ]]