{"id":53950,"date":"2025-08-12T19:59:50","date_gmt":"2025-08-12T11:59:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/53950.html"},"modified":"2025-08-12T19:59:50","modified_gmt":"2025-08-12T11:59:50","slug":"%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0-%e6%94%af%e6%8c%81%e5%90%91%e9%87%8f%e6%9c%ba%ef%bc%88svm%ef%bc%89%e5%ae%9e%e6%88%98%e6%a1%88%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/53950.html","title":{"rendered":"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b"},"content":{"rendered":"<p>SVM\u7684 \u6838\u51fd\u6570 \u548c \u8d85\u53c2\u6570 \u4ecb\u7ecd&#xff1a;<\/p>\n<p><span class=\"link-card-box\"><span class=\"link-title\">\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a&#xff08;SVM&#xff09;-CSDN\u535a\u5ba2<\/span><span class=\"link-link\"><img decoding=\"async\" class=\"link-link-icon\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812115945-689b2cb161289.png\" \/>https:\/\/blog.csdn.net\/2302_78022640\/article\/details\/150073569<\/span><\/span><\/p>\n<hr \/>\n<h2>\u652f\u6301\u5411\u91cf\u673a&#xff08;SVM&#xff09;\u5b9e\u6218\u6848\u4f8b&#xff1a;\u9e22\u5c3e\u82b1\u90e8\u5206\u6570\u636e \u4e8c\u5206\u7c7b\u4e0e\u51b3\u7b56\u8fb9\u754c\u53ef\u89c6\u5316<\/h2>\n<p>\u652f\u6301\u5411\u91cf\u673a&#xff08;Support Vector Machine&#xff0c;SVM&#xff09;\u662f\u4e00\u79cd\u5e38\u7528\u7684\u76d1\u7763\u5b66\u4e60\u5206\u7c7b\u7b97\u6cd5&#xff0c;\u6838\u5fc3\u601d\u60f3\u662f\u627e\u5230\u4e00\u4e2a\u80fd\u591f\u6700\u5927\u5316\u7c7b\u522b\u95f4\u9694\u7684\u8d85\u5e73\u9762&#xff0c;\u5b9e\u73b0\u6570\u636e\u7684\u5206\u7c7b\u3002\u672c\u6848\u4f8b\u5c06\u901a\u8fc7\u9e22\u5c3e\u82b1\u6570\u636e\u96c6&#xff08;Iris&#xff09;\u6784\u5efa\u4e00\u4e2a\u4e8c\u5206\u7c7b\u6a21\u578b&#xff0c;\u5e76\u7ed8\u5236\u51b3\u7b56\u8fb9\u754c\u548c\u652f\u6301\u5411\u91cf\u3002<\/p>\n<hr \/>\n<h3>1. \u6570\u636e\u51c6\u5907\u4e0e\u9009\u62e9\u7279\u5f81<\/h3>\n<p>from sklearn.datasets import load_iris<br \/>\nfrom sklearn.svm import SVC<br \/>\nimport numpy as np<br \/>\nimport matplotlib.pyplot as plt<br \/>\nplt.rcParams[&#034;font.family&#034;] &#061; [&#034;SimHei&#034;, &#034;WenQuanYi Micro Hei&#034;, &#034;Heiti TC&#034;]<\/p>\n<p># \u52a0\u8f7d\u9e22\u5c3e\u82b1\u6570\u636e\u96c6<br \/>\niris &#061; load_iris()<br \/>\ndata &#061; iris.data<br \/>\ntarget &#061; iris.target<\/p>\n<p># \u53ea\u53d6\u524d\u4e24\u7c7b&#xff08;setosa \u548c versicolor&#xff09;\u4ee5\u53ca\u4e24\u4e2a\u7279\u5f81&#xff1a;\u82b1\u843c\u957f\u5ea6&#xff08;0&#xff09;\u548c\u82b1\u74e3\u957f\u5ea6&#xff08;2&#xff09;<br \/>\nX &#061; data[0:100, [0, 2]]<br \/>\ny &#061; target[0:100]<\/p>\n<p>\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9e22\u5c3e\u82b1\u6570\u636e\u96c6\u5171\u6709 150 \u4e2a\u6837\u672c\u30013 \u4e2a\u7c7b\u522b&#xff08;0\u30011\u30012&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u4e86\u4fbf\u4e8e\u4e8c\u7ef4\u53ef\u89c6\u5316&#xff0c;\u8fd9\u91cc\u53d6\u524d\u4e24\u7c7b&#xff08;\u6807\u7b7e 0 \u548c 1&#xff09;&#xff0c;\u5e76\u4e14\u53ea\u7528\u4e24\u4e2a\u7279\u5f81&#xff08;\u4fbf\u4e8e\u753b\u4e8c\u7ef4\u5e73\u9762&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>2. \u6784\u5efa\u5e76\u8bad\u7ec3 SVM \u6a21\u578b<\/h3>\n<p># \u7ebf\u6027\u6838\u51fd\u6570&#xff0c;C&#061;\u221e \u76f8\u5f53\u4e8e\u786c\u95f4\u9694 SVM<br \/>\nmodel &#061; SVC(kernel&#061;&#039;linear&#039;, C&#061;float(&#039;inf&#039;), random_state&#061;100)<br \/>\nmodel.fit(X, y)<\/p>\n<p>\u6838\u5fc3\u53c2\u6570\u89e3\u91ca&#xff1a;<\/p>\n<ul>\n<li>\n<p>kernel&#061;&#039;linear&#039;&#xff1a;\u4f7f\u7528\u7ebf\u6027\u6838\u51fd\u6570&#xff0c;\u9002\u7528\u4e8e\u7ebf\u6027\u53ef\u5206\u7684\u60c5\u51b5\u3002<\/p>\n<\/li>\n<li>\n<p>C&#061;float(&#039;inf&#039;)&#xff1a;\u60e9\u7f5a\u56e0\u5b50 C \u8d8a\u5927&#xff0c;\u5bf9\u8bef\u5206\u7c7b\u7684\u5bb9\u5fcd\u5ea6\u8d8a\u4f4e&#xff0c;\u8fd9\u91cc\u53d6\u65e0\u9650\u5927\u76f8\u5f53\u4e8e\u786c\u95f4\u9694\u6700\u5927\u5316\u3002<\/p>\n<\/li>\n<li>\n<p>random_state&#xff1a;\u968f\u673a\u79cd\u5b50&#xff0c;\u4fdd\u8bc1\u7ed3\u679c\u53ef\u590d\u73b0\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>3. \u6570\u636e\u53ef\u89c6\u5316<\/h3>\n<p># \u7ed8\u5236\u4e24\u7c7b\u6570\u636e\u7684\u6563\u70b9\u56fe<br \/>\nplt.scatter(X[0:50, 0], X[0:50, 1], c&#061;&#039;r&#039;, marker&#061;&#039;o&#039;, label&#061;&#039;\u7c7b\u522b0&#039;)<br \/>\nplt.scatter(X[50:100, 0], X[50:100, 1], c&#061;&#039;g&#039;, marker&#061;&#039;&#043;&#039;, label&#061;&#039;\u7c7b\u522b1&#039;)<\/p>\n<ul>\n<li>\n<p>\u7c7b\u522b 0&#xff08;\u7ea2\u8272\u5706\u70b9&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7c7b\u522b 1&#xff08;\u7eff\u8272\u52a0\u53f7&#xff09;<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 style=\"background-color:transparent\">4. \u7ed8\u5236\u51b3\u7b56\u8fb9\u754c\u548c\u95f4\u9694\u7ebf<\/h3>\n<p># \u83b7\u53d6\u8d85\u5e73\u9762\u53c2\u6570 w \u548c b<br \/>\nw &#061; model.coef_[0]<br \/>\nb &#061; model.intercept_[0]<\/p>\n<p># \u51b3\u7b56\u8fb9\u754c&#xff1a;w1*x1 &#043; w2*x2 &#043; b &#061; 0<br \/>\nx1 &#061; np.linspace(0, 10, 100)<br \/>\nx2 &#061; -(w[0] * x1 &#043; b) \/ w[1]<\/p>\n<p># \u95f4\u9694\u8fb9\u754c&#xff1a;w1*x1 &#043; w2*x2 &#043; b &#061; \u00b11<br \/>\nx3 &#061; (1 &#8211; (w[0] * x1 &#043; b)) \/ w[1]<br \/>\nx4 &#061; (-1 &#8211; (w[0] * x1 &#043; b)) \/ w[1]<\/p>\n<p># \u7ed8\u5236<br \/>\nplt.plot(x1,x2,c&#061;&#039;b&#039;,label&#061;&#039;\u51b3\u7b56\u8fb9\u754c&#039;)<br \/>\nplt.plot(x1,x3,c&#061;&#039;b&#039;,linestyle&#061;&#039;&#8211;&#039;,label&#061;&#039;\u95f4\u9694\u8fb9\u754c&#039;)<br \/>\nplt.plot(x1,x4,c&#061;&#039;b&#039;,linestyle&#061;&#039;&#8211;&#039;,label&#061;&#039;\u95f4\u9694\u8fb9\u754c&#039;)<\/p>\n<ul>\n<li>\n<p>\u5b9e\u7ebf&#xff1a;\u51b3\u7b56\u8fb9\u754c<\/p>\n<\/li>\n<li>\n<p>\u865a\u7ebf&#xff1a;\u4e24\u6761\u95f4\u9694\u8fb9\u754c&#xff0c;\u652f\u6301\u5411\u91cf\u4f4d\u4e8e\u8fd9\u4e24\u6761\u7ebf\u4e0a\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 style=\"background-color:transparent\">5. \u6807\u8bb0\u652f\u6301\u5411\u91cf<\/h3>\n<p># \u83b7\u53d6\u652f\u6301\u5411\u91cf<br \/>\nvets &#061; model.support_vectors_<br \/>\nplt.scatter(vets[:, 0], vets[:, 1], s&#061;100, facecolors&#061;&#039;none&#039;, edgecolors&#061;&#039;b&#039;, label&#061;&#039;\u652f\u6301\u5411\u91cf&#039;)<\/p>\n<p>\u652f\u6301\u5411\u91cf\u662f\u79bb\u51b3\u7b56\u8fb9\u754c\u6700\u8fd1\u7684\u6837\u672c\u70b9&#xff0c;SVM \u7684\u4f18\u5316\u76ee\u6807\u5c31\u662f\u6700\u5927\u5316\u8fd9\u4e9b\u70b9\u5230\u8fb9\u754c\u7684\u95f4\u9694\u3002<\/p>\n<p>model.support_vectors_ \u662f\u4e00\u4e2a numpy.ndarray&#xff0c;\u5f62\u72b6\u4e3a (n_support_vectors, n_features)\u3002<\/p>\n<p>\u6bcf\u4e00\u884c\u5c31\u662f\u4e00\u4e2a\u652f\u6301\u5411\u91cf\u5728\u8bad\u7ec3\u65f6\u4f7f\u7528\u7684\u7279\u5f81\u7a7a\u95f4\u5750\u6807&#xff08;\u5373\u8bad\u7ec3\u65f6\u8f93\u5165\u7ed9 SVM \u7684\u7279\u5f81&#xff0c;\u82e5\u8bad\u7ec3\u524d\u505a\u8fc7 StandardScaler\/PCA \u7b49\u53d8\u6362&#xff0c;\u5219\u8fd9\u91cc\u662f\u53d8\u6362\u540e\u7684\u5750\u6807&#xff09;\u3002<\/p>\n<ul>\n<li>\n<p>vets[:, 0], vets[:, 1]<\/p>\n<ul>\n<li>\n<p>\u53d6\u652f\u6301\u5411\u91cf\u77e9\u9635\u7684\u7b2c 0 \u5217\u548c\u7b2c 1 \u5217\u4f5c\u4e3a x\u3001y \u5750\u6807 \u2014\u2014 \u524d\u63d0\u662f\u6570\u636e\u786e\u5b9e\u662f\u4e8c\u7ef4\u3002\u82e5\u7ef4\u5ea6 &gt;2&#xff0c;\u9700\u8981\u5148\u964d\u7ef4&#xff08;PCA\/t-SNE&#xff09;\u518d\u753b\u56fe\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>s&#061;100<\/p>\n<ul>\n<li>\n<p>\u6807\u8bb0\u5927\u5c0f&#xff0c;\u6ce8\u610f&#xff1a;s \u8868\u793a\u70b9\u7684\u9762\u79ef&#xff08;points^2&#xff09;&#xff0c;\u4e0d\u662f\u534a\u5f84\u3002s&#061;100 \u6bd4\u8f83\u663e\u773c&#xff1b;\u9700\u8981\u66f4\u5927\u66f4\u660e\u663e\u53ef\u4ee5\u6539\u6210 s&#061;150 \u6216 s&#061;300\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>facecolors&#061;&#039;none&#039;<\/p>\n<ul>\n<li>\n<p>\u4f7f\u6807\u8bb0\u5185\u90e8\u4e0d\u586b\u5145&#xff08;\u7a7a\u5fc3&#xff09;&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u201c\u5708\u51fa\u201d\u70b9\u800c\u4e0d\u906e\u6321\u539f\u6765\u7684\u989c\u8272\/\u5f62\u72b6\u3002\u5e38\u7528\u4e8e\u7a81\u51fa\u67d0\u4e9b\u70b9&#xff08;\u6bd4\u5982\u652f\u6301\u5411\u91cf&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>edgecolors&#061;&#039;b&#039;<\/p>\n<ul>\n<li>\n<p>\u6807\u8bb0\u8fb9\u7f18\u989c\u8272\u8bbe\u4e3a\u84dd\u8272&#xff08;&#039;b&#039;&#xff09;\u3002\u5f53 facecolors&#061;&#039;none&#039; \u4e14 marker \u662f\u53ef\u586b\u5145&#xff08;\u5982 &#039;o&#039;&#xff09;\u65f6&#xff0c;\u4f1a\u753b\u6210\u84dd\u8272\u7a7a\u5fc3\u5706\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>label&#061;&#039;\u652f\u6301\u5411\u91cf&#039;<\/p>\n<ul>\n<li>\n<p>\u7528\u4e8e\u56fe\u4f8b\u663e\u793a\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 style=\"background-color:transparent\">6. \u663e\u793a\u7ed3\u679c<\/h3>\n<p>plt.legend()<br \/>\nplt.show()<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"455\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812115946-689b2cb2af548.png\" width=\"596\" \/><\/p>\n<ul>\n<li>\n<p>\u7ea2\u8272\u5706\u70b9\u548c\u7eff\u8272\u52a0\u53f7\u5206\u522b\u4ee3\u8868\u4e24\u7c7b\u6837\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u84dd\u8272\u5b9e\u7ebf\u662f\u51b3\u7b56\u8fb9\u754c&#xff0c;\u865a\u7ebf\u662f\u6700\u5927\u95f4\u9694\u7ebf\u3002<\/p>\n<\/li>\n<li>\n<p>\u84dd\u8272\u5708\u51fa\u7684\u70b9\u662f\u652f\u6301\u5411\u91cf\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 style=\"background-color:transparent\">7. \u7ed3\u679c\u4e0e\u5206\u6790<\/h3>\n<h4 style=\"background-color:transparent\">1. \u652f\u6301\u5411\u91cf&#xff08;Support Vectors&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u5b9a\u4e49&#xff1a;\u652f\u6301\u5411\u91cf\u662f\u79bb\u5206\u7c7b\u8fb9\u754c\u6700\u8fd1\u7684\u6837\u672c\u70b9&#xff0c;\u5b83\u4eec\u4f4d\u4e8e\u6700\u5927\u95f4\u9694\u8fb9\u754c\u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f5c\u7528&#xff1a;<\/p>\n<li>\n<p>\u552f\u4e00\u51b3\u5b9a\u5206\u7c7b\u8d85\u5e73\u9762\u7684\u4f4d\u7f6e\u548c\u65b9\u5411\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u662f\u6240\u6709\u6837\u672c\u90fd\u4f1a\u5f71\u54cd\u5206\u7c7b\u7ed3\u679c&#xff0c;\u53ea\u6709\u652f\u6301\u5411\u91cf\u624d\u4f1a\u53c2\u4e0e\u4f18\u5316\u8ba1\u7b97\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u79fb\u9664\u975e\u652f\u6301\u5411\u91cf&#xff0c;\u6a21\u578b\u7684\u5206\u7c7b\u7ed3\u679c\u4e0d\u4f1a\u53d8&#xff1b;\u4f46\u5982\u679c\u79fb\u9664\u652f\u6301\u5411\u91cf&#xff0c;\u8fb9\u754c\u4f1a\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u5728\u56fe\u4e2d&#xff1a;\u84dd\u8272\u5708\u51fa\u6765\u7684\u70b9&#xff0c;\u5c31\u662f\u652f\u6301\u5411\u91cf\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>2. \u51b3\u7b56\u8fb9\u754c&#xff08;Decision Boundary&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u6570\u5b66\u5f62\u5f0f&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"30\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812115948-689b2cb41a813.png\" width=\"275\" \/><\/p>\n<p>\u8fd9\u662f\u6a21\u578b\u6700\u7ec8\u627e\u5230\u7684\u6700\u4f73\u5206\u7c7b\u8d85\u5e73\u9762&#xff0c;\u5b83\u80fd\u6700\u5927\u5316\u4e24\u7c7b\u6837\u672c\u7684\u95f4\u9694\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f5c\u7528&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5904\u5728\u8be5\u7ebf\u4e0a\u7684\u70b9&#xff0c;SVM \u5224\u65ad\u5b83\u4eec\u5c5e\u4e8e\u54ea\u4e00\u7c7b\u7684\u6982\u7387\u662f\u4e94\u4e94\u5f00&#xff08;\u5206\u7c7b\u51b3\u7b56\u503c\u4e3a 0&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u51b3\u7b56\u8fb9\u754c\u5de6\u4fa7\u7684\u70b9\u5224\u4e3a\u4e00\u7c7b&#xff0c;\u53f3\u4fa7\u7684\u70b9\u5224\u4e3a\u53e6\u4e00\u7c7b&#xff08;\u5bf9\u4e8e\u4e8c\u7ef4\u7a7a\u95f4\u800c\u8a00&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5728\u56fe\u4e2d&#xff1a;\u84dd\u8272\u5b9e\u7ebf\u662f\u51b3\u7b56\u8fb9\u754c\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>3. \u95f4\u9694\u8fb9\u754c&#xff08;Margin Boundaries&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u6570\u5b66\u5f62\u5f0f&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"34\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812115948-689b2cb47371b.png\" width=\"285\" \/><\/p>\n<p>\u548c<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"33\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812115948-689b2cb4eab7b.png\" width=\"299\" \/><\/p>\n<p>\u8fd9\u4e24\u6761\u7ebf\u8868\u793a\u79bb\u51b3\u7b56\u8fb9\u754c\u7b49\u8ddd\u79bb\u7684\u4e24\u6761\u5e73\u884c\u7ebf\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f5c\u7528&#xff1a;<\/p>\n<li>\n<p>\u95f4\u9694&#xff08;Margin&#xff09;\u662f\u8fd9\u4e24\u6761\u865a\u7ebf\u4e4b\u95f4\u7684\u533a\u57df&#xff0c;SVM \u4f1a\u52aa\u529b\u8ba9\u8fd9\u4e2a\u533a\u57df\u5c3d\u53ef\u80fd\u5bbd\u3002<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301\u5411\u91cf\u6b63\u597d\u843d\u5728\u8fd9\u4e24\u6761\u865a\u7ebf\u4e0a\u3002<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u5728\u56fe\u4e2d&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u84dd\u8272\u865a\u7ebf\u662f\u6700\u5927\u95f4\u9694\u8fb9\u754c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5176\u4e2d\u4e00\u6761\u865a\u7ebf\u7d27\u8d34\u7c7b\u522b 0 \u7684\u652f\u6301\u5411\u91cf&#xff0c;\u53e6\u4e00\u6761\u7d27\u8d34\u7c7b\u522b 1 \u7684\u652f\u6301\u5411\u91cf\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>8. \u5b8c\u6574\u4ee3\u7801<\/h3>\n<p>from sklearn.datasets import load_iris<br \/>\nfrom sklearn.svm import SVC<br \/>\nimport numpy as np<br \/>\nimport matplotlib.pyplot as plt<br \/>\nplt.rcParams[&#034;font.family&#034;] &#061; [&#034;SimHei&#034;, &#034;WenQuanYi Micro Hei&#034;, &#034;Heiti TC&#034;]<\/p>\n<p>iris &#061; load_iris()<br \/>\ndata &#061; iris.data<br \/>\nX &#061; data[0:100,[0,2]]<br \/>\ny &#061; iris.target[0:100]<br \/>\nmodel &#061; SVC(kernel&#061;&#039;linear&#039;, C&#061;float(&#039;inf&#039;), random_state&#061;100)<br \/>\nmodel.fit(X, y)<\/p>\n<p>plt.scatter(X[0:50,0],X[0:50,1],c&#061;&#039;r&#039;,marker&#061;&#039;o&#039;,label&#061;&#039;\u7c7b\u522b0&#039;)<br \/>\nplt.scatter(X[50:100,0],X[50:100,1],c&#061;&#039;g&#039;,marker&#061;&#039;&#043;&#039;,label&#061;&#039;\u7c7b\u522b1&#039;)<\/p>\n<p>w &#061; model.coef_[0]<br \/>\nb &#061; model.intercept_[0]<\/p>\n<p>x1 &#061; np.linspace(0,10,100)<br \/>\nx2 &#061; -(w[0]*x1&#043;b)\/w[1]<br \/>\nx3 &#061; (1-(w[0]*x1&#043;b))\/w[1]<br \/>\nx4 &#061; (-1-(w[0]*x1&#043;b))\/w[1]<\/p>\n<p>plt.plot(x1,x2,c&#061;&#039;b&#039;,label&#061;&#039;\u51b3\u7b56\u8fb9\u754c&#039;)<br \/>\nplt.plot(x1,x3,c&#061;&#039;b&#039;,linestyle&#061;&#039;&#8211;&#039;,label&#061;&#039;\u95f4\u9694\u8fb9\u754c&#039;)<br \/>\nplt.plot(x1,x4,c&#061;&#039;b&#039;,linestyle&#061;&#039;&#8211;&#039;,label&#061;&#039;\u95f4\u9694\u8fb9\u754c&#039;)<\/p>\n<p>vets &#061; model.support_vectors_<br \/>\nplt.scatter(vets[:,0],vets[:,1],s&#061;100,facecolors&#061;&#039;none&#039;, edgecolors&#061;&#039;b&#039;,label&#061;&#039;\u652f\u6301\u5411\u91cf&#039;)<\/p>\n<p>plt.legend()<br \/>\nplt.show()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb962\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09-CSDN\u535a\u5ba2\u3002<\/p>\n","protected":false},"author":2,"featured_media":53945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2792,207,305,427],"topic":[],"class_list":["post-53950","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-2792","tag-207","tag-305","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/53950.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb962\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09-CSDN\u535a\u5ba2\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/53950.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-12T11:59:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812115945-689b2cb161289.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/53950.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/53950.html\",\"name\":\"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-12T11:59:50+00:00\",\"dateModified\":\"2025-08-12T11:59:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/53950.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/53950.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/53950.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/53950.html","og_locale":"zh_CN","og_type":"article","og_title":"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb962\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09-CSDN\u535a\u5ba2\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/53950.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-12T11:59:50+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812115945-689b2cb161289.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/53950.html","url":"https:\/\/www.wsisp.com\/helps\/53950.html","name":"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-12T11:59:50+00:00","dateModified":"2025-08-12T11:59:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/53950.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/53950.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/53950.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u673a\u5668\u5b66\u4e60\u2014\u2014\u652f\u6301\u5411\u91cf\u673a\uff08SVM\uff09\u5b9e\u6218\u6848\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/53950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=53950"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/53950\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/53945"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=53950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=53950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=53950"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=53950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}