object 'idx' not found error

I continue to get this error:
Error in findClosestCentroids(as.matrix(X), initial_centroids): object 'idk' not found
Traceback:

  1. findClosestCentroids(as.matrix(X), initial_centroids)
findClosestCentroids <- function(X, centroids){

# Set K
    K = nrow(centroids)

# You need to return the following variables correctly.
    idx = matrix(0, nrow(X), 1)

    for(i in 1:nrow(X)){
        idx[i]<- min(sum(((X[i,]) - centroids)*(X[i,]) - centroids))
    }
return(idx)

The problem is that you have defined a matrix called idx but then you reference an unexisting idk matrix.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.