Skip to content

fixed duplicate centroids in kmeans initialization #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed duplicate centroids in kmeans initialization
  • Loading branch information
karthick1729 committed Dec 22, 2024
commit 9e50a49ee2d3da6c209954a19a26e418dc15da0f
8 changes: 2 additions & 6 deletions ML/algorithms/kmeans/kmeansclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ def __init__(self, X, num_clusters):
self.num_features = X.shape[1]

def initialize_random_centroids(self, X):
centroids = np.zeros((self.K, self.num_features))

for k in range(self.K):
centroid = X[np.random.choice(range(self.num_examples))]
centroids[k] = centroid

centroids = X[np.random.choice(range(self.num_examples), size=self.K, replace=False)]

return centroids

def create_clusters(self, X, centroids):
Expand Down