相關性

使用 Python 分析問卷資料

EbunOluwa Andrew

Data Scientist

問卷分析中的相關性

  • 變數數值的相互依存
    • 一個變數改變,另一個也會改變
  • 衡量兩個問項的線性關係
  • 相關性不等於因果
    • 可能存在第三個影響變數
    • 無法斷定哪個變數造成另一個改變

相關性不等於因果。文字設計

使用 Python 分析問卷資料

相關的強度與方向

  • 相關係數 → 「r」
  • -1.0 到 1.0
    • -1 或 1=完全關係
    • 0=無關係
    • 小於 0=負相關
    • 大於 0=正相關
  • 樣本少時,需要更強的相關才具統計顯著性

拼圖間的相關性

使用 Python 分析問卷資料

.corr() 函式

  • .corr()
  • _first column_.corr(_second column_)

相關類型

使用 Python 分析問卷資料

.corr() 範例:healthy_city

| City       | Rank | Life expectancy_years | Happiness levels |
|------------|------|-----------------------|------------------|
| Amsterdam  |    1 |                  81.2 |             7.44 |
| Sydney     |    2 |                  82.1 |             7.22 |
| Vienna     |    3 |                    81 |             7.29 |
| Stockholm  |    4 |                  81.8 |             7.35 |
| Copenhagen |    5 |                  79.8 |             7.64 |
| Helsinki   |    6 |                  80.4 |              7.8 |
| Fukuoka    |    7 |                  83.2 |             5.87 |
| Berlin     |    8 |                  80.6 |             7.07 |
| Barcelona  |    9 |                  82.2 |              6.4 |
使用 Python 分析問卷資料

.corr() 範例:healthy_city

import matplotlib.pyplot as plt
plt.scatter(healthy_city['Life expectancy_years'],
            healthy_city['Happiness levels'])

happy_survey 散佈圖

使用 Python 分析問卷資料

.corr() 範例:healthy_city

happy_survey['Happiness levels'].corr(
  happy_survey['Life expectancy_years'])
0.7245870841569987
使用 Python 分析問卷資料

一起來練習吧!

使用 Python 分析問卷資料

Preparing Video For Download...