5. Analyzing the Online Shopper's Purchasing Intention
Activity 5.01: Performing K-means Clustering for Administrative Duration versus Bounce Rate and Administrative Duration versus Exit Rate
- Select the
Administrative Duration
andBounce Rate
columns. Assign the column to a variable calledx
:x = df.iloc[:, [1, 6]].values x.shape
- Initialize the k-means algorithm:
wcss = [] for i in range(1, 11): km = KMeans(n_clusters = i, init = 'k-means++', \ max_iter = 300, n_init = 10, random_state = 0, \ algorithm = 'elkan', tol = 0.001)
- For the different values of
K
, compute theKmeans
inertia and store it in a variable calledwcss
:km.fit(x) labels = km.labels_ wcss.append...