-
-
Save amankharwal/eab7c7c61fd6049e5166ce763e41985f to your computer and use it in GitHub Desktop.
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
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
sns.set() | |
data = pd.read_csv("https://raw.githubusercontent.com/amankharwal/Website-data/master/customers.csv") | |
print(data.head()) | |
data["Income"] = data[["Annual Income (k$)"]] | |
data["Spending"] = data[["Spending Score (1-100)"]] | |
data = data[["Income", "Spending"]] | |
print(data.head()) | |
from sklearn.cluster import MeanShift | |
model = MeanShift(bandwidth=2) | |
model.fit(data) | |
pred = model.fit_predict(data) | |
plt.style.use('seaborn-whitegrid') | |
plt.figure(figsize=(12, 10)) | |
plt.scatter(data["Income"], data["Spending"], c=pred, cmap='rainbow', alpha=0.9) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment