File tree 1 file changed +15
-18
lines changed
1 file changed +15
-18
lines changed Original file line number Diff line number Diff line change 6
6
import math
7
7
import statistics
8
8
9
+ # 離散均勻分配( Discrete Uniform Distribution )
10
+ # 伯努利分配( Bernoulli Distribution )
11
+ # 二項分配(Binomial Distribution)
12
+ # 今天我們透過作業中的問題,回想今天的內容吧!
13
+ # 丟一個銅板,丟了100次,出現正面 50 次的機率有多大。
14
+
9
15
'''
10
- # 離散均勻分配 (Discrete Uniform Distribution)
11
- # 前提:其中有限個數值擁有相同的機率。
16
+ 你的答案
12
17
'''
13
- # 1.定義離散均勻分配的基本資訊
18
+ # 這是 bermoulli分配
19
+ p = 0.5 # 假設是公平硬幣
20
+ n = 100 # 重複實驗 100次,
21
+ r = 50 # 計算出現50次正面
22
+
14
23
15
- low = 1
16
- high = 7
17
- r = np .arange (low ,high )
18
- # 2.計算離散均勻分配的概率質量分佈 (probability mass function)
24
+ # 2.計算二項分佈的概率質量分佈 (probability mass function)
19
25
# 之所以稱為質量,是因為離散的點
20
- # 產生 x 軸的點
21
- #r = np.arange(stats.randint.ppf(0.01, low, high),
22
- # stats.randint.ppf(0.99, low, high),1)
23
- print (r )
24
26
# P(X=x) --> 是機率
25
- probs = stats .randint .pmf (r ,low ,high )
26
- print (probs )
27
- plt .bar (r , probs )
28
- plt .ylabel ('P(X=x)' )
29
- plt .xlabel ('x' )
30
- plt .title ('pmf of DU(1,6)' )
31
- plt .show ()
27
+ probs = stats .binom .pmf (r , n , p )
28
+ print (probs )
You can’t perform that action at this time.
0 commit comments