简体   繁体   English

如何在没有 MinMaxScaler package 的情况下规范化 numpy 数组上的数据

[英]How to normalization data on numpy array, without MinMaxScaler package

how to normalize data without minmaxscaler package. here I have tried it according to the minmax scale formula. how to normalize data without minmaxscaler package.这里我按照minmax比例公式试过了。 but i get an error like this IndexError: invalid index to scalar variable.但我收到类似IndexError 的错误:标量变量的索引无效。

the code:代码:

scale = []

for i in range(0,6):
    minFP = FCData[:,i].min()
    maxFP = FCData[:,i].max()
    yscale = (FCData[:,i] - minFP[i]) / ( maxFP[i] - minFP[i])
    scale.append(yscale[i])

scale = np.array(scale)

my data: Data shape: (15000,6)我的数据:数据形状:(15000,6)

array([[     4.46733  ,      4.39629  ,    -34.2351   ,  -4077.23     ,
         -6206.81     ,   -874.539    ],
       [     7.65166  ,      2.61174  ,    -49.7356   ,  -4846.76     ,
         -9060.05     ,  -1291.39     ],
       [    11.285    ,     -2.91447  ,    -87.9661   ,  -5412.32     ,
        -16345.2      ,   -213.72     ],
       [    12.7313   ,     -6.48048  ,   -123.094    ,  -5939.48     ,
        -23005.6      ,    443.115    ],
       [    11.6425   ,      0.0259204,   -131.717    ,  -6972.53     ,
        -24651.9      ,  -1112.73     ],
       [    12.3602   ,     10.1988   ,   -139.597    ,  -8544.17     ,
        -26118.8      ,  -3260.79     ],
       [    16.0733   ,     12.1455   ,   -165.01     , -10371.5      ,
        -30873.5      ,  -3643.65     ],
       [    21.1933   ,      8.86926  ,   -210.599    , -12673.2      ,
        -39447.9      ,  -2785.69     ],
       [    24.3619   ,      7.59683  ,   -267.449    , -16170.6      ,
        -50300.9      ,  -2823.35     ]])

在此处输入图像描述

You should be able to do this on 1 line with:您应该能够在 1 行上执行此操作:

scaleddata = (FCData - FCData.min(axis=0)) / (FCData.max(axis=0) - FCData.min(axis=0))

or (thanks to @cards in the comments), this could be even shorter with:或者(感谢评论中的@cards),这可能会更短:

scaleddata = (FCData - FCData.min(axis=0)) / np.ptp(FCData, axis=0)

maxFP and minFP are just values rather than lists/arrays, so do not need the i index, eg, change yscale = (FCData[:,i] - minFP[i]) / ( maxFP[i] - minFP[i]) to yscale = (FCData[:,i] - minFP) / (maxFP - minFP) How to normalization data on numpy array, without MinMaxScaler package maxFP 和 minFP 只是值而不是列表/数组,因此不需要 i 索引,例如,更改 yscale = (FCData[:,i] - minFP[i]) / ( maxFP[i] - minFP[i])到 yscale = (FCData[:,i] - minFP) / (maxFP - minFP) 如何在 numpy 数组上标准化数据,没有 MinMaxScaler package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM