Skip to content

Commit fac2821

Browse files
committed
update homework
1 parent e2fd535 commit fac2821

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

D20_seaborn/homework.py

+25-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
import numpy as np
2-
import seaborn as sns
31
import matplotlib.pyplot as plt
4-
# 比較好的教學 https://zhuanlan.zhihu.com/p/27816821
5-
6-
# 作業目標(1):
7-
# 繪製模型殘差 圖型
8-
2+
import numpy as np
3+
import pandas as pd
4+
from scipy import stats
5+
import math
6+
import statistics
97

10-
#設定圖形樣式 - whitegrid
11-
# sns.set_style('whitegrid')
12-
sns.set(style='whitegrid')
138

14-
# 利用 NUMPY 去建立資料集
15-
rs = np.random.RandomState(7)
16-
x = rs.normal(2, 1, 75)
17-
y = 2 + 1.5 * x + rs.normal(0, 2, 75)
18-
# 畫圖
19-
sns.residplot(x=x, y=y, lowess=True, color="g")
9+
# 今天學到五種分配,包含,
10+
# 離散均勻分配( Discrete Uniform Distribution )
11+
# 伯努利分配( Bernoulli Distribution )
12+
# 二項分配(Binomial Distribution)
13+
# 負二項分配(Negative Binomial Distribution)
14+
# 超幾何分配(Hypergeometric Distribution)
15+
# 今天我們透過作業中的問題,回想今天的內容吧!
2016

21-
plt.show()
22-
# 作業目標(2):
23-
# 使用 distplot()使用簡單的規則來正確猜測預設情況下正確的數位,但嘗試更多或更少的 bin 可能會顯示資料中的其他特徵:
24-
# 有無kde對圖形分布的影響
25-
# bin: 指的是特徵值,
26-
sns.set(color_codes=True)
17+
# Q1: 大樂透的頭獎,你必須從49個挑選出 6 個號碼,
18+
# 且這六個號碼與頭獎的六個號碼一致,頭獎的機率是屬於哪一種分配?
19+
# library
2720

28-
# bin: 指的是特徵值,
29-
# kde: on/off
30-
sns.distplot(x=x, bins=15, kde=False, rug=True);
31-
plt.show()
32-
###
33-
sns.distplot(x=x, bins=15, kde=True, rug=True);
34-
plt.show()
21+
print('''Q1: 大樂透的頭獎,你必須從49個挑選出 6 個號碼,
22+
可以想像成,大樂透中有49個號碼,6個是屬於開獎抽出的數字那一群,43個是不屬於開獎抽出的數字那一群,
23+
那你挑的六組號碼,有多少個是落在開獎抽出的數字那一群?
24+
屬於 超幾何分配.
25+
''')
26+
# Q2: 運用範例的 python 程式碼,計算大樂透的中頭獎機率?
27+
probs = stats.hypergeom.pmf(6,49,6,6)
28+
print("中頭獎的機率為==",probs)
29+
#Q3: 你覺得電腦簽注的中獎機率,和人腦簽注相比,哪一個機率高?
30+
print('以機率的角度來看,兩者一樣高')

D29_ContStatics/homework.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
import pandas as pd
4+
from scipy import stats
5+
import math
6+
import statistics
7+
8+
9+
# 今天學到五種分配,包含,
10+
# 離散均勻分配( Discrete Uniform Distribution )
11+
# 伯努利分配( Bernoulli Distribution )
12+
# 二項分配(Binomial Distribution)
13+
# 負二項分配(Negative Binomial Distribution)
14+
# 超幾何分配(Hypergeometric Distribution)
15+
# 今天我們透過作業中的問題,回想今天的內容吧!
16+
17+
# Q1: 大樂透的頭獎,你必須從49個挑選出 6 個號碼,
18+
# 且這六個號碼與頭獎的六個號碼一致,頭獎的機率是屬於哪一種分配?
19+
# library
20+
21+
print('''Q1: 大樂透的頭獎,你必須從49個挑選出 6 個號碼,
22+
可以想像成,大樂透中有49個號碼,6個是屬於開獎抽出的數字那一群,43個是不屬於開獎抽出的數字那一群,
23+
那你挑的六組號碼,有多少個是落在開獎抽出的數字那一群?
24+
屬於 超幾何分配.
25+
''')
26+
# Q2: 運用範例的 python 程式碼,計算大樂透的中頭獎機率?
27+
probs = stats.hypergeom.pmf(6,49,6,6)
28+
print("中頭獎的機率為==",probs)
29+
#Q3: 你覺得電腦簽注的中獎機率,和人腦簽注相比,哪一個機率高?
30+
print('以機率的角度來看,兩者一樣高')

0 commit comments

Comments
 (0)