gpt4 book ai didi

python - 如何在所有列上使用 MinMaxScaler?

转载 作者:太空宇宙 更新时间:2023-11-04 02:17:53 26 4
gpt4 key购买 nike

现在,我的数据在一个 2 x 2 numpy 数组中。如果我要在数组上使用 MinMaxScaler fit_transform,它将逐列对其进行归一化,而我希望将整个 np 数组一起归一化。有办法吗?

最佳答案

为什么不按以下方式使用原始的 MinMaxScaler API:

  1. 将 X numpy 数组 reshape 为单列数组,
  2. 规模,
  3. 将结果重新整形为 X 数组的形状

    import numpy as np

    X = np.array([[-1, 2], [-0.5, 6]])
    scaler = MinMaxScaler()
    X_one_column = X.reshape([-1,1])
    result_one_column = scaler.fit_transform(X_one_column)
    result = result_one_column.reshape(X.shape)
    print(result)

输出

[[ 0.          0.42857143]
[ 0.07142857 1. ]]

关于python - 如何在所有列上使用 MinMaxScaler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52226200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com