{"id":8180,"date":"2019-09-23T13:42:47","date_gmt":"2019-09-23T04:42:47","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=8180"},"modified":"2020-05-28T10:15:15","modified_gmt":"2020-05-28T01:15:15","slug":"scikit-learn%ec%9d%98-svm%ec%9d%84-%ed%86%b5%ed%95%9c-%eb%b6%84%eb%a5%98classification","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=8180","title":{"rendered":"scikit-learn\uc758 SVM\uc744 \ud1b5\ud55c \ubd84\ub958(Classification)"},"content":{"rendered":"<p>SVM(Support Vector Machine)\uc740 \ub370\uc774\ud130 \ubd84\uc11d \uc911 \ubd84\ub958\uc5d0 \uc774\uc6a9\ub418\uba70 \uc9c0\ub3c4\ud559\uc2b5 \ubc29\uc2dd\uc758 \ubaa8\ub378\uc785\ub2c8\ub2e4. SVM\uc5d0 \ub300\ud55c \uc88b\uc740 \uad6c\ud604\uccb4\ub294 \uc0ac\uc774\ud0b7-\ub7f0(scikit-learn)\uc778\ub370, \uc774\ub97c \uc774\uc6a9\ud574 SVM\uc5d0 \ub300\ud55c \ub0b4\uc6a9\uc744 \uc815\ub9ac\ud574 \ubd05\ub2c8\ub2e4.<\/p>\n<p>\uba3c\uc800 \ud559\uc2b5\uc744 \uc704\ud55c \uc785\ub825 \ub370\uc774\ud130\uac00 \ud544\uc694\ud55c\ub370, scikit-learn\uc740 \ub370\uc774\ud130 \ubd84\ub958\ub97c \ubaa9\uc801\uc73c\ub85c \ub370\uc774\ud130\ub97c \uc0dd\uc131\ud574 \uc8fc\ub294 make_blobs\ub77c\ub294 \ud568\uc218\ub97c \uc81c\uacf5\ud569\ub2c8\ub2e4. \uc774\ub97c \uc774\uc6a9\ud574 \uc544\ub798\ucc98\ub7fc 2\uc885\ub958\uc758 \ucd1d 40\uac1c\uc758 \uc0d8\ud50c \ub370\uc774\ud130\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom sklearn import svm\r\nfrom sklearn.datasets.samples_generator import make_blobs\r\n\r\nX, y = make_blobs(n_samples=40, centers=2, random_state=20)\r\n<\/pre>\n<p>\uc704\uc5d0\uc11c \uc0dd\uc131\ud55c \ub370\uc774\ud130 \uc0d8\ud50c\uc744 SVM\uc73c\ub85c \ud559\uc2b5\uc2dc\ud0a4\ub294 \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nclf = svm.SVC(kernel='linear')\r\nclf.fit(X, y)\r\n<\/pre>\n<p>SVM\uc740 \uc120\ud615 \ubd84\ub958\uc640 \ube44\uc120\ud615 \ubd84\ub958\ub97c \uc9c0\uc6d0\ud558\ub294\ub370, \uadf8 \uc911 \uc120\ud615 \ubaa8\ub378\uc744 \uc704\ud574 kernel\uc744 linear\ub85c \uc9c0\uc815\ud558\uc600\uc2b5\ub2c8\ub2e4. \ube44\uc120\ud615\uc5d0 \ub300\ud55c kernel\ub85c\ub294 rbf\uc640 poly \ub4f1\uc774 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ud559\uc2b5\ub41c SVM \ubaa8\ub378\uc744 \ud1b5\ud574 \ub370\uc774\ud130 (3,4)\ub97c \ubd84\ub958\ud558\ub294 \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nnewData = [[3,4]]\r\nprint(clf.predict(newData))\r\n<\/pre>\n<p>\ub2e4\uc74c\uc740 \uc2dc\uac01\ud654\uc785\ub2c8\ub2e4. \uc0d8\ud50c \ub370\uc774\ud130\uc640 \ucd08\ud3c9\uba74(Hyper-Plane), \uc9c0\uc9c0\ubca1\ud130(Support Vector)\ub97c \uadf8\ub798\ud504\uc5d0 \ud45c\uc2dc\ud558\ub294 \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n# \uc0d8\ud50c \ub370\uc774\ud130 \ud45c\ud604\r\nplt.scatter(X[:,0], X[:,1], c=y, s=30, cmap=plt.cm.Paired)\r\n\r\n# \ucd08\ud3c9\uba74(Hyper-Plane) \ud45c\ud604\r\nax = plt.gca()\r\n\r\nxlim = ax.get_xlim()\r\nylim = ax.get_ylim()\r\n\r\nxx = np.linspace(xlim[0], xlim[1], 30)\r\nyy = np.linspace(ylim[0], ylim[1], 30)\r\nYY, XX = np.meshgrid(yy, xx)\r\nxy = np.vstack([XX.ravel(), YY.ravel()]).T\r\nZ = clf.decision_function(xy).reshape(XX.shape)\r\n\r\nax.contour(XX, YY, Z, colors='k', levels=[-1,0,1], alpha=0.5, linestyles=['--', '-', '--'])\r\n\r\n# \uc9c0\uc9c0\ubca1\ud130(Support Vector) \ud45c\ud604\r\nax.scatter(clf.support_vectors_[:,0], clf.support_vectors_[:,1], s=60, facecolors='r')\r\n\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4. \ube68\uac04\uc0c9 \ud3ec\uc778\ud2b8\uac00 \uc9c0\uc9c0\ubca1\ud130\uc774\uace0, \uc9c4\ud55c \ud68c\uc0c9\uc120\uc774 \ucd08\uba85\ud3b8\uc785\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/09\/svm_linear.png\" alt=\"\" width=\"601\" class=\"aligncenter size-full wp-image-8181\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 \ube44\uc120\ud615 SVM\ub85c\uc368 kernel\uc774 rbf\uc778 \uacb0\uacfc \uadf8\ub798\ud504\uc785\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/09\/svm_rbf.png\" alt=\"\" width=\"613\" class=\"aligncenter size-full wp-image-8182\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SVM(Support Vector Machine)\uc740 \ub370\uc774\ud130 \ubd84\uc11d \uc911 \ubd84\ub958\uc5d0 \uc774\uc6a9\ub418\uba70 \uc9c0\ub3c4\ud559\uc2b5 \ubc29\uc2dd\uc758 \ubaa8\ub378\uc785\ub2c8\ub2e4. SVM\uc5d0 \ub300\ud55c \uc88b\uc740 \uad6c\ud604\uccb4\ub294 \uc0ac\uc774\ud0b7-\ub7f0(scikit-learn)\uc778\ub370, \uc774\ub97c \uc774\uc6a9\ud574 SVM\uc5d0 \ub300\ud55c \ub0b4\uc6a9\uc744 \uc815\ub9ac\ud574 \ubd05\ub2c8\ub2e4. \uba3c\uc800 \ud559\uc2b5\uc744 \uc704\ud55c \uc785\ub825 \ub370\uc774\ud130\uac00 \ud544\uc694\ud55c\ub370, scikit-learn\uc740 \ub370\uc774\ud130 \ubd84\ub958\ub97c \ubaa9\uc801\uc73c\ub85c \ub370\uc774\ud130\ub97c \uc0dd\uc131\ud574 \uc8fc\ub294 make_blobs\ub77c\ub294 \ud568\uc218\ub97c \uc81c\uacf5\ud569\ub2c8\ub2e4. \uc774\ub97c \uc774\uc6a9\ud574 \uc544\ub798\ucc98\ub7fc 2\uc885\ub958\uc758 \ucd1d 40\uac1c\uc758 \uc0d8\ud50c \ub370\uc774\ud130\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. import numpy as np import matplotlib.pyplot as &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=8180\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;scikit-learn\uc758 SVM\uc744 \ud1b5\ud55c \ubd84\ub958(Classification)&#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":[131,132],"tags":[],"class_list":["post-8180","post","type-post","status-publish","format-standard","hentry","category-python","category-deep-machine-learning"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8180","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=8180"}],"version-history":[{"count":5,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8180\/revisions"}],"predecessor-version":[{"id":9380,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8180\/revisions\/9380"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8180"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}