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...