Reputation: 3
My code is returning a type error when I try to implement a clustering algorithm. I have tried altering the inputs of that line to resolve the error but I am not sure why it is returning the list' object is not callable error.
def clustering(xs, K, steps=10):
(T, W) = xs.shape
representatives = np.zeros((K, W))
group_assignments = np.random.randint(0, K, T)
group_history = [group_assignments]
assign = []
assign_cluster = []
for iteration in range(0,steps):
for i in range(len(xs)):
distance = {}
for c in range(K):
distance[c] = compute_distance(xs[i],representatives[c])
assign = assign_cluster(distance,xs[c],representatives)
group_assignments[assign[0]] = compute_new_cluster(assign[1],representatives[assign[0]])
if iteration == (steps-1):
assign_cluster.append(assign)
return [assign_cluster, K]
Upvotes: 0
Views: 103
Reputation: 131
It seems that you haven't posted the snippet of code where the error actually occurred. But based on the error message, you might have created a list called kmeans_cluster
, which conflicts with your function name. That might be why it's trying to "call" your list, because even though you intend for it to be using the kmeans_cluster
function, it's actually using the kmeans_cluster
list (which can't be called).
Again, this is mostly speculation based on the error message, since you haven't posted the code preceding the error message. But inspect your code for conflicting variable and function names.
Upvotes: 1