Skip to content

Instantly share code, notes, and snippets.

@karamanbk
Created May 3, 2019 20:23
Show Gist options
  • Save karamanbk/88777c517969372d2ca0e159e8417349 to your computer and use it in GitHub Desktop.
Save karamanbk/88777c517969372d2ca0e159e8417349 to your computer and use it in GitHub Desktop.
#apply clustering
kmeans = KMeans(n_clusters=4)
kmeans.fit(tx_user[['Revenue']])
tx_user['RevenueCluster'] = kmeans.predict(tx_user[['Revenue']])
#order the cluster numbers
tx_user = order_cluster('RevenueCluster', 'Revenue',tx_user,True)
#show details of the dataframe
tx_user.groupby('RevenueCluster')['Revenue'].describe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment