เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ตรวจสอบผลการจัดกลุ่ม

ตอนนี้มาตรวจสอบผลการจัดกลุ่มที่ทำไว้ในแบบฝึกหัดก่อนหน้ากัน

โค้ดจากแบบฝึกหัดก่อนหน้าได้รันไปแล้ว ดังนั้น new_points จึงเป็น array ของจุดข้อมูล และ labels คือ array ของป้ายกำกับคลัสเตอร์ของแต่ละจุด

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Unsupervised Learning ใน Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • นำเข้า matplotlib.pyplot โดยใช้ชื่อแทนว่า plt
  • กำหนดให้ xs เท่ากับคอลัมน์ 0 ของ new_points และ ys เท่ากับคอลัมน์ 1 ของ new_points
  • สร้าง scatter plot จาก xs และ ys โดยระบุ keyword argument c=labels เพื่อกำหนดสีของจุดตามป้ายกำกับคลัสเตอร์ และระบุ alpha=0.5 ด้วย
  • คำนวณพิกัดของจุด centroid โดยใช้ attribute .cluster_centers_ ของ model
  • กำหนดให้ centroids_x เท่ากับคอลัมน์ 0 ของ centroids และ centroids_y เท่ากับคอลัมน์ 1 ของ centroids
  • สร้าง scatter plot จาก centroids_x และ centroids_y โดยใช้ 'D' (รูปทรงเพชร) เป็น marker ผ่านพารามิเตอร์ marker และกำหนดขนาด marker เป็น 50 โดยใช้ s=50

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Import pyplot
____

# Assign the columns of new_points: xs and ys
xs = ____
ys = ____

# Make a scatter plot of xs and ys, using labels to define the colors
____

# Assign the cluster centers: centroids
centroids = ____

# Assign the columns of centroids: centroids_x, centroids_y
centroids_x = centroids[:,0]
centroids_y = centroids[:,1]

# Make a scatter plot of centroids_x and centroids_y
____
plt.show()
แก้ไขและรันโค้ด