仍然在使用Python开始我的旅程,所以这是一个我不理解的简单问题
尝试从这里使用Zigy对Cramer V统计的定义声明: Using pandas, calculate Cramér's coefficient matrix
但当我将其放入Python时,定义并没有在返回时结束:
>>> import pandas as pd
>>> def cramers_corrected_stat(confusion_matrix):
... # calculate Cramers V statistic for categorial-categorial association.
... # uses correction from Bergsma and Wicher,
... # Journal of the Korean Statistical Society 42 (2013): 323-328
...
... chi2 = ss.chi2_contingency(confusion_matrix)[0]
... n = confusion_matrix.sum()
... phi2 = chi2/n
... r,k = confusion_matrix.shape
... phi2corr = max(0, phi2 - ((k-1)*(r-1))/(n-1))
... rcorr = r - ((r-1)**2)/(n-1)
... kcorr = k - ((k-1)**2)/(n-1)
... return np.sqrt(phi2corr / min( (kcorr-1), (rcorr-1)))
...
我没有看到什么
在REPL中,需要两个连续的空行来完成语句。但是,在REPL中编写代码非常麻烦,因为您无法轻松编辑/修复以前编写的代码,因此我建议您将所做的任何事情保存到
.py
文件中,在该文件中您可以更轻松地编辑代码,然后通过python ./myfile.py
运行代码相关问题 更多 >
编程相关推荐