描述統計與推論統計

使用 Python 分析問卷資料

EbunOluwa Andrew

Data Scientist

描述統計

  • 描述問卷資料的基本量度
  • 例如:mean、median、mode、range、standard deviation 等
  • .describe()

Lukas 攝:圖表特寫

1 Photo by Lukas
使用 Python 分析問卷資料

.describe() 函式

data.describe()
|      | year     | satisfaction_rating
|------|----------|--------------------
| count|       42 |                  42
| mean | 2012.381 |            7192.857
| std  |    4.196 |             945.178
| min  |     2006 |                5500
| 25%  |     2009 |                6325
| 50%  |   2012.5 |                7400
| 75%  |     2016 |                8000
| max  |     2019 |                8600
data.describe(include = np.object)
|        | category    |
|--------|-------------|
| count  | 42          |
| unique | 3           |
| top    | Residential |
| freq   | 14          |
使用 Python 分析問卷資料

解讀 .describe()

  • 離群值 = 最大值 > 平均與中位數
  • 不合理值 = 值不合邏輯時
|       | year     | satisfaction_rating |
|-------|----------|---------------------|
| count |       42 |                  42 |
| mean  | 2012.381 |            7192.857 |
| std   |    4.196 |             945.178 |
| min   |     2006 |                5500 |
| 25%   |     2009 |                6325 |
| 50%   |   2012.5 |                7400 |
| 75%   |     2016 |                8000 |
| max   |     2019 |                8600 |
使用 Python 分析問卷資料

解讀 .describe()

  • Top = 眾數 = 出現次數最多的類別
  • Freq = 最多類別出現的次數
|        | category    |
|--------|-------------|
| count  | 42          |
| unique | 3           |
| top    | Residential |
| freq   | 14          |
使用 Python 分析問卷資料

對 electric_satisfaction 使用 .describe()

import pandas as pd

electric_satisfaction = pd.read_csv("austin-energy-customer-satisfaction.csv")
使用 Python 分析問卷資料

對 electric_satisfaction 使用 .describe()

electric_satisfaction.describe()
|      | year     | satisfaction_rating
|------|----------|--------------------
| count|       42 |                  42
| mean | 2012.381 |            7192.857
| std  |    4.196 |             945.178
| min  |     2006 |                5500
| 25%  |     2009 |                6325
| 50%  |   2012.5 |                7400
| 75%  |     2016 |                8000
| max  |     2019 |                8600
  • satisfaction_rating 有離群值
  • 第 50 百分位 = 中位數
使用 Python 分析問卷資料

對 electric_satisfaction 使用 .describe()

|        | category    |
|--------|-------------|
| count  | 42          |
| unique | 3           |
| top    | Residential |
| freq   | 14          |
  • 眾數 = Residential 受訪者
使用 Python 分析問卷資料

推論統計

  • 判斷資料能否推及更大母體
  • 樣本小於母體 → 抽樣誤差
  • 估計母體參數
    • 信賴區間
      • norm.interval() 函式

Andrea Piacquadio 攝(Pexels):手持燈泡的女子

1 Photo by Andrea Piacquadio on Pexels
使用 Python 分析問卷資料

norm.interval() 函式

  • 適用大型資料集
  • 假設樣本平均的抽樣分配為常態
import scipy.stats
scipy.stats.norm.interval(alpha, loc, scale)
  • alpha = 信賴水準
  • loc = 樣本平均
  • scale= 樣本標準誤
使用 Python 分析問卷資料

解讀 electric_satisfaction 的 norm.interval()

electric_satisfaction = pd.read_csv(
  "austin-energy-customer-satisfaction.csv")

conf_interval = st.norm.interval(
  alpha = 0.99,
  loc = np.mean(electric_satisfaction.satisfaction),
  scale=st.sem(electric_satisfaction.satisfaction))

print(conf_interval)
(6817.187361704269, 7568.526924010017)
使用 Python 分析問卷資料

一起來練習吧!

使用 Python 分析問卷資料

Preparing Video For Download...