I have two dataset that I want to run a running window over and calculate the R^2 value for each window. What I have is:
import numpy as np
from scipy.ndimage.filters import generic_filter
from sklearn.metrics import r2_score
data1 = np.random.randint(1,100,size=(100,50))
data2 = np.random.randint(1,100,size=(100,50))
array = np.ones(np.shape(data1))
def function(array):
return r2_score(data1,data2)
window = generic_filter(array,function,footprint=np.ones((3,3)),mode='nearest')
So basically a R^2 value should be calculated for each 3x3 box and that value placed in the center of where that box was like:
0 0 0
0 R^2 0
0 0 0
And then it would move over to the next point and calculate another R^2 and so on for the whole array of size (100x50). When I run this though it creates an array that's 100x50 but it's all the same value. I think it's calculating the R^2 for the entire data1 and data2 instead of each footprint size. I'm not exactly sure what I need to pass into function instead of array.