如何在 MATLAB 上使用 Pearson 相关性替换缺失值
我在 MATLAB 中使用“corr”函数时遇到问题,
a =
1 4 3 2
2 3 3 2
3 2 3 2
4 1 3 2
>> corr(a)
ans =
1 -1 NaN NaN
-1 1 NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
当我手动计算时,缺失值 (NaN) 是因为分母为零 (0)。 尽管如此,我们可以看到第 3 列和第 4 列的相似度为 1 (+1)。
有人知道如何增强或替换缺失的值吗?
谢谢之前。
I have problem with using 'corr' function in MATLAB,
a =
1 4 3 2
2 3 3 2
3 2 3 2
4 1 3 2
>> corr(a)
ans =
1 -1 NaN NaN
-1 1 NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
When I calculate manually, the Missing Value (NaN) is because the denominator is ZERO (0).
Although, we can be see that similarity of column 3 and 4 is ONE (+1).
Anyone know how to enhance or replace the missing value?
Thank's Before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您期望什么,相关性是两个变量之间线性相关性的度量,
计算为由标准差标准化的协方差(变量一起变化的程度)。
因此,如果一个变量是常量,则毫无意义(您得到零除以零,这是未定义的并报告为 NaN)...
What do you expect, correlation is a measure of linear dependence between two variables,
computed as the covariance (how much the variables change together) normalized by the standard deviations.
Thus it makes no sense if one variable is constant (you get zero divided by zero which is undefined and reported as NaN)...
正如 Amro 所说,
corr
正在报告正确的答案,但该答案是未定义的。如果您想以特殊方式处理未定义,例如设置为 1,您可以这样做:但听起来您的数据有一些更深层次的问题 - 没有足够的观察?为什么不删除相同的系列?
As Amro said,
corr
is reporting the correct answer, which is undefined. If you want to handle the undefineds a special way, such as setting to 1, you can do this:But it sounds like you have some deeper issues with your data - not enough observations? Why not remove identical series?