...
/K-Means Clustering Implementation Steps: 4 to 6
K-Means Clustering Implementation Steps: 4 to 6
Continue to become familiar with the implementation steps (4-6) of k-means clustering.
We'll cover the following...
4) Predict
By using the predict function under a new variable (model_predict
), you can execute the model and generate the centroid coordinates using cluster_centers_
.
Press + to interact
main.py
advertising.csv
#4) Predictmodel_predict = model.predict(X)centroids = model.cluster_centers_print(model.cluster_centers_)
5) Visualize the output
It’s now time to plot the clusters on a scatterplot using two sets of elements. The first is the four color-coded clusters produced using the k-means model, which are stored under the variable named model_predict
. The second is the cluster centroids, which are stored under the variable named centroids.
The centroids are black with a marker size (s
) of 200 and an alpha of 1. Alpha can take any float number between 0 and 1.0, with 0 equal to ...