MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / cost

Function cost

unsupervised_class/kmeans.py:20–31  ·  view source on GitHub ↗
(X, R, M)

Source from the content-addressed store, hash-verified

18
19
20def cost(X, R, M):
21 cost = 0
22 for k in range(len(M)):
23 # method 1
24 # for n in range(len(X)):
25 # cost += R[n,k]*d(M[k], X[n])
26
27 # method 2
28 diff = X - M[k]
29 sq_distances = (diff * diff).sum(axis=1)
30 cost += (R[:,k] * sq_distances).sum()
31 return cost
32
33
34def plot_k_means(X, K, max_iter=20, beta=3.0, show_plots=False):

Callers 2

mainFunction · 0.90
plot_k_meansFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected