簡體   English   中英

使用卡方找到擬合優度

[英]Using Chi-Squared to find the goodness of a fit

我正在嘗試使用 scipy.stats chisquare 工具來確定兩個數組之間的擬合優度。 我使用了擬合為 10 的 np.polyfit 工具來找到兩個數組之間的擬合,現在我只是想弄清楚如何使用卡方方法來確定擬合的好壞。 在這種情況下如何正確使用 scipy 的卡方工具?

data = np.loadtxt("location of data")

x = data[:,0] #defining the first column as x
y = data[:,1] #defining the second column as y

fit = np.polyfit(x, y, 10)
p = np.poly1d(fit)

import scipy
from scipy.stats import chisquare

您可以通過將它們作為 group1 和 group2 傳遞到 chisquare 模塊中來直接測試分布。 X 是 group1。 Y 是 group2。 這里 group1 代表 freq_observed,group2 代表 freq_expected。 將自由度設置為可選參數 ddof 或者您可以讓模型從元素數量中選擇它

import scipy.stats as stat
stat.chisquare(np.array(group1), np.array(group2))

是使用它的方法。 現在,您可以針對這兩列分別使用擬合數據進行測試,因為 group1 是擬合數據,group2 是獨立的 X、Y。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM