Untitled

 avatar
unknown
plain_text
5 months ago
746 B
2
Indexable

SOURCE CODE:

import numpy as np
import pandas as pd
import statsmodels.api as sm
importmatplotlib.pyplot as plt
import seaborn as sns
sns.set()
fromsklearn.cluster import KMeans
data = pd.read_csv('C:\\Users\\aliet\\Downloads\\cluster.csv')
data
plt.scatter(data['Longitude'],data['Latitude'])
plt.xlim(-180,180)
plt.ylim(-90,90)
plt.show()
x = data.iloc[:,1:3] # 1t for rows and second for columns
x
kmeans = KMeans(3)
kmeans.fit(x)
identified_clusters = kmeans.fit_predict(x)
identified_clusters
data_with_clusters = data.copy()
data_with_clusters['Clusters'] = identified_clusters
plt.scatter(data_with_clusters['Longitude'],data_with_clusters['Latitude'],c=data_with_clusters['Clusters'],cmap='rainbow')
print(data_with_clusters)


Output:
Editor is loading...
Leave a Comment