{"id":10074,"date":"2020-08-03T10:55:01","date_gmt":"2020-08-03T01:55:01","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=10074"},"modified":"2020-08-03T10:55:01","modified_gmt":"2020-08-03T01:55:01","slug":"k-means-%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98%ec%9d%84-%ec%9d%b4%ec%9a%a9%ed%95%9c-%ea%b5%b0%ec%a7%91%ed%99%94cluster","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=10074","title":{"rendered":"k-Means \uc54c\uace0\ub9ac\uc998\uc744 \uc774\uc6a9\ud55c \uad70\uc9d1\ud654(Cluster)"},"content":{"rendered":"<p>\ub2e4\uc74c\uacfc \uac19\uc740 \ub370\uc774\ud130\uac00 \uc874\uc7ac\ud55c\ub2e4\uace0 \ud569\uc2dc\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2020\/08\/cluster1.png\" alt=\"\" width=\"1110\" height=\"1127\" class=\"aligncenter size-full wp-image-10075\" \/><\/p>\n<p>\uc704\uc758 \ub370\uc774\ud130\ub294 \uc544\ub798\uc758 \ucf54\ub4dc\ub85c \uc0dd\uc131\ub41c \uac83\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport sklearn\r\nimport numpy as np\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\nfrom sklearn.cluster import KMeans\r\nfrom sklearn.datasets import make_blobs\r\n\r\nblob_centers = np.array(\r\n    [[ 0.5,  0.5 ],\r\n     [ 1.5,  0.5 ],\r\n     [ 0.5,  1.5],\r\n     [ 1.5,  1.5]])\r\nblob_std = np.array([0.4, 0.3, 0.1, 0.1])\r\n\r\nX, y = make_blobs(n_samples=2000, centers=blob_centers, cluster_std=blob_std, random_state=3224)\r\n\r\ndef plot_data(X, y):\r\n    plt.scatter(X[:, 0], X[:, 1], c=y, marker='.', s=10)\r\n\r\nplot_data(X, y)\r\nplt.show()\r\n<\/pre>\n<p>\uc704\uc758 \ub370\uc774\ud130\ub294 4\uac1c\ub85c \uad6c\ub8f9\uc9c0\uc744 \uc218 \uc788\ub2e4\ub294 \uac83\uc744 \ucf54\ub4dc\ub97c \ud1b5\ud574 \uc54c \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\uc81c \uc774 \ub370\uc774\ud130\ub97c k-Means\ub97c \uc774\uc6a9\ud558\uc5ec 4\uac1c\ub85c \uad70\uc9d1\ud654\ud558\ub294 \ucf54\ub4dc\ub294 \uc0b4\ud3b4\ubcf4\uba74 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nk = 4\r\nkmeans = KMeans(n_clusters=k)\r\ny_pred = kmeans.fit_predict(X)\r\n<\/pre>\n<p>\uc704\uc758 \ucf54\ub4dc\ub97c \ud1b5\ud574 kmeans \ubaa8\ub378\uc740 \uc0c8\ub85c\uc6b4 \uc0d8\ud50c \ub370\uc774\ud130\uc5d0 \ub300\ud574\uc11c 4\uac1c\uc758 \uadf8\ub8f9\uc911 \uc5b4\ub5a4 \uadf8\ub8f9\uc5d0 \ud3ec\ud568\ub418\ub294\uc9c0 \uc608\uce21\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\uc5d0 \ub300\ud55c \uc2dc\uac01\ud654 \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\ndef plot_decision_boundaries(clusterer, X, y, resolution=500):\r\n    mins = X.min(axis=0) - 0.1\r\n    maxs = X.max(axis=0) + 0.1\r\n    xx, yy = np.meshgrid(np.linspace(mins[0], maxs[0], resolution), np.linspace(mins[1], maxs[1], resolution))\r\n    Z = clusterer.predict(np.c_[xx.ravel(), yy.ravel()])\r\n    Z = Z.reshape(xx.shape)\r\n\r\n    plt.contourf(Z, extent=(mins[0], maxs[0], mins[1], maxs[1]), cmap=\"gist_stern\")\r\n    plt.contour(Z, extent=(mins[0], maxs[0], mins[1], maxs[1]), linewidths=1, colors='k')\r\n    plot_data(X, y)\r\n\r\nplot_decision_boundaries(kmeans, X, y)\r\nplt.show()\r\n<\/pre>\n<p>\uc704 \ucf54\ub4dc\uc758 \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2020\/08\/cluster2.png\" alt=\"\" width=\"1113\" height=\"1126\" class=\"aligncenter size-full wp-image-10076\" \/><\/p>\n<p>\uc2e4\uc81c k-means\ub97c \uc801\uc6a9\ud560 \uc2dc\uc5d0\ub294 \uad70\uc9d1\ud654\ud560 \uac1c\uc218\ub97c \uc54c \uc218 \uc5c6\ub294 \uacbd\uc6b0\uac00 \ub300\ubd80\ubd84\uc785\ub2c8\ub2e4. \uc704\uc758 \ucf54\ub4dc\uc5d0\uc11c\ub294 k \uac12\uc778\ub370\uc694. \uc774 \uac12\uc744 \ud6a8\uacfc\uc801\uc73c\ub85c \uacb0\uc815\ud558\uae30 \uc704\ud574\uc11c\ub294 \uc2e4\ub8e8\uc5e3 \ub2e4\uc774\uc5b4\uadf8\ub7a8(Silhouette Diagram)\uc744 \ud1b5\ud574 \ud6a8\uacfc\uc801\uc73c\ub85c \ud30c\uc545\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ub2e4\uc74c\uacfc \uac19\uc740 \ub370\uc774\ud130\uac00 \uc874\uc7ac\ud55c\ub2e4\uace0 \ud569\uc2dc\ub2e4. \uc704\uc758 \ub370\uc774\ud130\ub294 \uc544\ub798\uc758 \ucf54\ub4dc\ub85c \uc0dd\uc131\ub41c \uac83\uc785\ub2c8\ub2e4. import sklearn import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from sklearn.cluster import KMeans from sklearn.datasets import make_blobs blob_centers = np.array( [[ 0.5, 0.5 ], [ 1.5, 0.5 ], [ 0.5, 1.5], [ 1.5, 1.5]]) blob_std = np.array([0.4, 0.3, 0.1, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=10074\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;k-Means \uc54c\uace0\ub9ac\uc998\uc744 \uc774\uc6a9\ud55c \uad70\uc9d1\ud654(Cluster)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[132],"tags":[],"class_list":["post-10074","post","type-post","status-publish","format-standard","hentry","category-deep-machine-learning"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10074"}],"version-history":[{"count":3,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10074\/revisions"}],"predecessor-version":[{"id":10079,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10074\/revisions\/10079"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10074"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}