【问题标题】:plt.hist showing the strange plot after preprocessing.normalizeplt.hist 显示 preprocessing.normalize 后的奇怪图
【发布时间】:2019-02-09 21:17:14
【问题描述】:

我是 Python 新手,所以我执行以下代码:

test1 = np.array([95, 91, 104, 93, 85, 107, 97, 90, 86, 93, 86, 90, 88, 89, 94, 96, 89, 99, 104, 101, 84, 84, 94, 87, 99, 85, 83, 107, 102, 80, 89, 88, 93, 101, 87, 100, 82, 90, 106, 81, 95])
plt.hist(test1)
plt.show()

得到这张图片:

在我标准化数据并再次检查绘图后:

plt.gcf().clear()
test2 = preprocessing.normalize([test1])
    plt.hist(test2)
    plt.show()

新图有不同的形状,在直方图上我看到每个数字代表一次,与第一个图相比,这对我来说看起来很奇怪。所以我希望 smth similat 首先绘制,但范围从 0 到 1。 我错在哪里了?

【问题讨论】:

    标签: python scikit-learn histogram normalize


    【解决方案1】:

    这是一种解决方案。你需要MinMaxScaler,其默认的标准化范围是(0,1)。更多信息请参考this官方页面sklearn

    from sklearn import preprocessing
    
    test1 = np.array([95, 91, 104, 93, 85, 107, 97, 90, 86, 93, 86, 90, 88, 89, 94, 96, 89, 99, 104, 101, 84, 84, 94, 87, 99, 85, 83, 107, 102, 80, 89, 88, 93, 101, 87, 100, 82, 90, 106, 81, 95])
    min_max_scaler = preprocessing.MinMaxScaler()
    test2 = min_max_scaler.fit_transform(test1.reshape(-1, 1));
    plt.hist(test2)
    

    输出

    【讨论】:

      猜你喜欢
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2018-06-05
      • 2013-12-09
      • 1970-01-01
      相关资源
      最近更新 更多