BaşlayınÜcretsiz Başlayın

How many clusters of grain?

In the video, you learned how to choose a good number of clusters for a dataset using the k-means inertia graph. You are given an array samples containing the measurements (such as area, perimeter, length, and several others) of samples of grain. What's a good number of clusters in this case?

KMeans and PyPlot (plt) have already been imported for you.

This dataset was sourced from the UCI Machine Learning Repository.

Bu egzersiz

Unsupervised Learning in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • For each of the given values of k, perform the following steps:
  • Create a KMeans instance called model with k clusters.
  • Fit the model to the grain data samples.
  • Append the value of the inertia_ attribute of model to the list inertias.
  • The code to plot ks vs inertias has been written for you, so hit submit to see the plot!

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

ks = range(1, 6)
inertias = []

for k in ks:
    # Create a KMeans instance with k clusters: model
    ____
    
    # Fit model to samples
    ____
    
    # Append the inertia to the list of inertias
    ____
    
# Plot ks vs inertias
plt.plot(ks, inertias, '-o')
plt.xlabel('number of clusters, k')
plt.ylabel('inertia')
plt.xticks(ks)
plt.show()
Kodu Düzenle ve Çalıştır