Uh oh!
There was an error while loading. Please reload this page.
Scale Corr - #623
Conversation
| pass | ||
| def corr(self): |
There was a problem hiding this comment.
Duplicate function definition. Other definition in line 507.
AlexanderKalistratov
commented
Feb 19, 2020
corr(x,y) = cov(x, y)/sqrt(var(x)*var(y)) Please note, that cov here is unbiased, while Series.cov calculates biased one Biasedcov calculation is here: Suggestion for var implementation is here: Considering all of it, corr calculation would be something like this: defhpat_pandas_series_corr_impl(self, other, min_periods=None):
ifmin_periodsisNoneormin_periods<1:
min_periods=1min_len=min(len(self._data), len(other._data))
ifmin_len==0:
returnnumpy.nansum_y=0.sum_x=0.sum_xy=0.sum_xx=0.sum_yy=0.total_count=0foriinprange(min_len):
x=self._data[i]
y=other._data[i]
ifnot (numpy.isnan(x) ornumpy.isnan(y)):
sum_x+=xsum_y+=ysum_xy+=x*ysum_xx+=x*xsum_yy+=y*ytotal_count+=1iftotal_count<min_periods:
returnnumpy.nancov_xy= (sum_xy-sum_x*sum_y/total_count)
var_x= (sum_xx-sum_x*sum_x/total_count)
var_y= (sum_yy-sum_y*sum_y/total_count)
corr_xy=cov_xy/sqrt(var_x*var_y)
returncorr_xyHaven't verified it. So, please, double check it and fix any mistakes in calculation. Also, if we had loops fusion, we'd be able to simply call three functions (cov(x,y), var(x) and var(y)). |
1e-to
commented
Feb 20, 2020
I tried to use our algorithms for var and cov to test fusing with Todd’s fix, but the unit tests stopped passing, the algorithm does not work correctly. Results have not needed accurancy. Does this mean that we need to rewrite the var and cov? |
AlexanderKalistratov
commented
Feb 20, 2020
It doesn't match because Series.conv calculates biased cov. And you need unbiased one. Have you tried the provided solution? |
Uh oh!
There was an error while loading. Please reload this page.