Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created May 5, 2021 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/8cf2699d7f2e611e243e23e443eae11d to your computer and use it in GitHub Desktop.
Save amankharwal/8cf2699d7f2e611e243e23e443eae11d to your computer and use it in GitHub Desktop.
colors = {0:"red", 1:"yellow", 2:"blue", 3:"green", 4:"pink"}
pca = PCA()
principal_components = pca.fit_transform(x)
x, y = principal_components[:,0], principal_components[:,1]
df = pd.DataFrame({"X": x, "Y": y, "Labels": labels})
groups = df.groupby(labels)
fig, ax = plt.subplots(figsize=(15, 10))
for i, j in groups:
ax.plot(j.X, j.Y, marker='o', linestyle='', ms=5, color=colors[i], mec='none')
ax.set_aspect('auto')
ax.tick_params(axis='x',which='both',bottom='off',top='off',labelbottom='off')
ax.tick_params(axis= 'y',which='both',left='off',top='off',labelleft='off')
ax.set_title("Credit Card Customer Segmentation")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment