text_plain_output_1.png
from sklearn.cluster import KMeans

from sklearn.cluster import KMeans

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_csv('/kaggle/input/ulabox-orders-with-categories-partials-2017/ulabox_orders_with_categories_partials_2017.csv')

df.shape

df.columns

df.isnull().sum()

df.columns = ['customer', 'order', 'total_items', 'discount_percent', 'weekday', 'hour', 'food_percent', 'fresh_percent', 'drinks_percent', 'home_percent', 'beauty_percent', 'health_percent', 'baby_percent', 'pets_percent']

df.discount_percent.mean()

df[df['total_items'] == df.total_items.max()]

len(df) - len(df.drop_duplicates())

df_customer = df.drop_duplicates('customer', keep='first')

df_customer.drop(['customer', 'order'], inplace=True, axis=1)

scaler = StandardScaler()
scaled_features = scaler.fit_transform(df_customer)

import matplotlib.pyplot as plt
df_corr = df_customer.corr()
fig, ax = plt.subplots(figsize=(16, 16))
ax = sns.heatmap(df_corr, annot=True)

dff = scaled_features
from sklearn.cluster import KMeans
wcss = []
for k in range(2, 11):
    kmeanModel = KMeans(n_clusters=k, init='k-means++')
    kmeanModel.fit(dff)
    wcss.append(kmeanModel.inertia_)
plt.figure(figsize=(16, 8))
plt.plot(range(2, 11), wcss, 'bx-')
plt.xlabel('k')
plt.ylabel('Distortion')
plt.title('The Elbow Method showing the optimal k')
plt.show()