Skip to content

Instantly share code, notes, and snippets.

@Magesh-Sundaravel
Created January 12, 2023 23:38
Show Gist options
  • Save Magesh-Sundaravel/691d48457ad872dd6d75d9f7ab6f9038 to your computer and use it in GitHub Desktop.
Save Magesh-Sundaravel/691d48457ad872dd6d75d9f7ab6f9038 to your computer and use it in GitHub Desktop.
KmeansProject
# importing
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df=pd.read_csv("C:\\Users\MageshMacpeth\Desktop\College_Data.csv",index_col = 0)
print(df)
sns.lmplot(data=df,x='Room.Board',y='Grad.Rate',hue='Private',fit_reg=False,palette='coolwarm')
plt.show()
sns.lmplot(data=df,x='Outstate',y='F.Undergrad',hue='Private',fit_reg=False)
plt.show()
o = sns.FacetGrid(df,hue='Private',palette='coolwarm')
o = o.map(plt.hist,'Outstate',bins=20,alpha=0.7)
plt.show()
g = sns.FacetGrid(df,hue='Private',palette='coolwarm')
g = g.map(plt.hist,'Grad.Rate',bins=20,alpha=0.7)
plt.show()
psg=df[df["Grad.Rate"]>100]
df['Grad.Rate']['Cazenovia College']=100
g = sns.FacetGrid(df,hue='Private',palette='coolwarm')
g = g.map(plt.hist,'Grad.Rate',bins=20,alpha=0.7)
plt.show()
from sklearn.cluster import KMeans
kmeans=KMeans(n_clusters=2)
kmeans.fit(df.drop('Private',axis=1))
print(kmeans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment