ใช้ Python สำหรับสถิติเชิงวิเคราะห์และการวาดกราฟด้วย pandas, matplotlib, seaborn, numpy
โหลดข้อมูล (Seeds Dataset)
import pandas as pd
import warnings
warnings.filterwarnings("ignore")
# สมมติไฟล์ seeds.csv อยู่ใน path
# df = pd.read_csv('seeds.csv')
# print(df.head())
1. Histogram (แผนภาพแท่ง)
แสดงการกระจายของ Kernel Length
import matplotlib.pyplot as plt
import numpy as np
from numpy import genfromtxt
# data = genfromtxt('seeds.csv', delimiter=',')
# kernel_length = data[:, 3]
# bins = int(np.sqrt(len(kernel_length)))
# plt.hist(kernel_length, bins=bins, color='#FF4040')
# plt.xlabel('Kernel Length')
# plt.ylabel('Frequency')
# plt.show()
2. ECDF (Empirical CDF)
แสดงสัดสะสมของ Kernel Groove
def ecdf(data):
x = np.sort(data)
y = np.arange(1, len(x)+1) / len(x)
return x, y
# x, y = ecdf(kernel_groove)
# plt.plot(x, y, marker='.', linestyle='none')
# plt.xlabel('Kernel Groove')
# plt.ylabel('ECDF')
# plt.show()
3. Beeswarm Plot
แสดงการกระจายของ Asymmetry Coeff แยกตาม Type
import seaborn as sns
# sns.swarmplot(x='Type', y='Asymmetry.Coeff', data=df, color='#458B00')
# plt.xlabel('Type')
# plt.ylabel('Asymmetry Coeff')
# plt.show()
กราฟอื่นๆ ที่น่าสนใจ
- Box plot: แสดง quartiles และ outliers
- Violin plot: รวม box plot + density
- Pair plot: scatter matrix ทุกคู่คอลัมน์
- Heatmap: correlation matrix
สรุป
Python มีเครื่องมือสถิติและการวาดกราฟครบครัน เหมาะสำหรับ EDA (Exploratory Data Analysis)