{"id":450,"date":"2025-04-29T22:35:36","date_gmt":"2025-04-29T14:35:36","guid":{"rendered":"https:\/\/www.vcoco.top\/?p=450"},"modified":"2025-04-29T22:35:37","modified_gmt":"2025-04-29T14:35:37","slug":"%e5%86%8d%e6%88%98%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0-%e5%86%b3%e7%ad%96%e6%a0%91%ef%bc%88%e6%89%be%e5%b7%a5%e4%bd%9c%e7%af%87%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.vcoco.top\/index.php\/2025\/04\/29\/%e5%86%8d%e6%88%98%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0-%e5%86%b3%e7%ad%96%e6%a0%91%ef%bc%88%e6%89%be%e5%b7%a5%e4%bd%9c%e7%af%87%ef%bc%89\/","title":{"rendered":"\u518d\u6218\u673a\u5668\u5b66\u4e60\u2014\u2014\u51b3\u7b56\u6811\uff08\u627e\u5de5\u4f5c\u7bc7\uff09\u00a0"},"content":{"rendered":"\n<p>\u51b3\u7b56\u6811\u4e00\u822c\u7684\u4e09\u79cd\u7b97\u6cd5\uff1aID3\uff0cC4.5\uff0cCART\u3002<\/p>\n\n\n\n<p>ID3 sklearn\u624b\u6413<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># from sklearn.metric import accuracy_score\r\nimport numpy as np\r\nimport pandas as pd\r\n\r\nfrom sklearn.datasets import load_iris\r\n\r\ndatas=load_iris()\r\nprint(datas.keys())\r\nX=datas&#91;'data']\r\ny=datas&#91;'target']\n\n# \u7b80\u5386\u51b3\u7b56\u6811\u6a21\u578b\r\nfrom sklearn import tree\r\ndc_tree=tree.DecisionTreeClassifier(criterion='entropy', min_samples_leaf=5)\r\ndc_tree.fit(X, y)\n\ny_predict = dc_tree.predict(X) \r\nfrom sklearn.metrics import accuracy_score\r\n\r\naccuracy=accuracy_score(y, y_predict)\r\nprint(accuracy)\n\n# %matplotlib inline\r\nfrom matplotlib import pyplot as plt\r\n# fig = plt.figure(figsize=(10,10))\r\ntree.plot_tree(dc_tree, filled=True, feature_names= datas&#91;'feature_names'], class_names=datas&#91;'target_names'])\n```<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0.9733333333333334\nText(0.4444444444444444, 0.9, 'petal width (cm) &lt;= 0.8\\nentropy = 1.585\\nsamples = 150\\nvalue = &#91;50, 50, 50]\\nclass = setosa'),\n Text(0.3333333333333333, 0.7, 'entropy = 0.0\\nsamples = 50\\nvalue = &#91;50, 0, 0]\\nclass = setosa'),\n Text(0.38888888888888884, 0.8, 'True  '),\n Text(0.5555555555555556, 0.7, 'petal width (cm) &lt;= 1.75\\nentropy = 1.0\\nsamples = 100\\nvalue = &#91;0, 50, 50]\\nclass = versicolor'),\n Text(0.5, 0.8, '  False'),\n Text(0.3333333333333333, 0.5, 'petal length (cm) &lt;= 4.95\\nentropy = 0.445\\nsamples = 54\\nvalue = &#91;0, 49, 5]\\nclass = versicolor'),\n Text(0.2222222222222222, 0.3, 'sepal length (cm) &lt;= 5.15\\nentropy = 0.146\\nsamples = 48\\nvalue = &#91;0, 47, 1]\\nclass = versicolor'),\n Text(0.1111111111111111, 0.1, 'entropy = 0.722\\nsamples = 5\\nvalue = &#91;0, 4, 1]\\nclass = versicolor'),\n Text(0.3333333333333333, 0.1, 'entropy = 0.0\\nsamples = 43\\nvalue = &#91;0, 43, 0]\\nclass = versicolor'),\n Text(0.4444444444444444, 0.3, 'entropy = 0.918\\nsamples = 6\\nvalue = &#91;0, 2, 4]\\nclass = virginica'),\n Text(0.7777777777777778, 0.5, 'petal length (cm) &lt;= 4.95\\nentropy = 0.151\\nsamples = 46\\nvalue = &#91;0, 1, 45]\\nclass = virginica'),\n Text(0.6666666666666666, 0.3, 'entropy = 0.65\\nsamples = 6\\nvalue = &#91;0, 1, 5]\\nclass = virginica'),\n Text(0.8888888888888888, 0.3, 'entropy = 0.0\\nsamples = 40\\nvalue = &#91;0, 0, 40]\\nclass = virginica')]<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.vcoco.top\/wp-content\/uploads\/2025\/04\/image-11.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"515\" height=\"389\" data-original=\"https:\/\/www.vcoco.top\/wp-content\/uploads\/2025\/04\/image-11.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-452\"  sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/div><\/figure>\n\n\n\n<p>\u4fee\u6539min_samples_leaf=1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u7b80\u5386\u51b3\u7b56\u6811\u6a21\u578b\r\nfrom sklearn import tree\r\ndc_tree=tree.DecisionTreeClassifier(criterion='entropy', min_samples_leaf=1)\r\ndc_tree.fit(X, y)\r\n\r\ny_predict = dc_tree.predict(X) \r\nfrom sklearn.metrics import accuracy_score\r\n\r\naccuracy=accuracy_score(y, y_predict)\r\nprint(accuracy)\r\n\r\n# %matplotlib inline\r\nfrom matplotlib import pyplot as plt\r\n# fig = plt.figure(figsize=(10,10))\r\ntree.plot_tree(dc_tree, filled=True, feature_names= datas&#91;'feature_names'], class_names=datas&#91;'target_names'])\n<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.0\r\n&#91;Text(0.5, 0.9166666666666666, 'petal length (cm) &lt;= 2.45\\nentropy = 1.585\\nsamples = 150\\nvalue = &#91;50, 50, 50]\\nclass = setosa'),\r\n Text(0.4230769230769231, 0.75, 'entropy = 0.0\\nsamples = 50\\nvalue = &#91;50, 0, 0]\\nclass = setosa'),\r\n Text(0.46153846153846156, 0.8333333333333333, 'True  '),\r\n Text(0.5769230769230769, 0.75, 'petal width (cm) &lt;= 1.75\\nentropy = 1.0\\nsamples = 100\\nvalue = &#91;0, 50, 50]\\nclass = versicolor'),\r\n Text(0.5384615384615384, 0.8333333333333333, '  False'),\r\n Text(0.3076923076923077, 0.5833333333333334, 'petal length (cm) &lt;= 4.95\\nentropy = 0.445\\nsamples = 54\\nvalue = &#91;0, 49, 5]\\nclass = versicolor'),\r\n Text(0.15384615384615385, 0.4166666666666667, 'petal width (cm) &lt;= 1.65\\nentropy = 0.146\\nsamples = 48\\nvalue = &#91;0, 47, 1]\\nclass = versicolor'),\r\n Text(0.07692307692307693, 0.25, 'entropy = 0.0\\nsamples = 47\\nvalue = &#91;0, 47, 0]\\nclass = versicolor'),\r\n Text(0.23076923076923078, 0.25, 'entropy = 0.0\\nsamples = 1\\nvalue = &#91;0, 0, 1]\\nclass = virginica'),\r\n Text(0.46153846153846156, 0.4166666666666667, 'petal width (cm) &lt;= 1.55\\nentropy = 0.918\\nsamples = 6\\nvalue = &#91;0, 2, 4]\\nclass = virginica'),\r\n Text(0.38461538461538464, 0.25, 'entropy = 0.0\\nsamples = 3\\nvalue = &#91;0, 0, 3]\\nclass = virginica'),\r\n Text(0.5384615384615384, 0.25, 'sepal length (cm) &lt;= 6.95\\nentropy = 0.918\\nsamples = 3\\nvalue = &#91;0, 2, 1]\\nclass = versicolor'),\r\n Text(0.46153846153846156, 0.08333333333333333, 'entropy = 0.0\\nsamples = 2\\nvalue = &#91;0, 2, 0]\\nclass = versicolor'),\r\n Text(0.6153846153846154, 0.08333333333333333, 'entropy = 0.0\\nsamples = 1\\nvalue = &#91;0, 0, 1]\\nclass = virginica'),\r\n Text(0.8461538461538461, 0.5833333333333334, 'petal length (cm) &lt;= 4.85\\nentropy = 0.151\\nsamples = 46\\nvalue = &#91;0, 1, 45]\\nclass = virginica'),\r\n Text(0.7692307692307693, 0.4166666666666667, 'sepal width (cm) &lt;= 3.1\\nentropy = 0.918\\nsamples = 3\\nvalue = &#91;0, 1, 2]\\nclass = virginica'),\r\n Text(0.6923076923076923, 0.25, 'entropy = 0.0\\nsamples = 2\\nvalue = &#91;0, 0, 2]\\nclass = virginica'),\r\n Text(0.8461538461538461, 0.25, 'entropy = 0.0\\nsamples = 1\\nvalue = &#91;0, 1, 0]\\nclass = versicolor'),\r\n Text(0.9230769230769231, 0.4166666666666667, 'entropy = 0.0\\nsamples = 43\\nvalue = &#91;0, 0, 43]\\nclass = virginica')]<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.vcoco.top\/wp-content\/uploads\/2025\/04\/image-13.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"790\" data-original=\"https:\/\/www.vcoco.top\/wp-content\/uploads\/2025\/04\/image-13.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-455\"  sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u51b3\u7b56\u6811\u4e00\u822c\u7684\u4e09\u79cd\u7b97\u6cd5\uff1aID3\uff0cC4.5\uff0cCART\u3002 ID3 sklearn\u624b\u6413 \u8f93\u51fa \u4fee\u6539min_sample [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[97,96],"class_list":["post-450","post","type-post","status-publish","format-standard","hentry","category-machine-learning","tag-id3","tag-96"],"_links":{"self":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/comments?post=450"}],"version-history":[{"count":3,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/450\/revisions"}],"predecessor-version":[{"id":456,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/450\/revisions\/456"}],"wp:attachment":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/media?parent=450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/categories?post=450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/tags?post=450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}