测试适合度

时间:2016-08-14 16:12:32

标签: python dictionary chi-squared goodness-of-fit

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

除此之外,还有另一种方法可以测试适合度吗?

0 个答案:

没有答案