Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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