在 Python 中的 scipy/numpy 中计算 2D 矩阵的 z 分数
如何在 Python 中计算矩阵的 z 分数?
假设我有数组:
a = array([[ 1, 2, 3],
[ 30, 35, 36],
[2000, 6000, 8000]])
并且我想计算每行的 z 分数。我想出的解决方案是:
array([zs(item) for item in a])
其中 zs 位于 scipy.stats.stats 中。有没有更好的内置矢量化方法来做到这一点?
另外,在使用欧几里德距离或塞几里德距离的层次聚类之前对数字进行 z 评分总是好的吗?有人可以讨论相对优点/缺点吗?
谢谢。
How can I compute the z-score for matrices in Python?
Suppose I have the array:
a = array([[ 1, 2, 3],
[ 30, 35, 36],
[2000, 6000, 8000]])
and I want to compute the z-score for each row. The solution I came up with is:
array([zs(item) for item in a])
where zs is in scipy.stats.stats. Is there a better built-in vectorized way to do this?
Also, is it always good to z-score numbers before using hierarchical clustering with euclidean or seuclidean distance? Can anyone discuss the relative advantages/disadvantages?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
scipy.stats.stats.zs 的定义如下:
因此,要将其扩展为在 ndarray 的给定轴上工作,您可以这样做:
scipy.stats.stats.zs is defined like this:
So to extend it to work on a given axis of an ndarray, you could do this:
下一个版本中提供的 scipy 新 zscore 采用任意数组维度
http://projects.scipy .org/scipy/changeset/6169
the new zscore of scipy, available in the next release takes arbitrary array dimension
http://projects.scipy.org/scipy/changeset/6169