Created
March 12, 2023 07:57
-
-
Save liliya2022/63d389ec39c3f08a58f89f831713a26d 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
km = KMeans(n_clusters = 5) | |
y_predicted = km.fit_predict(salary_story[['Total Salary Paid', 'Home Price']]) | |
salary_story['Cluster'] = y_predicted |
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
plt.figure(figsize = (10,5)) | |
df1 = salary_story[salary_story.Cluster == 0] | |
df2 = salary_story[salary_story.Cluster == 1] | |
df3 = salary_story[salary_story.Cluster == 2] | |
df4 = salary_story[salary_story.Cluster == 3] | |
df5 = salary_story[salary_story.Cluster == 4] | |
plt.scatter(df1['Total Salary Paid'], df1['Home Price'], color = 'green') | |
plt.scatter(df2['Total Salary Paid'], df2['Home Price'], color = 'red') | |
plt.scatter(df3['Total Salary Paid'], df3['Home Price'], color = 'yellow') | |
plt.scatter(df4['Total Salary Paid'], df4['Home Price'], color='blue') | |
plt.scatter(df5['Total Salary Paid'], df5['Home Price'], color='black') | |
plt.scatter(km.cluster_centers_[:, 0], km.cluster_centers_[:, 1], color='purple', marker='*', label='centroid') | |
plt.xlabel('Total Salary Paid') | |
plt.ylabel('Home Price') | |
plt.legend() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment