{"width":"100%","provider_url":"https://hatena.blog","title":"k-means","author_name":"HTN20190109","height":"190","version":"1.0","type":"rich","url":"https://htn20190109.hatenablog.com/entry/2026/03/31/020026","categories":["DL"],"description":"import numpy as npimport matplotlib.pyplot as plt # ===== k-means\u672c\u4f53 =====def init_centroid(X, n_data, k): # X = (\u30c7\u30fc\u30bf\u4ef6\u6570\u3001\u7279\u5fb4\u91cf\u306e\u6b21\u5143\u6570) # n_data = \u30c7\u30fc\u30bf\u4ef6\u6570 # \u30c7\u30fc\u30bf\u304b\u3089\u30e9\u30f3\u30c0\u30e0\u306b\u30af\u30e9\u30b9\u30bf\u6570\u5206\u306e\u5ea7\u6a19\u3092\u53d6\u5f97\u3057\u3066\u30bb\u30f3\u30c8\u30ed\u30a4\u30c9\u306e\u521d\u671f\u5024\u3068\u3059\u308b idx = np.random.permutation(n_data)[:k] centroids = X[idx] return centroids def compute_distances(X, k, n_data, cen\u2026","author_url":"https://blog.hatena.ne.jp/HTN20190109/","provider_name":"Hatena Blog","published":"2026-03-31 02:00:26","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fhtn20190109.hatenablog.com%2Fentry%2F2026%2F03%2F31%2F020026\" title=\"k-means - HTN20190109\u306e\u65e5\u8a18\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","blog_title":"HTN20190109\u306e\u65e5\u8a18","blog_url":"https://htn20190109.hatenablog.com/","image_url":null}