Skip to content

Commit

Permalink
Add k-means code in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav Singh committed Oct 31, 2020
1 parent b9a3054 commit 4c5b2c3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Python/ML Algorithms/k-means.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sklearn.cluster import KMeans
import pandas as pd

#reading the csv file having fees and experience as two columns
df = pd.read_csv('file_name.csv', sep=',', header=None)

#checking the values read in a numpy array
print(df.values)

# making two cluster for k-means
kmeans = KMeans(n_clusters=2)

#passing the cluster values to the k-means
kmeans.fit(df.values)

#checking the centres of the two clusters formed
print(kmeans.cluster_centers_)

#checking the cluster that is formed
#here 1 signifies that the element is present in the cluster and 0 specifies it is not.
print(kmeans.labels_)

0 comments on commit 4c5b2c3

Please sign in to comment.