In the previous segment, you built the model after training the data set. Now let’s determine the model’s accuracy. In the next video, Ajay will explain the model evaluation process.
Note:
Please follow the notebook above since some of the library installations may not have been covered in the video.
As explained in the video above, the silhouette coefficient score indicates the accuracy of the K-Means model. To calculate the silhouette coefficient score of the model, you need to first define a clustering evaluator, as shown below.
Next, you need to calculate the score using the. evaluate() method, as shown below.
To print the score, you can use the following command:
After calculating the silhouette score, you can use another important metric to find the K-value: the elbow method. You calculate the cost function values for different K-values in the present model using the following block of code:
Now the above code calculates the cost function for k=[3,7,10]. Now to plot the elbow curve, the following code is used:
As you can see in the figure given below, K=7 is the optimal value for the number of clusters for this data set.
Report an error