{"published":"2026-04-16 23:43:23","type":"rich","description":"import numpy as np def init_centroid(X, k): # X = (\u30c7\u30fc\u30bf\u4ef6\u6570\u3001\u7279\u5fb4\u91cf\u306e\u6b21\u5143\u6570) n_data = X.shape[0] idx = np.random.choice(n_data) #\u30c7\u30fc\u30bf\u4ef6\u6570\u304b\u3089\u30e9\u30f3\u30c0\u30e0\u306b1\u4ef6\u9078\u629e\u3057\u3066\u30bb\u30f3\u30c8\u30ed\u30a4\u30c91\u500b\u76ee\u306e\u5ea7\u6a19\u3068\u3059\u308b centroids = X[idx].reshape(1, -1) print(\"1 centroids.shape=\",centroids.shape) for _ in range(k - 1): # distances = (\u30c7\u30fc\u30bf\u4ef6\u6570\u3001\u30bb\u30f3\u30c8\u30ed\u30a4\u30c9\u6570)\u3001\u5404\u30c7\u30fc\u30bf\u3001\u5404\u30bb\u30f3\u30c8\u30ed\u30a4\u30c9\u3054\u3068\u306e\u30c7\u30fc\u2026","height":"190","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fhtn20190109.hatenablog.com%2Fentry%2F2026%2F04%2F16%2F234323\" 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>","author_name":"HTN20190109","version":"1.0","categories":["DL"],"image_url":null,"provider_name":"Hatena Blog","title":"k-means++","url":"https://htn20190109.hatenablog.com/entry/2026/04/16/234323","width":"100%","blog_url":"https://htn20190109.hatenablog.com/","author_url":"https://blog.hatena.ne.jp/HTN20190109/","blog_title":"HTN20190109\u306e\u65e5\u8a18","provider_url":"https://hatena.blog"}