{"id":1884,"date":"2019-07-14T16:44:42","date_gmt":"2019-07-14T07:44:42","guid":{"rendered":"https:\/\/tnishimaki.com\/?p=1884"},"modified":"2025-06-12T19:27:17","modified_gmt":"2025-06-12T10:27:17","slug":"python%e3%81%ab%e3%82%88%e3%82%8b%e9%9a%8e%e5%b1%a4%e5%9e%8b%e3%82%af%e3%83%a9%e3%82%b9%e3%82%bf%e3%83%aa%e3%83%b3%e3%82%b0","status":"publish","type":"post","link":"https:\/\/analysis-navi.com\/?p=1884","title":{"rendered":"Python\u306b\u3088\u308b\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306e\u5b9f\u884c\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3092Python\u3067\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>scipy\u306ecluster\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3048\u3070\u975e\u5e38\u306b\u7c21\u5358\u306b\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306e\u7406\u8ad6\u306b\u3064\u3044\u3066\u306f<a href=\"https:\/\/analysis-navi.com\/?p=1805\">\u3053\u3061\u3089<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/analysis-navi.com\/?p=1805\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f<\/h2>\n\n\n\n<p>\u4eca\u56de\u306f\u3001\u7406\u8ad6\u7de8\u3067\u7528\u3044\u305f\u3082\u306e\u3068\u540c\u69d8\u306e\u30c7\u30fc\u30bf\u3092\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u300cclustering.csv\u300d\u3068\u3044\u3046\u540d\u524d\u306b\u3057\u3066\u8aad\u307f\u8fbc\u307e\u305b\u3066\u307f\u307e\u3059\u3002<br><img decoding=\"async\" src=\"https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/cb2032c9dc9cdfda32a24d2a5e8a0208.png\" alt=\"\" width=\"259\" height=\"158\" class=\"alignnone size-full wp-image-1986\" srcset=\"https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/cb2032c9dc9cdfda32a24d2a5e8a0208.png 518w, https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/cb2032c9dc9cdfda32a24d2a5e8a0208-300x183.png 300w\" sizes=\"(max-width: 259px) 100vw, 259px\" \/><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd\ndf = pd.read_csv(\"clustering.csv\",index_col=0)<\/pre>\n\n\n\n<p>index_col=0\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001csv\u306e1\u5217\u76ee\u3092index\u3068\u3057\u3066\u8aad\u307f\u8fbc\u3093\u3067\u304f\u308c\u307e\u3059\u3002<br>\u3067\u306f\u3053\u306e\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u3001\u69d8\u3005\u306a\u624b\u6cd5\u3067\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306e\u5b9f\u884c<\/h2>\n\n\n\n<p>\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306b\u3082\u8272\u3005\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u7406\u8ad6\u7de8\u3067\u3001<strong><span style=\"background-color: #87cefa;\">\u300c\u56f0\u3063\u305f\u3089\u30a6\u30a9\u30fc\u30c9\u6cd5\u300d<\/span><\/strong>\u3068\u8ff0\u3079\u305f\u3068\u304a\u308a\u3001\u307e\u305a\u306f\u30a6\u30a9\u30fc\u30c9\u6cd5\u3092\u7528\u3044\u3066\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import matplotlib.pyplot as plt\nfrom scipy.cluster.hierarchy import linkage, dendrogram, fcluster\n\nlinkage_result = linkage(df, method='ward', metric='euclidean')\nplt.figure(num=None, figsize=(16, 9), dpi=200, facecolor='w', edgecolor='k')\ndendrogram(linkage_result, labels=df.index)\nplt.show()<\/pre>\n\n\n\n<p>\u3053\u308c\u3060\u3051\u3067\u3059\u3002\u975e\u5e38\u306b\u7c21\u5358\u3067\u3059\u306d\u3002<br>linkage\u95a2\u6570\u306e<strong><span style=\"background-color: #87cefa;\">\u5f15\u6570method\u3067\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306e\u624b\u6cd5\u3092\u9078\u629e<\/span><\/strong>\u3057\u307e\u3059\u3002<br><strong>\u300csingle\u300d<\/strong>\u304c\u6700\u5c0f\u7d50\u5408\u6cd5\u3001<strong>\u300ccomplete\u300d<\/strong>\u304c\u6700\u5927\u7d50\u5408\u6cd5\u3001<strong>\u300caverage\u300d<\/strong>\u304c\u7fa4\u5e73\u5747\u6cd5\u3001\u4eca\u56de\u306e\u3088\u3046\u306b<strong>\u300cward\u300d<\/strong>\u304c\u30a6\u30a9\u30fc\u30c9\u6cd5\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br>\u3053\u306e\u4ed6\u306b\u3082\u3001\u91cd\u307f\u4ed8\u304d\u5e73\u5747\u6cd5\u3068\u547c\u3070\u308c\u308b<strong>\u300cweighted\u300d<\/strong>\u3001\u91cd\u5fc3\u6cd5\u3068\u547c\u3070\u308c\u308b<strong>\u300ccentroid\u300d<\/strong>\u306e6\u3064\u306e\u624b\u6cd5\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001<strong><span style=\"background-color: #87cefa;\">\u5f15\u6570metric\u3067\u4f7f\u7528\u3059\u308b\u8ddd\u96e2\u306e\u7a2e\u985e\u3092\u9078\u629e<\/span><\/strong>\u3057\u307e\u3059\u3002<br>\u300c\u8ddd\u96e2\u300d\u306b\u306f\u5b9f\u306f\u5c71\u306e\u3088\u3046\u306b\u7a2e\u985e\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001<strong><span style=\"background-color: #87cefa;\">\u6211\u3005\u304c\u4e00\u822c\u7684\u306b\u300c\u8ddd\u96e2\u300d\u3068\u8a00\u3063\u3066\u3044\u308b\u3082\u306e\u306f\u30e6\u30fc\u30b0\u30ea\u30c3\u30c9\u8ddd\u96e2(eulidean)<\/span><\/strong>\u306a\u306e\u3067\u3001\u7279\u6bb5\u7406\u7531\u304c\u7121\u3051\u308c\u3070\u3053\u308c\u3092\u9078\u629e\u3057\u3066\u304a\u3051\u3070\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u6700\u5f8c\u306eplt.show()\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b0\u30e9\u30d5\u304c\u53ef\u8996\u5316\u3055\u308c\u3066\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br><img decoding=\"async\" src=\"https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/6fbdf8bbfc6e4099152bd91c14ae69a0-1024x567.png\" alt=\"\" width=\"1024\" height=\"567\" class=\"alignnone size-large wp-image-1987\" srcset=\"https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/6fbdf8bbfc6e4099152bd91c14ae69a0-1024x567.png 1024w, https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/6fbdf8bbfc6e4099152bd91c14ae69a0-658x364.png 658w, https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/6fbdf8bbfc6e4099152bd91c14ae69a0-300x166.png 300w, https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/6fbdf8bbfc6e4099152bd91c14ae69a0-768x425.png 768w, https:\/\/analysis-navi.com\/wp-content\/uploads\/2019\/07\/6fbdf8bbfc6e4099152bd91c14ae69a0.png 1482w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n\n\n\n<p>\u7406\u8ad6\u7de8\u3067\u8a08\u7b97\u3057\u305f\u6642\u3068\u540c\u69d8\u306e\u30b0\u30e9\u30d5\u304c\u5f97\u3089\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<br>(ABCDE\u306e\u4e26\u3073\u9806\u306f\u9055\u3044\u307e\u3059\u304c\u3002)<\/p>\n\n\n\n<p>\u540c\u3058\u3088\u3046\u306b\u3001method\u306b\u300csingle\u300d\u300ccomplete\u300d\u300caverage\u300d\u3092\u9078\u629e\u3057\u305f\u969b\u306b\u3082\u3001\u7406\u8ad6\u7de8\u3067\u8a08\u7b97\u3057\u305f\u6642\u3068\u540c\u69d8\u306e\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306f\u30c7\u30fc\u30bf\u3092\u30b0\u30eb\u30fc\u30d7\u5206\u3051\u3059\u308b\u969b\u306b\u975e\u5e38\u306b\u5354\u529b\u3068\u306a\u308b\u624b\u6cd5\u3067\u3059\u304c\u3001Excel\u3067\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3092\u884c\u3046\u306e\u306f\u3001\u76ee\u4e0b\u3001\u56f0\u96e3\u3067\u3059\u3002<br>\u3057\u304b\u3057Python\u3092\u4f7f\u3048\u3070<strong><span style=\"background-color: #87cefa;\">10\u884c\u8db3\u3089\u305a\u3067\u7c21\u5358\u306b\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u304c\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/span><\/strong><\/p>\n\n\n\n<p>\u662f\u975e\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3092\u6d3b\u7528\u3057\u3066\u3001\u30c7\u30fc\u30bf\u306b\u7720\u308b\u65b0\u305f\u306a\u4fa1\u5024\u3092\u898b\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p>\u975e\u968e\u5c64\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u306b\u6574\u7406\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/analysis-navi.com\/?p=2147\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3092Python\u3067\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002scipy\u306ecluster\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3048\u3070\u975e\u5e38\u306b\u7c21\u5358\u306b\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002 \u968e\u5c64\u578b\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306e\u7406\u8ad6\u306b\u3064\u3044\u3066\u306f\u3053\u3061\u3089\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002 \u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5049,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"swell_btn_cv_data":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[129],"tags":[101,134],"class_list":["post-1884","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-study","tag-ml","tag-python"],"_links":{"self":[{"href":"https:\/\/analysis-navi.com\/index.php?rest_route=\/wp\/v2\/posts\/1884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/analysis-navi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/analysis-navi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/analysis-navi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/analysis-navi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1884"}],"version-history":[{"count":9,"href":"https:\/\/analysis-navi.com\/index.php?rest_route=\/wp\/v2\/posts\/1884\/revisions"}],"predecessor-version":[{"id":5160,"href":"https:\/\/analysis-navi.com\/index.php?rest_route=\/wp\/v2\/posts\/1884\/revisions\/5160"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/analysis-navi.com\/index.php?rest_route=\/wp\/v2\/media\/5049"}],"wp:attachment":[{"href":"https:\/\/analysis-navi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/analysis-navi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/analysis-navi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}