Elbow Method บนกลุ่มข้อมูลที่แยกชัดเจน
ลองใช้ชุดข้อมูล comic con เพื่อดูว่า elbow plot มีลักษณะอย่างไรเมื่อนำไปใช้กับชุดข้อมูลที่มีกลุ่มแยกชัดเจน อาจลองแสดงจุดข้อมูลก่อนเริ่มทำแบบฝึกหัดนี้
ข้อมูลถูกเก็บไว้ใน pandas DataFrame ชื่อ comic_con โดย x_scaled และ y_scaled คือชื่อคอลัมน์ของพิกัด X และ Y ที่ผ่านการ standardize แล้ว แทนตำแหน่งของผู้คน ณ ช่วงเวลาหนึ่ง
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์กลุ่มข้อมูลใน Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
distortions = []
num_clusters = range(1, 7)
# Create a list of distortions from the kmeans function
for i in ____:
cluster_centers, distortion = ____
distortions.append(distortion)
# Create a DataFrame with two lists - num_clusters, distortions
elbow_plot = pd.DataFrame({'num_clusters': ____, 'distortions': ____})
# Creat a line plot of num_clusters and distortions
sns.lineplot(x=____, y=____, data = ____)
plt.xticks(num_clusters)
plt.show()