def _labels_inertia(X, centers):
n_examples, n_features = X.shape<EOL>n_clusters, n_features = centers.shape<EOL>labels = np.zeros((n_examples,))<EOL>inertia = np.zeros((n_examples,))<EOL>for ee in range(n_examples):<EOL><INDENT>dists = np.zeros((n_clusters,))<EOL>for cc in range(n_clusters):<EOL><INDENT>dists[cc] = <NUM_LIT:1> - X[ee, :].dot(centers[cc, :].T)<EOL><DEDENT>labels[ee] = np.argmin(dists)<EOL>inertia[ee] = dists[int(labels[ee])]<EOL><DEDENT>return labels, np.sum(inertia)<EOL>
Compute labels and inertia with cosine distance.