ฮิสโตแกรม

Python เบื้องต้นสำหรับการเงิน

Adina Howe

Professor

ทำไมต้องใช้ฮิสโตแกรมในการวิเคราะห์ทางการเงิน?

ฮิสโตแกรม

Python เบื้องต้นสำหรับการเงิน

ฮิสโตแกรมกับข้อมูล

  • ข้อมูลมีความเบ้หรือไม่?
  • ข้อมูลรวมตัวอยู่รอบค่าเฉลี่ยหรือไม่?
  • มีจุดข้อมูลที่ผิดปกติ (outlier) หรือไม่?
Python เบื้องต้นสำหรับการเงิน

ฮิสโตแกรมกับ matplotlib.pyplot

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=3)
plt.show()

hist1

Python เบื้องต้นสำหรับการเงิน

การเปลี่ยนจำนวน bin

import matplotlib.pyplot as plt
plt.hist(prices, bins=6)
plt.show()

hist2

Python เบื้องต้นสำหรับการเงิน

การนอร์มัลไลซ์ข้อมูลในฮิสโตแกรม

import matplotlib.pyplot as plt
plt.hist(prices, bins=6, density=True)
plt.show()

normed

Python เบื้องต้นสำหรับการเงิน

การซ้อนฮิสโตแกรมบนกราฟเดียวกัน

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True)
plt.hist(x=prices_new, bins=6, density=True)
plt.show()
Python เบื้องต้นสำหรับการเงิน

ผลลัพธ์ของฮิสโตแกรม

two_hist_normed

Python เบื้องต้นสำหรับการเงิน

Alpha: การปรับความโปร่งใสของฮิสโตแกรม

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True, alpha=0.5)
plt.hist(x=prices_new, bins=6, density=True, alpha=0.5)
plt.show()
Python เบื้องต้นสำหรับการเงิน

ผลลัพธ์ของฮิสโตแกรม

two-hist-transparent

Python เบื้องต้นสำหรับการเงิน

การเพิ่มคำอธิบายสัญลักษณ์

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True, alpha=0.5, label="Prices 1")
plt.hist(x=prices_new, bins=6, density=True, alpha=0.5, label="Prices New")
plt.legend()
plt.show()
Python เบื้องต้นสำหรับการเงิน

ผลลัพธ์ของฮิสโตแกรม

pretty hist

Python เบื้องต้นสำหรับการเงิน

มาฝึกกันเถอะ!

Python เบื้องต้นสำหรับการเงิน

Preparing Video For Download...