การวิเคราะห์กลุ่มข้อมูลใน Python
Shaumik Daityari
Business Analyst
kmeans(obs, k_or_guess, iter, thresh, check_finite)
obs: ข้อมูลที่ผ่านการ standardize แล้วk_or_guess: จำนวน clusteriter: จำนวนรอบการวนซ้ำ (ค่าเริ่มต้น: 20)thres: ค่า threshold (ค่าเริ่มต้น: 1e-05)check_finite: ตรวจสอบว่าข้อมูลมีเฉพาะตัวเลขจำกัดหรือไม่ (ค่าเริ่มต้น: True)คืนค่าสองอย่าง: จุดศูนย์กลาง cluster และค่า distortion

vq(obs, code_book, check_finite=True)
obs: ข้อมูลที่ผ่านการ standardize แล้วcode_book: จุดศูนย์กลาง clustercheck_finite: ตรวจสอบว่าข้อมูลมีเฉพาะตัวเลขจำกัดหรือไม่ (ค่าเริ่มต้น: True)คืนค่าสองอย่าง: รายการ label ของ cluster และรายการค่า distortion
kmeans คืนค่า distortion เพียงค่าเดียวvq คืนค่าเป็นรายการของค่า distortion# Import kmeans and vq functions
from scipy.cluster.vq import kmeans, vq
# Generate cluster centers and labels
cluster_centers, _ = kmeans(df[['scaled_x', 'scaled_y']], 3)
df['cluster_labels'], _ = vq(df[['scaled_x', 'scaled_y']], cluster_centers)
# Plot clusters
sns.scatterplot(x='scaled_x', y='scaled_y', hue='cluster_labels', data=df)
plt.show()

การวิเคราะห์กลุ่มข้อมูลใน Python