Scipy有一种使用数组计算拟合优度的相当好的方法。
import scipy, scipy.stats.chisquare
observed_values=scipy.array([1,1])
expected_values=scipy.array([2,2])
chisquare(observed_values, f_exp=expected_values)
def chisquare(observed_values,expected_values): #Calculating the value for the test statistic,x^2
test_statistic=0
for observed, expected in zip(observed_values, expected_values):
test_statistic+=(float(observed)-float(expected))**2/float(expected)
return test_statistic
除此之外,还有另一种方法可以测试适合度吗?