我正在利用this答案,以便在形状为(294211001)[即29421行和11001列]的矩阵(ndarray)中找到大于给定极限f的相关系数。你知道吗
我对代码进行了如下调整(随机位选择要删除的两列之一;此外,与链接答案对应的行后面有“###”:
问题:我得到成千上万的相关系数大于1。。。据我所知,这不应该发生吗?你知道吗
rand = random()
rows = dataset_normalized.shape[0] ###
print("Rows: " + str(dataset_normalized.shape[0]) + ", Columns: " + str(dataset_normalized.shape[1]))
ms = dataset_normalized.mean(axis=1)[(slice(None, None, None), None)] ###
datam = dataset_normalized - ms ###
datass = np.sqrt(scipy.stats.ss(datam, axis=1)) ###
correlations = {}
percent_rand_one = 0
percent_rand_zero = 0
for i in range(rows): ###
if(0 in datass[i:] or datass[i] == 0):
continue
else:
temp = np.dot(datam[i:], datam[i].T) ###
rs = temp / (datass[i:] * datass[i]) ###
for counter, corr in enumerate(rs):
if(corr > 1 or corr < -1):
# ERROR IS HERE: This is printing right now,
# a lot, so I'm not sure what's happening?
print("Correlation of " + str(corr) + " on " + str(i) + " and " + str(counter) + ".")
print("Something went wrong. Correlations calculated were either above 1 or below -1.")
elif(corr > f or corr < f):
rand_int = randint(1, 100)
if(rand_int > 50):
correlations[counter] = corr
percent_rand_one += 1
else:
correlations[i] = corr
percent_rand_zero += 1
有什么建议或想法吗?你知道吗
弄明白了…这是最奇怪的事情。我只需要翻转轴。你知道吗
相关问题 更多 >
编程相关推荐