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

Function cost

unsupervised_class/books.py:87–98  ·  view source on GitHub ↗
(X, R, M)

Source from the content-addressed store, hash-verified

85 return diff.dot(diff)
86
87def cost(X, R, M):
88 cost = 0
89 for k in range(len(M)):
90 # method 1
91 # for n in range(len(X)):
92 # cost += R[n,k]*d(M[k], X[n])
93
94 # method 2
95 diff = X - M[k]
96 sq_distances = (diff * diff).sum(axis=1)
97 cost += (R[:,k] * sq_distances).sum()
98 return cost
99
100def plot_k_means(X, K, index_word_map, max_iter=20, beta=1.0, show_plots=True):
101 N, D = X.shape

Callers 1

plot_k_meansFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected