IniziaInizia gratis

Clustering 2D points

From the scatter plot of the previous exercise, you saw that the points seem to separate into 3 clusters. You'll now create a KMeans model to find 3 clusters, and fit it to the data points from the previous exercise. After the model has been fit, you'll obtain the cluster labels for some new points using the .predict() method.

You are given the array points from the previous exercise, and also an array new_points.

Questo esercizio fa parte del corso

Unsupervised Learning in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Import KMeans from sklearn.cluster.
  • Using KMeans(), create a KMeans instance called model to find 3 clusters. To specify the number of clusters, use the n_clusters keyword argument.
  • Use the .fit() method of model to fit the model to the array of points points.
  • Use the .predict() method of model to predict the cluster labels of new_points, assigning the result to labels.
  • Hit submit to see the cluster labels of new_points.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Import KMeans
____

# Create a KMeans instance with 3 clusters: model
model = ____

# Fit model to points
____

# Determine the cluster labels of new_points: labels
labels = ____

# Print cluster labels of new_points
print(labels)
Modifica ed esegui il codice