{"id":1221,"date":"2023-07-27T06:02:37","date_gmt":"2023-07-27T06:02:37","guid":{"rendered":"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/"},"modified":"2023-07-27T06:02:37","modified_gmt":"2023-07-27T06:02:37","slug":"r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91","status":"publish","type":"post","link":"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/","title":{"rendered":"\u5982\u4f55\u5728 r \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u5f53\u4e00\u7ec4\u9884\u6d4b\u53d8\u91cf\u548c<a href=\"https:\/\/statorials.org\/cn\/\u53d8\u91cf\u89e3\u91ca\u6027\u53cd\u5e94\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u54cd\u5e94\u53d8\u91cf<\/a>\u4e4b\u95f4\u7684\u5173\u7cfb\u662f\u7ebf\u6027\u65f6\uff0c<a href=\"https:\/\/statorials.org\/cn\/\u591a\u5143\u7ebf\u6027\u56de\u5f52-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u591a\u5143\u7ebf\u6027\u56de\u5f52<\/a>\u7b49\u65b9\u6cd5\u53ef\u4ee5\u751f\u6210\u51c6\u786e\u7684\u9884\u6d4b\u6a21\u578b\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u7136\u800c\uff0c\u5f53\u4e00\u7ec4\u9884\u6d4b\u53d8\u91cf\u548c\u54cd\u5e94\u4e4b\u95f4\u7684\u5173\u7cfb\u66f4\u52a0\u590d\u6742\u65f6\uff0c\u975e\u7ebf\u6027\u65b9\u6cd5\u901a\u5e38\u53ef\u4ee5\u751f\u6210\u66f4\u51c6\u786e\u7684\u6a21\u578b\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u662f <a href=\"https:\/\/statorials.org\/cn\/\u5206\u7c7b\u548c\u56de\u5f52\u6811\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u5206\u7c7b\u548c\u56de\u5f52\u6811<\/a>(CART)\uff0c\u5b83\u4f7f\u7528\u4e00\u7ec4\u9884\u6d4b\u53d8\u91cf\u6765\u521b\u5efa\u9884\u6d4b\u54cd\u5e94\u53d8\u91cf\u503c\u7684\u51b3\u7b56\u6811\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5982\u679c\u54cd\u5e94\u53d8\u91cf\u662f\u8fde\u7eed\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u56de\u5f52\u6811\uff0c\u5982\u679c\u54cd\u5e94\u53d8\u91cf\u662f\u5206\u7c7b\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u5206\u7c7b\u6811\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u5728 R \u4e2d\u521b\u5efa\u56de\u5f52\u6811\u548c\u5206\u7c7b\u6811\u3002<\/span><\/p>\n<h3><span style=\"color: #000000;\"><strong>\u793a\u4f8b 1\uff1a\u5728 R \u4e2d\u6784\u5efa\u56de\u5f52\u6811<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528<strong>ISLR<\/strong>\u5305\u4e2d\u7684<strong>Hitters<\/strong>\u6570\u636e\u96c6\uff0c\u5176\u4e2d\u5305\u542b 263 \u540d\u804c\u4e1a\u68d2\u7403\u8fd0\u52a8\u5458\u7684\u5404\u79cd\u4fe1\u606f\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u5c06\u4f7f\u7528\u6b64\u6570\u636e\u96c6\u6784\u5efa\u4e00\u4e2a\u56de\u5f52\u6811\uff0c\u8be5\u56de\u5f52\u6811\u4f7f\u7528<em>\u672c\u5792\u6253<\/em>\u548c<em>\u6253\u7403\u5e74\u4efd<\/em>\u7684\u9884\u6d4b\u53d8\u91cf\u6765\u9884\u6d4b\u7ed9\u5b9a\u7403\u5458\u7684<em>\u85aa\u6c34<\/em>\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u521b\u5efa\u6b64\u56de\u5f52\u6811\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\"><strong>\u6b65\u9aa41\uff1a\u52a0\u8f7d\u5fc5\u8981\u7684\u5305\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u9996\u5148\uff0c\u6211\u4eec\u5c06\u52a0\u8f7d\u6b64\u793a\u4f8b\u6240\u9700\u7684\u5305\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\">library<\/span> (ISLR) <span style=\"color: #008080;\">#contains Hitters dataset<\/span>\n<span style=\"color: #993300;\">library<\/span> (rpart) <span style=\"color: #008080;\">#for fitting decision trees<\/span>\n<span style=\"color: #993300;\">library<\/span> (rpart.plot) <span style=\"color: #008080;\">#for plotting decision trees\n<\/span><\/strong><\/pre>\n<p><span style=\"color: #000000;\"><strong>\u6b65\u9aa4 2\uff1a\u6784\u5efa\u521d\u59cb\u56de\u5f52\u6811\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u9996\u5148\uff0c\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u5927\u578b\u7684\u521d\u59cb\u56de\u5f52\u6811\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u8f83\u5c0f\u7684<strong>cp<\/strong>\u503c\uff08\u4ee3\u8868\u201c\u590d\u6742\u5ea6\u53c2\u6570\u201d\uff09\u6765\u4fdd\u8bc1\u6811\u5f88\u5927\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8fd9\u610f\u5473\u7740\u53ea\u8981\u6a21\u578b\u7684\u6574\u4f53 R \u5e73\u65b9\u81f3\u5c11\u589e\u52a0 cp \u6307\u5b9a\u7684\u503c\uff0c\u6211\u4eec\u5c31\u4f1a\u5bf9\u56de\u5f52\u6811\u6267\u884c\u8fdb\u4e00\u6b65\u7684\u5206\u5272\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u7136\u540e\u6211\u4eec\u5c06\u4f7f\u7528<strong>printcp()<\/strong>\u51fd\u6570\u6253\u5370\u6a21\u578b\u7ed3\u679c\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #008080;\">#build the initial tree\n<\/span><span style=\"color: #000000;\">tree &lt;- rpart(Salary ~ Years + HmRun, data=Hitters, control=rpart. <span style=\"color: #3366ff;\">control<\/span> (cp= <span style=\"color: #008000;\">.0001<\/span> ))\n\n<span style=\"color: #008080;\">#view results<\/span>\nprintcp(tree)\n\nVariables actually used in tree construction:\n[1] HmRun Years\n\nRoot node error: 53319113\/263 = 202734\n\nn=263 (59 observations deleted due to missingness)\n\n           CP nsplit rel error xerror xstd\n1 0.24674996 0 1.00000 1.00756 0.13890\n2 0.10806932 1 0.75325 0.76438 0.12828\n3 0.01865610 2 0.64518 0.70295 0.12769\n4 0.01761100 3 0.62652 0.70339 0.12337\n5 0.01747617 4 0.60891 0.70339 0.12337\n6 0.01038188 5 0.59144 0.66629 0.11817\n7 0.01038065 6 0.58106 0.65697 0.11687\n8 0.00731045 8 0.56029 0.67177 0.11913\n9 0.00714883 9 0.55298 0.67881 0.11960\n10 0.00708618 10 0.54583 0.68034 0.11988\n11 0.00516285 12 0.53166 0.68427 0.11997\n12 0.00445345 13 0.52650 0.68994 0.11996\n13 0.00406069 14 0.52205 0.68988 0.11940\n14 0.00264728 15 0.51799 0.68874 0.11916\n15 0.00196586 16 0.51534 0.68638 0.12043\n16 0.00016686 17 0.51337 0.67577 0.11635\n17 0.00010000 18 0.51321 0.67576 0.11615\nn=263 (59 observations deleted due to missingness)\n<\/span><\/span><\/strong><\/pre>\n<p><span style=\"color: #000000;\"><strong>\u7b2c\u4e09\u6b65\uff1a\u4fee\u526a\u6811\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4fee\u526a\u56de\u5f52\u6811\uff0c\u4ee5\u627e\u5230\u7528\u4e8e cp\uff08\u590d\u6742\u6027\u53c2\u6570\uff09\u7684\u6700\u4f73\u503c\uff0c\u4ece\u800c\u5b9e\u73b0\u6700\u4f4e\u7684\u6d4b\u8bd5\u8bef\u5dee\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8bf7\u6ce8\u610f\uff0ccp \u7684\u6700\u4f73\u503c\u662f\u5bfc\u81f4\u524d\u4e00\u8f93\u51fa\u4e2d<strong>x \u8bef\u5dee<\/strong>\u6700\u4f4e\u7684\u503c\uff0c\u5b83\u8868\u793a\u4ea4\u53c9\u9a8c\u8bc1\u6570\u636e\u7684\u89c2\u6d4b\u503c\u7684\u8bef\u5dee\u3002<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #008080;\">#identify best cp value to use\n<span style=\"color: #000000;\">best &lt;- tree$cptable[which. <span style=\"color: #3366ff;\">min<\/span> (tree$cptable[,\" <span style=\"color: #008000;\">xerror<\/span> \"]),\" <span style=\"color: #008000;\">CP<\/span> \"]\n\n<span style=\"color: #008080;\">#produce a pruned tree based on the best cp value\n<\/span>pruned_tree &lt;- <span style=\"color: #3366ff;\">prune<\/span> (tree, cp=best)\n\n<span style=\"color: #008080;\">#plot the pruned tree\n<\/span>prp(pruned_tree,\n    faclen= <span style=\"color: #008000;\">0<\/span> , <span style=\"color: #008080;\">#use full names for factor labels<\/span>\n    extra= <span style=\"color: #008000;\">1<\/span> , <span style=\"color: #008080;\">#display number of obs. for each terminal node<\/span>\n    roundint= <span style=\"color: #008000;\">F<\/span> , <span style=\"color: #008080;\">#don't round to integers in output<\/span>\n    digits= <span style=\"color: #008000;\">5<\/span> ) <span style=\"color: #008080;\">#display 5 decimal places in output\n<\/span><\/span><\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12094 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre3.png\" alt=\"R \u4e2d\u7684\u56de\u5f52\u6811\" width=\"425\" height=\"326\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u6700\u7ec8\u7684\u4fee\u526a\u6811\u6709\u516d\u4e2a\u7ec8\u7aef\u8282\u70b9\u3002\u6bcf\u4e2a\u53f6\u8282\u70b9\u663e\u793a\u8be5\u8282\u70b9\u4e2d\u7403\u5458\u7684\u9884\u6d4b\u5de5\u8d44\u4ee5\u53ca\u539f\u59cb\u6570\u636e\u96c6\u4e2d\u5c5e\u4e8e\u8be5\u7ea7\u522b\u7684\u89c2\u5bdf\u6570\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u539f\u59cb\u6570\u636e\u96c6\u4e2d\uff0c\u6709 90 \u540d\u7ecf\u9a8c\u4e0d\u8db3 4.5 \u5e74\u7684\u7403\u5458\uff0c\u4ed6\u4eec\u7684\u5e73\u5747\u5de5\u8d44\u4e3a $225.83K\u3002<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12095 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre4.png\" alt=\"\u89e3\u91ca R \u4e2d\u7684\u56de\u5f52\u6811\" width=\"403\" height=\"302\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p><span style=\"color: #000000;\"><strong>\u7b2c\u56db\u6b65\uff1a\u4f7f\u7528\u6811\u8fdb\u884c\u9884\u6d4b\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6700\u7ec8\u7684\u4fee\u526a\u6811\u6765\u6839\u636e\u7ed9\u5b9a\u7403\u5458\u7684\u591a\u5e74\u7ecf\u9a8c\u548c\u5e73\u5747\u672c\u5792\u6253\u6765\u9884\u6d4b\u4ed6\u7684\u85aa\u6c34\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f8b\u5982\uff0c\u4e00\u540d\u62e5\u6709 7 \u5e74\u7ecf\u9a8c\u3001\u5e73\u5747\u6253\u51fa 4 \u4e2a\u672c\u5792\u6253\u7684\u7403\u5458\uff0c\u5176\u9884\u671f\u85aa\u8d44\u4e3a<strong>$502.81k<\/strong> \u3002<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12096 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre5.png\" alt=\"R \u4e2d\u56de\u5f52\u6811\u7684\u793a\u4f8b\" width=\"422\" height=\"306\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528R\u4e2d\u7684<strong>predict()<\/strong>\u51fd\u6570\u6765\u786e\u8ba4\u8fd9\u4e00\u70b9\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #008080;\">#define new player\n<span style=\"color: #000000;\">new &lt;- data.frame(Years=7, HmRun=4)\n\n<\/span>#use pruned tree to predict salary of this player\n<span style=\"color: #000000;\">predict(pruned_tree, newdata=new)\n\n502.8079<\/span><\/span><\/span><\/strong><\/pre>\n<h3><span style=\"color: #000000;\"><strong>\u793a\u4f8b 2\uff1a\u5728 R \u4e2d\u6784\u5efa\u5206\u7c7b\u6811<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528<strong>rpart.plot<\/strong>\u5305\u4e2d\u7684<strong>ptitanic<\/strong>\u6570\u636e\u96c6\uff0c\u5176\u4e2d\u5305\u542b\u6709\u5173\u6cf0\u5766\u5c3c\u514b\u53f7\u4e0a\u4e58\u5ba2\u7684\u5404\u79cd\u4fe1\u606f\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u5c06\u4f7f\u7528\u6b64\u6570\u636e\u96c6\u521b\u5efa\u4e00\u4e2a\u5206\u7c7b\u6811\uff0c\u8be5\u5206\u7c7b\u6811\u4f7f\u7528\u9884\u6d4b\u53d8\u91cf<em>\u7c7b<\/em>\u3001<em>\u6027\u522b<\/em>\u548c<em>\u5e74\u9f84<\/em>\u6765\u9884\u6d4b\u7ed9\u5b9a\u4e58\u5ba2\u662f\u5426\u5e78\u5b58\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u521b\u5efa\u6b64\u5206\u7c7b\u6811\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\"><strong>\u6b65\u9aa41\uff1a\u52a0\u8f7d\u5fc5\u8981\u7684\u5305\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u9996\u5148\uff0c\u6211\u4eec\u5c06\u52a0\u8f7d\u6b64\u793a\u4f8b\u6240\u9700\u7684\u5305\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\">library<\/span> (rpart) <span style=\"color: #008080;\">#for fitting decision trees<\/span>\n<span style=\"color: #993300;\">library<\/span> (rpart.plot) <span style=\"color: #008080;\">#for plotting decision trees\n<\/span><\/strong><\/pre>\n<p><span style=\"color: #000000;\"><strong>\u6b65\u9aa42\uff1a\u6784\u5efa\u521d\u59cb\u5206\u7c7b\u6811\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u9996\u5148\uff0c\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u5927\u578b\u7684\u521d\u59cb\u5206\u7c7b\u6811\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u8f83\u5c0f\u7684<strong>cp<\/strong>\u503c\uff08\u4ee3\u8868\u201c\u590d\u6742\u5ea6\u53c2\u6570\u201d\uff09\u6765\u4fdd\u8bc1\u6811\u5f88\u5927\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8fd9\u610f\u5473\u7740\u53ea\u8981\u6574\u4f53\u6a21\u578b\u62df\u5408\u5ea6\u81f3\u5c11\u589e\u52a0 cp \u6307\u5b9a\u7684\u503c\uff0c\u6211\u4eec\u5c31\u4f1a\u5bf9\u5206\u7c7b\u6811\u6267\u884c\u8fdb\u4e00\u6b65\u7684\u5206\u5272\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u7136\u540e\u6211\u4eec\u5c06\u4f7f\u7528<strong>printcp()<\/strong>\u51fd\u6570\u6253\u5370\u6a21\u578b\u7ed3\u679c\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #008080;\">#build the initial tree\n<\/span><span style=\"color: #000000;\">tree &lt;- rpart(survived~pclass+sex+age, data=ptitanic, control=rpart. <span style=\"color: #3366ff;\">control<\/span> (cp= <span style=\"color: #008000;\">.0001<\/span> ))\n\n<span style=\"color: #008080;\">#view results<\/span>\nprintcp(tree)\n\nVariables actually used in tree construction:\n[1] age pclass sex   \n\nRoot node error: 500\/1309 = 0.38197\n\nn=1309 \n\n      CP nsplit rel error xerror xstd\n1 0.4240 0 1.000 1.000 0.035158\n2 0.0140 1 0.576 0.576 0.029976\n3 0.0095 3 0.548 0.578 0.030013\n4 0.0070 7 0.510 0.552 0.029517\n5 0.0050 9 0.496 0.528 0.029035\n6 0.0025 11 0.486 0.532 0.029117\n7 0.0020 19 0.464 0.536 0.029198\n8 0.0001 22 0.458 0.528 0.029035\n<\/span><\/span><\/strong><\/pre>\n<p><span style=\"color: #000000;\"><strong>\u7b2c\u4e09\u6b65\uff1a\u4fee\u526a\u6811\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4fee\u526a\u56de\u5f52\u6811\uff0c\u4ee5\u627e\u5230\u7528\u4e8e cp\uff08\u590d\u6742\u6027\u53c2\u6570\uff09\u7684\u6700\u4f73\u503c\uff0c\u4ece\u800c\u5b9e\u73b0\u6700\u4f4e\u7684\u6d4b\u8bd5\u8bef\u5dee\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8bf7\u6ce8\u610f\uff0ccp \u7684\u6700\u4f73\u503c\u662f\u5bfc\u81f4\u524d\u4e00\u8f93\u51fa\u4e2d<strong>x \u8bef\u5dee<\/strong>\u6700\u4f4e\u7684\u503c\uff0c\u5b83\u8868\u793a\u4ea4\u53c9\u9a8c\u8bc1\u6570\u636e\u7684\u89c2\u6d4b\u503c\u7684\u8bef\u5dee\u3002<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #008080;\">#identify best cp value to use\n<span style=\"color: #000000;\">best &lt;- tree$cptable[which. <span style=\"color: #3366ff;\">min<\/span> (tree$cptable[,\" <span style=\"color: #008000;\">xerror<\/span> \"]),\" <span style=\"color: #008000;\">CP<\/span> \"]\n\n<span style=\"color: #008080;\">#produce a pruned tree based on the best cp value\n<\/span>pruned_tree &lt;- <span style=\"color: #3366ff;\">prune<\/span> (tree, cp=best)\n\n<span style=\"color: #008080;\">#plot the pruned tree\n<\/span>prp(pruned_tree,\n    faclen= <span style=\"color: #008000;\">0<\/span> , #use full names for factor labels\n    extra= <span style=\"color: #008000;\">1<\/span> , #display number of obs. for each terminal node\n    roundint= <span style=\"color: #008000;\">F<\/span> , #don't round to integers in output\n    digits= <span style=\"color: #008000;\">5<\/span> ) #display 5 decimal places in output\n<\/span><\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12098 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre6.png\" alt=\"R \u4e2d\u7684\u6811\u5206\u7c7b\" width=\"415\" height=\"422\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u6700\u7ec8\u7684\u526a\u679d\u6811\u6709 10 \u4e2a\u7ec8\u7aef\u8282\u70b9\u3002\u6bcf\u4e2a\u822a\u7ad9\u697c\u8282\u70b9\u90fd\u663e\u793a\u6b7b\u4ea1\u4e58\u5ba2\u4eba\u6570\u4ee5\u53ca\u5e78\u5b58\u8005\u4eba\u6570\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f8b\u5982\uff0c\u5728\u6700\u5de6\u8fb9\u7684\u8282\u70b9\u4e2d\uff0c\u6211\u4eec\u770b\u5230 664 \u540d\u4e58\u5ba2\u6b7b\u4ea1\uff0c136 \u540d\u4e58\u5ba2\u5e78\u5b58\u3002<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12099 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre7.png\" alt=\"\u89e3\u91ca R \u4e2d\u7684\u5206\u7c7b\u6811\" width=\"462\" height=\"463\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p><span style=\"color: #000000;\"><strong>\u7b2c\u56db\u6b65\uff1a\u4f7f\u7528\u6811\u8fdb\u884c\u9884\u6d4b\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6700\u7ec8\u7684\u4fee\u526a\u6811\u6765\u6839\u636e\u4e58\u5ba2\u7684\u7c7b\u522b\u3001\u5e74\u9f84\u548c\u6027\u522b\u6765\u9884\u6d4b\u7279\u5b9a\u4e58\u5ba2\u7684\u751f\u5b58\u6982\u7387\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f8b\u5982\uff0c\u4e00\u540d 8 \u5c81\u7684\u4e00\u7b49\u8231\u7537\u6027\u4e58\u5ba2\u7684\u751f\u5b58\u6982\u7387\u4e3a 11\/29 = 37.9%\u3002<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12100 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre8.png\" alt=\"R \u4e2d\u7684\u6811\u5206\u7c7b\" width=\"402\" height=\"417\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p><span style=\"color: #000000;\">\u60a8\u53ef\u4ee5<a href=\"https:\/\/github.com\/Statorials\/R-Guides\/blob\/main\/CART_models.R\" target=\"_blank\" rel=\"noopener noreferrer\">\u5728\u6b64\u5904<\/a>\u627e\u5230\u8fd9\u4e9b\u793a\u4f8b\u4e2d\u4f7f\u7528\u7684\u5b8c\u6574 R \u4ee3\u7801\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4e00\u7ec4\u9884\u6d4b\u53d8\u91cf\u548c\u54cd\u5e94\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u662f\u7ebf\u6027\u65f6\uff0c\u591a\u5143\u7ebf\u6027\u56de\u5f52\u7b49\u65b9\u6cd5\u53ef\u4ee5\u751f\u6210\u51c6\u786e\u7684\u9884\u6d4b\u6a21\u578b\u3002 \u7136\u800c\uff0c\u5f53\u4e00\u7ec4\u9884\u6d4b\u53d8\u91cf\u548c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-1221","post","type-post","status-publish","format-standard","hentry","category-11"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811<\/title>\n<meta name=\"description\" content=\"\u672c\u6559\u7a0b\u901a\u8fc7\u5206\u6b65\u793a\u4f8b\u89e3\u91ca\u4e86\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/cn\/r-\u4e2d\u7684\u5206\u7c7b\u548c\u56de\u5f52\u6811\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6559\u7a0b\u901a\u8fc7\u5206\u6b65\u793a\u4f8b\u89e3\u91ca\u4e86\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/cn\/r-\u4e2d\u7684\u5206\u7c7b\u548c\u56de\u5f52\u6811\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-27T06:02:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre3.png\" \/>\n<meta name=\"author\" content=\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/\",\"url\":\"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/\",\"name\":\"\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/cn\/#website\"},\"datePublished\":\"2023-07-27T06:02:37+00:00\",\"dateModified\":\"2023-07-27T06:02:37+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261\"},\"description\":\"\u672c\u6559\u7a0b\u901a\u8fc7\u5206\u6b65\u793a\u4f8b\u89e3\u91ca\u4e86\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u5bb6\",\"item\":\"https:\/\/statorials.org\/cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5982\u4f55\u5728 r \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/cn\/#website\",\"url\":\"https:\/\/statorials.org\/cn\/\",\"name\":\"Statorials\",\"description\":\"\u60a8\u7684\u7edf\u8ba1\u7d20\u517b\u6307\u5357\uff01\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261\",\"name\":\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\"},\"description\":\"\u5927\u5bb6\u597d\uff0c\u6211\u662f\u672c\u6770\u660e\uff0c\u4e00\u4f4d\u9000\u4f11\u7684\u7edf\u8ba1\u5b66\u6559\u6388\uff0c\u540e\u6765\u6210\u4e3a Statorials \u7684\u70ed\u5fc3\u6559\u5e08\u3002 \u51ed\u501f\u5728\u7edf\u8ba1\u9886\u57df\u7684\u4e30\u5bcc\u7ecf\u9a8c\u548c\u4e13\u4e1a\u77e5\u8bc6\uff0c\u6211\u6e34\u671b\u5206\u4eab\u6211\u7684\u77e5\u8bc6\uff0c\u901a\u8fc7 Statorials \u589e\u5f3a\u5b66\u751f\u7684\u80fd\u529b\u3002\u4e86\u89e3\u66f4\u591a\",\"sameAs\":[\"https:\/\/statorials.org\/cn\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811","description":"\u672c\u6559\u7a0b\u901a\u8fc7\u5206\u6b65\u793a\u4f8b\u89e3\u91ca\u4e86\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\u3002","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:\/\/statorials.org\/cn\/r-\u4e2d\u7684\u5206\u7c7b\u548c\u56de\u5f52\u6811\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811","og_description":"\u672c\u6559\u7a0b\u901a\u8fc7\u5206\u6b65\u793a\u4f8b\u89e3\u91ca\u4e86\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\u3002","og_url":"https:\/\/statorials.org\/cn\/r-\u4e2d\u7684\u5206\u7c7b\u548c\u56de\u5f52\u6811\/","og_site_name":"Statorials","article_published_time":"2023-07-27T06:02:37+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/arbre3.png"}],"author":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/","url":"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/","name":"\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811","isPartOf":{"@id":"https:\/\/statorials.org\/cn\/#website"},"datePublished":"2023-07-27T06:02:37+00:00","dateModified":"2023-07-27T06:02:37+00:00","author":{"@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261"},"description":"\u672c\u6559\u7a0b\u901a\u8fc7\u5206\u6b65\u793a\u4f8b\u89e3\u91ca\u4e86\u5982\u4f55\u5728 R \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811\u3002","breadcrumb":{"@id":"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/cn\/r-%e4%b8%ad%e7%9a%84%e5%88%86%e7%b1%bb%e5%92%8c%e5%9b%9e%e5%bd%92%e6%a0%91\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u5bb6","item":"https:\/\/statorials.org\/cn\/"},{"@type":"ListItem","position":2,"name":"\u5982\u4f55\u5728 r \u4e2d\u62df\u5408\u5206\u7c7b\u6811\u548c\u56de\u5f52\u6811"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/cn\/#website","url":"https:\/\/statorials.org\/cn\/","name":"Statorials","description":"\u60a8\u7684\u7edf\u8ba1\u7d20\u517b\u6307\u5357\uff01","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261","name":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a"},"description":"\u5927\u5bb6\u597d\uff0c\u6211\u662f\u672c\u6770\u660e\uff0c\u4e00\u4f4d\u9000\u4f11\u7684\u7edf\u8ba1\u5b66\u6559\u6388\uff0c\u540e\u6765\u6210\u4e3a Statorials \u7684\u70ed\u5fc3\u6559\u5e08\u3002 \u51ed\u501f\u5728\u7edf\u8ba1\u9886\u57df\u7684\u4e30\u5bcc\u7ecf\u9a8c\u548c\u4e13\u4e1a\u77e5\u8bc6\uff0c\u6211\u6e34\u671b\u5206\u4eab\u6211\u7684\u77e5\u8bc6\uff0c\u901a\u8fc7 Statorials \u589e\u5f3a\u5b66\u751f\u7684\u80fd\u529b\u3002\u4e86\u89e3\u66f4\u591a","sameAs":["https:\/\/statorials.org\/cn"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts\/1221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/comments?post=1221"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts\/1221\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/media?parent=1221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/categories?post=1221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/tags?post=1221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}