借助chisquare()方法,可以使用此方法獲得chi-square分布。主要地,我們可以在假設檢驗中使用這種分布。

chi-square分配
用法:numpy.random.chisquare(df, size=None)
參數:
1)df-自由度數,必須大於0。
2)size-標量數組的輸出形狀。
返回:返回標量numpy數組。
範例1:
在此示例中,我們可以看到,通過使用chisquare()方法,我們可以獲取chi-square分布並使用此方法返回標量numpy數組。
Python3
# import chisquare
import numpy as np
import matplotlib.pyplot as plt
# Using chisquare() method
gfg = np.random.chisquare(3, 1000)
count, bins, ignored = plt.hist(gfg, 14, density = True)
plt.show()
輸出:
範例2:
Python3
# import chisquare
import numpy as np
import matplotlib.pyplot as plt
# Using chisquare() method
gfg = np.random.chisquare(5, 10000)
gfg1 = np.random.chisquare(gfg, 10000)
count, bins, ignored = plt.hist(gfg1, 30, density = True)
plt.show()
輸出:
相關用法
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 numpy.random.chisquare() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。