-
-
Save amankharwal/241bcaacb59899e8044ad3d0128d8d8c 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
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