This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.cluster import KMeans | |
errors = [] | |
for i in range(1, 11): | |
kmeans = KMeans(n_clusters=i) | |
kmeans.fit(df1) | |
errors.append(kmeans.inertia_) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Scatter Plot | |
sns.scatterplot(df1['Annual Income (k$)'], df1['Spending Score (1-100)']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df1 = df[['Annual Income (k$)', 'Spending Score (1-100)']] | |
df1.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
corr = df.corr() | |
sns.heatmap(corr, annot=True, cmap="YlGnBu_r") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Females, Males = df['Gender'].value_counts() | |
print(f'There are {Females} Female customers and {Males} Male customers in the dataset') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nRows, nColumns = df.shape | |
print(f"There are {nRows} rows and {nColumns} columns in our dataset") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loading in the Data | |
df = pd.read_csv('Mall_Customers.csv') | |
df.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing libraries | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from sklearn.preprocessing import StandardScaler | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = plt.figure(figsize=(20,15)) | |
ax = fig.add_subplot(111, projection='3d') | |
ax.scatter(df2['Age'][df2['Label']==0], df2['Annual Income (k$)'][df2['Label']==0], | |
df2['Spending Score (1-100)'][df2['Label']==0], c='green', s=50) | |
ax.scatter(df2['Age'][df2['Label']==1], df2['Annual Income (k$)'][df2['Label']==1], | |
df2['Spending Score (1-100)'][df2['Label']==1], c='blue', s=50) | |
ax.scatter(df2['Age'][df2['Label']==2], df2['Annual Income (k$)'][df2['Label']==2], | |
df2['Spending Score (1-100)'][df2['Label']==2], c='black', s=50) | |
ax.scatter(df2['Age'][df2['Label']==3], df2['Annual Income (k$)'][df2['Label']==3], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df2_clusters = df2['Label'].value_counts() | |
df2_clusters |