使用scipy的Y值包含NAN的线性回归

时间:2015-11-05 16:15:44

标签: python arrays numpy scipy linear-regression

我有两个一维数组,我想做一些线性回归。 我用过:

slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)

但是斜率和截距总是NAN,NAN。我读了一点,我发现如果x或y有一些NAN,那就是预期的结果。我尝试了这个solution,但它不起作用,因为在我的情况下,只有y包含一些NAN;不是x。所以使用该解决方案,我有错误: ValueError: all the input array dimensions except for the concatenation axis must match exactly.

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

屏蔽xy NaN y的值xm = np.ma.masked_array(x,mask=np.isnan(y)).compressed() ym = np.ma.masked_array(y,mask=np.isnan(y)).compressed() slope, intercept, r_value, p_value, std_err = stats.linregress(xm, ym) 中的值:

ionic platform add android