【问题标题】:Comparing two arrays which have very dispersed values比较两个具有非常分散值的数组
【发布时间】:2016-12-30 10:16:17
【问题描述】:

我有一个非常稀疏的数组,看起来像:

Array A: min = -68093253945.0 max=8.54631971208e+13
Array B: min=-1e+15 max = 1.87343e+14

而且每个数组都会集中在某些级别,例如2000 附近、1m 附近、0.05 附近等。

我正在尝试比较这两个数组的集中度,并希望以一种不受每个数组中条目数影响的方式进行比较。如果可能的话,我还想考虑巨大的异常值,并可能将 bin 压缩到 0 到 1 之间或类似的东西。

目的是通过以下方式制作直方图:

plt.hist(A,alpha=0.5,label='A')  # plt.hist passes it's arguments to np.histogram
ion()
plt.hist(B,alpha=0.5,label='B')
plt.title("Histogram of Values")
plt.legend(loc='upper right')
plt.savefig('valuecomp.png')

我该怎么做?我已经尝试过:

A = stats.zscore(A)
B = stats.zscore(B)

A = preprocessing.scale(A)
B = preprocessing.scale(B)

A = preprocessing.scale(A, axis=0, with_mean=True, with_std=True, copy=True)
B = preprocessing.scale(B, axis=0, with_mean=True, with_std=True, copy=True)

然后对于我的直方图,添加normed=Truerange(0,100)。所有的方法都给了我一个直方图,它有一个接近 0.0 的大量垂直块,而不是平滑地分布这些值。 range(0,100) 看起来不错,但它会忽略任何值,例如 100 之外的 1m。

也许我需要先从数据中删除异常值,然后再做直方图?

【问题讨论】:

  • 这是什么语言?你在使用 python 和 SciPy 吗?请编辑您的标签。
  • @ebyrob 完成。这是在python中,我也在使用matplotlib.pyplotsklearn.preprocessing
  • this这样的非恒定/动态bin-width直方图怎么样(来自astroml,也可以在astropy中获得)?

标签: python scipy histogram normalization binning


【解决方案1】:

@sascha 建议使用 AstroML 是一个不错的建议,但 knuthfreedman 版本似乎花费了天文数字的时间(请原谅双关语),而 blocks 版本只是简化了块。

我通过from scipy.special import expit 获取每个值的 sigmoid,然后以这种方式绘制直方图。只有这样我才能让它工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2020-04-30
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多