Skip to content
Snippets Groups Projects
Commit d9f19f47 authored by s183897's avatar s183897 :ice_skate:
Browse files

ADDED K-MEANS FUNCTION

parent fa46705f
No related branches found
No related tags found
No related merge requests found
import numpy as np
from sklearn.neighbors import NearestNeighbors
from sklearn.cluster import KMeans
def nn(X,y):
neigh = NearestNeighbors(n_neighbors=1)
......@@ -13,3 +14,20 @@ print(nn(np.array([
[6,1,3],
[8,-2,3],
[7,3,11]]), np.array([[8,-1,2]])))
#K-MEANS
def km(X):
kmeans = KMeans(n_clusters=2)
kmeans.fit(X)
point = kmeans.predict(X)
point = np.squeeze(np.asarray(point))
c = kmeans.cluster_centers_
print(c)
return point
print(km(np.array([
[1,6,2],
[6,1,3],
[8,-2,3],
[7,3,11]])))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment