March 2019
Beginner to intermediate
464 pages
10h 57m
English
In this section, we are going to discuss different ways to draw insights from the results of the previous clustering analysis. Let's first build a k-means clustering model with four clusters. You can use the following code:
kmeans = KMeans(n_clusters=4).fit( normalized_df[['TotalSales', 'OrderCount', 'AvgOrderValue']])four_cluster_df = normalized_df[['TotalSales', 'OrderCount', 'AvgOrderValue']].copy(deep=True)four_cluster_df['Cluster'] = kmeans.labels_
As you can see from this code, we are fitting a k-means clustering model with 4 clusters, based on three attributes: TotalSales, OrderCount, and AvgOrderValue. Then, we store the cluster label information into a DataFrame, four_cluster_df. This DataFrame is shown ...
Read now
Unlock full access