Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created February 8, 2021 09:48
Show Gist options
  • Save amankharwal/241bcaacb59899e8044ad3d0128d8d8c to your computer and use it in GitHub Desktop.
Save amankharwal/241bcaacb59899e8044ad3d0128d8d8c to your computer and use it in GitHub Desktop.
scaler=StandardScaler()
dataset_temp=data[['Income','Seniority','Spending']]
X_std=scaler.fit_transform(dataset_temp)
X = normalize(X_std,norm='l2')
gmm=GaussianMixture(n_components=4, covariance_type='spherical',max_iter=2000, random_state=5).fit(X)
labels = gmm.predict(X)
dataset_temp['Cluster'] = labels
dataset_temp=dataset_temp.replace({0:'Stars',1:'Need attention',2:'High potential',3:'Leaky bucket'})
data = data.merge(dataset_temp.Cluster, left_index=True, right_index=True)
pd.options.display.float_format = "{:.0f}".format
summary=data[['Income','Spending','Seniority','Cluster']]
summary.set_index("Cluster", inplace = True)
summary=summary.groupby('Cluster').describe().transpose()
summary.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment