{"id":464,"date":"2018-07-12T12:14:04","date_gmt":"2018-07-12T04:14:04","guid":{"rendered":"http:\/\/www.tastestars.com\/?p=464"},"modified":"2018-07-12T12:56:41","modified_gmt":"2018-07-12T04:56:41","slug":"0712","status":"publish","type":"post","link":"https:\/\/tastestars.com\/index.php\/2018\/07\/12\/0712\/","title":{"rendered":"\u3010\u673a\u5668\u5b66\u4e60\u3011\u4e0d\u5e73\u8861\u6570\u636e\u5206\u7c7b\u65b9\u6cd5"},"content":{"rendered":"<p>\u5728\u6211\u7684\u9879\u76ee\u4e2d\u4e5f\u9047\u5230\u4e86\u6570\u636e\u4e0d\u5e73\u8861\u7684\u73b0\u8c61\uff0c\u5176\u5b9e\u5728\u75c5\u7406\u65b9\u9762\u5f88\u5bb9\u6613\u9047\u5230\u5065\u5eb7\u6837\u672c\u591a\u3001\u75be\u75c5\u6837\u672c\u5c11\uff0c\u6216\u8005\u4f53\u865a\u8f83\u591a\uff0c\u4f53\u5b9e\u8f83\u5c11\u7684\u73b0\u8c61\u3002\u901a\u8fc7\u4e00\u5b9a\u7684\u6570\u636e\u5e73\u8861\u65b9\u6cd5\u53ef\u4ee5\u5927\u5927\u6539\u8fdb\u5b9e\u9a8c\u7684\u53ef\u9760\u6027\uff0c\u4ee5\u53ca\u63d0\u5347\u67e5\u5168\u7387\u3001\u67e5\u51c6\u7387\u3002<\/p>\n<ul>\n<li>\u5e38\u7528\u89e3\u51b3\u65b9\u6cd5\uff1a\n<ul>\n<li>\u6539\u53d8\u6570\u636e\u5206\u5e03<\/li>\n<li>\u8bbe\u8ba1\u65b0\u7684\u5206\u7c7b\u65b9\u6cd5<\/li>\n<li>\u8bbe\u8ba1\u65b0\u7684\u5206\u7c7b\u5668\u6027\u80fd\u8bc4\u4ef7\u51c6\u5219<\/li>\n<\/ul>\n<\/li>\n<li>\u96be\u70b9\uff1a\n<ul>\n<li>\u7ecf\u5178\u7684\u5206\u7c7b\u7cbe\u5ea6\u8bc4\u4ef7\u51c6\u5219\u4e0d\u80fd\u9002\u7528\u4e8e\u4e0d\u5e73\u8861\u7684\u5206\u7c7b\u5668\u6027\u80fd\u5224\u522b<\/li>\n<li>\u4ec5\u6709\u5f88\u5c11\u7684\u5c11\u6570\u7c7b\u6837\u672c\u6570\u636e<\/li>\n<li>\u6570\u636e\u788e\u7247\uff0c\u5f88\u591a\u7b97\u6cd5\u91c7\u7528\u5206\u6cbb\u6cd5\uff0c\u9648\u80dc\u5f88\u591a\u5b50\u7a7a\u95f4\u5305\u542b\u5f88\u5c11\u7684\u5c11\u91cf\u6837\u672c<\/li>\n<li>\u4e0d\u6070\u5f53\u7684\u5f52\u7eb3\u504f\u7f6e<\/li>\n<\/ul>\n<\/li>\n<li>\u65b9\u6cd5\uff1a\n<ul>\n<li>\u6570\u636e\u5c42\u9762\uff1a\n<ul>\n<li>\u8fc7\u62bd\u6837\uff1a\u5728\u5c0f\u6570\u636e\u7684\u79cd\u7c7b\u4e0a\u591a\u62bd\u6837<\/li>\n<li>\u6b20\u62bd\u6837\uff1a\u51cf\u5c11\u591a\u6570\u6837\u672c\u6765\u63d0\u9ad8\u5c11\u6570\u7c7b\u7684\u5206\u7c7b\u6027\u80fd\uff0c\u5c3d\u91cf\u4e0d\u5220\u9664\u6709\u7528\u7684\u6837\u672c\uff0c\u591a\u6570\u7c7b\u6837\u672c\u88ab\u5206\u4e3a\u201c\u566a\u97f3\u6837\u672c\u201d\u3001\u201c\u8fb9\u754c\u6837\u672c\u201d\u548c\u201c\u5b89\u5168\u6837\u672c\u201d\u3002\u5c06\u8fb9\u754c\u6837\u672c\u548c\u566a\u97f3\u6837\u672c\u4ece\u591a\u6570\u7c7b\u4e2d\u5220\u9664\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7b97\u6cd5\u5c42\u9762\uff1a\n<ul>\n<li>\u4ee3\u4ef7\u654f\u611f\u65b9\u6cd5\uff1a\n<ul>\n<li>\u91cd\u6784\u8bad\u7ec3\u96c6\uff1a\u6839\u636e\u6837\u672c\u7684\u4e0d\u540c\u9519\u5206\u4ee3\u4ef7\u91cd\u6784\u8bad\u7ec3\u96c6\uff0c\u7ed9\u6bcf\u4e00\u4e2a\u6837\u672c\u52a0\u6743\u4e0d\u6539\u53d8\u5df2\u6709\u7684\u7b97\u6cd5\u3002\u7f3a\uff1a\u4e22\u5931\u4e86\u4e00\u4e9b\u6709\u7528\u7684\u4fe1\u606f\u3002<\/li>\n<li>\u5f15\u5165\u4ee3\u4ef7\u654f\u611f\u56e0\u5b50\uff1a\u9519\u5206\u4ee3\u4ef7\u4e0d\u540c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u96c6\u6210\u5b66\u4e60\u65b9\u6cd5\uff1a\u6309\u7167\u57fa\u672c\u5206\u7c7b\u5668\u4e4b\u95f4\u7684\u79cd\u7c7b\u5173\u7cfb\u5206\u4e3a\uff1a\n<ul>\n<li>\u5f02\u6001\u96c6\u6210\u5b66\u4e60\uff1a\u4f7f\u7528\u5404\u79cd\u4e0d\u540c\u7684\u5206\u7c7b\u5668\u8fdb\u884c\u96c6\u6210<\/li>\n<li>\u540c\u6001\u96c6\u6210\u5b66\u4e60\uff1a\u96c6\u6210\u7684\u57fa\u672c\u5206\u7c7b\u5668\u90fd\u662f\u540c\u4e00\u79cd\u5206\u7c7b\u5668\uff0c\u53ea\u662f\u5206\u7c7b\u5668\u4e4b\u95f4\u53c2\u6570\u4e0d\u540c\u3002(\u6295\u7968)<br \/>\nAdaboost,AdaCost,RareBoost<\/li>\n<\/ul>\n<\/li>\n<li>\u5355\u7c7b\u5206\u7c7b\u5668\u65b9\u6cd5\uff1a\u5bf9\u5355\u4e00\u7c7b\u6570\u636e\u8fdb\u884c\u8bad\u7ec3\uff0c\u6bd4\u5982\u8bf4SVM\u7684one Class<\/li>\n<li>\u9762\u5411\u5355\u4e2a\u6b63\u7c7b\u7684FLDA\u7b97\u6cd5\uff0cFisher\u7ebf\u6027\u5224\u522b\u65b9\u6cd5\uff0c\u627e\u51fa\u5355\u4e2a\u6b63\u7c7b\u5728\u8d1f\u7c7b\u4e2d\u7684k\u4e2a\u8fd1\u90bb\uff0c\u6309\u7167\u4e00\u5b9a\u89c4\u5219\u4f9d\u6b21\u5728\u5355\u4e2a\u6b63\u4f8b\u548c\u5b83\u5404\u4e2a\u8fd1\u90bb\u7684\u8fde\u7ebf\u4e0a\u4ea7\u751f\u5408\u6210\u6837\u672c\uff0c\u5c06\u5408\u6210\u6837\u672c\u6dfb\u52a0\u5230\u539f\u59cb\u6b63\u7c7b\u4e2d\uff08\u6b63\u5c11\u8d1f\u591a\uff09<\/li>\n<li>\u591a\u7c7b\u4e0d\u5e73\u8861\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\uff1a\u91c7\u7528\u5df2\u6709\u7684\u591a\u7c7b\u5206\u7c7b\u65b9\u6cd5\u548c\u4e24\u7c7b\u4e0d\u5e73\u8861\u5206\u7c7b\u7b56\u7565\u76f8\u7ed3\u5408\u3002<\/li>\n<li>\u5176\u4ed6\uff1a\u4e3b\u52a8\u5b66\u4e60\u3001\u968f\u673a\u68ee\u6797\u3001\u5b50\u7a7a\u95f4\u65b9\u6cd5\u3001\u7279\u5f81\u9009\u62e9\u65b9\u6cd5\u3001SVM\u6a21\u578b\u4e0b\u7684\u540e\u9a8c\u6982\u7387\u6c42\u89e3\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u4e0d\u5e73\u8861\u6570\u636e\u5206\u7c7b\u7684\u8bc4\u4ef7\u51c6\u5219\uff1a\n<ul>\n<li>\u67e5\u5168\u7387(recall)\u3001\u67e5\u51c6\u7387(precision)\u3001F-value\u3001G-mean\u503c\u3001AUC<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8bba\u6587\uff1a\u6768\u660e, \u5c39\u519b\u6885, \u5409\u6839\u6797. \u4e0d\u5e73\u8861\u6570\u636e\u5206\u7c7b\u65b9\u6cd5\u7efc\u8ff0[J]. \u5357\u4eac\u5e08\u8303\u5927\u5b66\u5b66\u62a5(\u5de5\u7a0b\u6280\u672f\u7248), 2008, 8(4):7-12.<\/p>\n<p>\u5176\u4e2d\uff0c\u5728\u673a\u5668\u5b66\u4e60\u5e93sklearn\u4e2d\uff0csvm\u9488\u5bf9\u6570\u636e\u4e0d\u5e73\u8861\u6709\u4e24\u79cd\u4e0d\u540c\u7684\u5904\u7406\u65b9\u6cd5\uff1a<\/p>\n<h4>sample_weight<\/h4>\n<p>\u5bf9\u4e8e\u6837\u672c\uff0c\u52a0\u4e0a\u6743\u91cd\uff0c\u4f8b\u5982\u4f60\u7684\u75be\u75c5\u6837\u672c\u86ee\u5c11\uff0c\u4f60\u7ed9\u90e8\u5206\u6709\u663e\u8457\u7279\u5f81\u7684\u75be\u75c5\u6837\u672c\u52a0\u4e0a\u5927\u7684\u6743\u91cd\uff0c\u5728\u4e0e\u5065\u5eb7\u6837\u672c\u533a\u5206\u4e0d\u5927\u7684\u75be\u75c5\u6837\u672c\u52a0\u4e0a\u4e00\u4e2a\u5c0f\u4e00\u70b9\u7684\u6743\u91cd\u3002\u5177\u4f53\u4f7f\u7528\u65b9\u6cd5\u662f\uff1a<\/p>\n<pre class=\"lang:python decode:true \" >\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import svm\n\n\ndef plot_decision_function(classifier, sample_weight, axis, title):\n    # plot the decision function\n    xx, yy = np.meshgrid(np.linspace(-4, 5, 500), np.linspace(-4, 5, 500))\n\n    Z = classifier.decision_function(np.c_[xx.ravel(), yy.ravel()])\n    Z = Z.reshape(xx.shape)\n\n    # plot the line, the points, and the nearest vectors to the plane\n    axis.contourf(xx, yy, Z, alpha=0.75, cmap=plt.cm.bone)\n    axis.scatter(X[:, 0], X[:, 1], c=y, s=100 * sample_weight, alpha=0.9,\n                 cmap=plt.cm.bone, edgecolors='black')\n\n    axis.axis('off')\n    axis.set_title(title)\n\n\n# we create 20 points\nnp.random.seed(0)\nX = np.r_[np.random.randn(10, 2) + [1, 1], np.random.randn(10, 2)]\ny = [1] * 10 + [-1] * 10\n# print(y)\nsample_weight_last_ten = abs(np.random.randn(len(X)))\nsample_weight_constant = np.ones(len(X))\n# and bigger weights to some outliers\nsample_weight_last_ten[15:] *= 5\nsample_weight_last_ten[9] *= 15\n\n# for reference, first fit without class weights\n\n# fit the model\nclf_weights = svm.SVC()\n# print(sample_weight_last_ten)\n# print(X.shape)\n# print(sample_weight_last_ten.shape)\nclf_weights.fit(X, y, sample_weight=sample_weight_last_ten)\n\nclf_no_weights = svm.SVC()\nclf_no_weights.fit(X, y)\n\nfig, axes = plt.subplots(1, 2, figsize=(14, 6))\nplot_decision_function(clf_no_weights, sample_weight_constant, axes[0],\n                       \"Constant weights\")\nplot_decision_function(clf_weights, sample_weight_last_ten, axes[1],\n                       \"Modified weights\")\n\n# plt.show()<\/pre>\n<p>\u505a\u51fa\u6765\u957f\u8fd9\u6837\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"468\" data-permalink=\"https:\/\/tastestars.com\/index.php\/2018\/07\/12\/0712\/%e6%8d%95%e8%8e%b7-6\/\" data-orig-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7.png\" data-orig-size=\"1177,546\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\u6355\u83b7\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7-300x139.png\" data-large-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7-1024x475.png\" src=\"http:\/\/www.tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7-300x139.png\" alt=\"\" width=\"300\" height=\"139\" class=\"alignnone size-medium wp-image-468\" srcset=\"https:\/\/tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7-300x139.png 300w, https:\/\/tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7-768x356.png 768w, https:\/\/tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7-1024x475.png 1024w, https:\/\/tastestars.com\/wp-content\/uploads\/2018\/07\/\u6355\u83b7.png 1177w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><br \/>\n\u5de6\u8fb9\u662f\u6ca1\u6709\u6743\u91cd\u4e4b\u524d\uff0c\u53f3\u8fb9\u662f\u52a0\u4e86\u6743\u91cd\uff0c\u53ef\u4ee5\u770b\u770b\u533a\u522b\u3002\u4e0d\u8fc7\u6ce8\u610f\uff0c<br \/>\n\u6587\u6863\u4e2d\u7684sample_weight\u5b9a\u4e49\uff1a<br \/>\nsample_weight : array-like, shape = [n_samples], optional Sample weights.<br \/>\n\u8f93\u5165\u7684X\uff08\u4e5f\u5c31\u662f\u5b83\u7684\u5750\u6807\uff09\u957f\u8fd9\u6837\uff1a<br \/>\n[[ 2.76405235  1.40015721]<br \/>\n [ 1.97873798  3.2408932 ]<br \/>\n [ 2.86755799  0.02272212]<br \/>\n [ 1.95008842  0.84864279]<br \/>\n [ 0.89678115  1.4105985 ]<br \/>\n [ 1.14404357  2.45427351]<br \/>\n [ 1.76103773  1.12167502]<br \/>\n [ 1.44386323  1.33367433]<br \/>\n [ 2.49407907  0.79484174]<br \/>\n [ 1.3130677   0.14590426]<br \/>\n [-2.55298982  0.6536186 ]<br \/>\n [ 0.8644362  -0.74216502]<br \/>\n [ 2.26975462 -1.45436567]<br \/>\n [ 0.04575852 -0.18718385]<br \/>\n [ 1.53277921  1.46935877]<br \/>\n [ 0.15494743  0.37816252]<br \/>\n [-0.88778575 -1.98079647]<br \/>\n [-0.34791215  0.15634897]<br \/>\n [ 1.23029068  1.20237985]<br \/>\n [-0.38732682 -0.30230275]]<\/p>\n<p>\u800c\u5b83\u7684\u6743\u91cd\u957f\u8fd9\u6837\uff1a<br \/>\n[ 1.04855297  1.42001794  1.70627019  1.9507754   0.50965218  0.4380743<br \/>\n  1.25279536  0.77749036  1.61389785  3.1911042   0.89546656  0.3869025<br \/>\n  0.51080514  1.18063218  0.02818223  2.14165935  0.33258611  1.51235949<br \/>\n  3.17161047  1.81370583]<\/p>\n<h4>class_weight<\/h4>\n<p>\u663e\u800c\u6613\u89c1\uff0c\u8fd9\u4e2aclass\u6743\u91cd\uff0c\u5c31\u662f\u9488\u5bf9\u7684\u67d0\u4e00\u7c7b\u6837\u672c\u5f88\u5c11\u7684\u60c5\u51b5\uff0c\u4f8b\u5982\uff0c\u60a3\u75c5\u8fd9\u4e00\u7c7b\u5f88\u5c11\uff0c\u5c31\u5c06\u75be\u75c5\u8fd9\u4e00\u7c7b\u7684class\u6743\u91cd\u52a0\u5927\u3002sklearn\u4e2d\u662f\u8fd9\u6837\u5b9a\u4e49\u7684\uff1a<br \/>\nclass_weight : {dict, \u2018balanced\u2019}, optional<\/p>\n<p>Set the parameter C of class i to class_weight[i]*C for SVC. If not given, all classes are supposed to have weight one. The \u201cbalanced\u201d mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples \/ (n_classes * np.bincount(y))<\/p>\n<p>\u6ce8\u610f\u5662\uff0c\u5b83\u662f\u4e00\u4e2a\u5b57\u5178\u7684\u5f62\u5f0f\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"lang:python decode:true \" >svc =  svm.SVC(kernel='linear', C=C,class_weight={1:6,0:1}).fit(X_train, y_train)<\/pre>\n<p>\u597d\u5566\uff0c\u5173\u4e8e\u6570\u636e\u5e73\u8861\u7684\u65b9\u6cd5\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u5566\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6211\u7684\u9879\u76ee\u4e2d\u4e5f\u9047\u5230\u4e86\u6570\u636e\u4e0d\u5e73\u8861\u7684\u73b0\u8c61\uff0c\u5176\u5b9e\u5728\u75c5\u7406\u65b9\u9762\u5f88\u5bb9\u6613\u9047\u5230\u5065\u5eb7\u6837\u672c\u591a\u3001\u75be\u75c5\u6837\u672c\u5c11\uff0c\u6216\u8005\u4f53\u865a\u8f83\u591a\uff0c\u4f53\u5b9e\u8f83\u5c11\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[61],"tags":[],"class_list":["post-464","post","type-post","status-publish","format-standard","hentry","category-61"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s9Hs6X-0712","_links":{"self":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/comments?post=464"}],"version-history":[{"count":3,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/464\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/464\/revisions\/469"}],"wp:attachment":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/media?parent=464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/categories?post=464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/tags?post=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}