{"id":370893,"date":"2024-05-21T04:35:57","date_gmt":"2024-05-21T04:35:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=370893"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=370893","title":{"rendered":"<span>\u0412\u044b\u0436\u0438\u043c\u0430\u0435\u043c \u0438\u0437 Random Forest \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c: \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0442\u0443 \u043f\u0440\u0438 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0411\u044b\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430: \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u2014 \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0438\u043b\u0438 \u043d\u0435\u0442. \u0418 \u043a\u0430\u043a \u0431\u044b \u044f \u043a \u044d\u0442\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043d\u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u043b\u0441\u044f, \u0441 \u043a\u0430\u043a\u043e\u0433\u043e \u0440\u0430\u043a\u0443\u0440\u0441\u0430 \u043d\u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u043b, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0443\u0432\u044b, \u043d\u0435 \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u044f\u043b. \u0414\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b\u043e \u043c\u0430\u043b\u043e, \u0430 \u0442\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e, \u043e\u0431\u043b\u0430\u0434\u0430\u043b\u043e \u0441\u043b\u0430\u0431\u043e\u0439 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u043b\u043e\u0439. \u0425\u043e\u0442\u044f \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0418 \u0432\u043e\u0442, \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043c\u0435\u043d\u044f \u043e\u0441\u0435\u043d\u0438\u043b\u043e \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e-\u043a\u0430 \u044f \u043e\u0431\u0440\u0435\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 Random Forest, \u0434\u043e \u043e\u0434\u043d\u043e\u0439, \u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0432\u0435\u0442\u043a\u0438. \u0418 \u2014 \u043e \u0447\u0443\u0434\u043e! \u2014 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u043a\u0430\u043a \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c (precision), \u0442\u0430\u043a \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u0430 (recall).\u00a0\u0418 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0442\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043b \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445. \u0418 \u0432\u0435\u0437\u0434\u0435 \u043f\u0440\u0438 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0432\u044b\u0440\u043e\u0441\u0442\u0430\u043b\u0430 \u043f\u043e\u043b\u043d\u043e\u0442\u0430. \u0427\u0442\u043e \u0436\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u043b?<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ee5\/892\/aed\/ee5892aedcefd97af083fc5cf0a247eb.png\" width=\"1131\" height=\"373\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ee5\/892\/aed\/ee5892aedcefd97af083fc5cf0a247eb.png\"\/><\/figure>\n<h2>\u0418\u0434\u0435\u044f<\/h2>\n<p>\u041e\u0431\u0440\u0435\u0437\u043a\u0430 \u0438\u043b\u0438 \u0441\u0442\u0440\u0438\u0436\u043a\u0430 (pruning) \u0434\u0435\u0440\u0435\u0432\u0430 \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u043e\u0440\u044c\u0431\u044b \u0441 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c. \u041e\u0431\u044b\u0447\u043d\u043e \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0440\u043e\u0441\u0442\u0430 (\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u0430, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043b\u0438\u0441\u0442\u0435 \u0438 \u0442. \u0434.).\u00a0\u042d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0435\u0437\u043a\u0430 (pre-pruning), \u0430 \u043f\u043e \u0441\u0443\u0442\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u043e\u0441\u0442\u0430.<\/p>\n<p>\u041d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u0438 _\u0432_\u0441\u0430\u043c\u043e\u043c_\u0434\u0435\u043b\u0435\u0448\u043d\u0430\u044f_ \u043e\u0431\u0440\u0435\u0437\u043a\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 (post-pruning). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u0445\u043d\u0438\u043a\u0430 <a href=\"https:\/\/scikit-learn.org\/stable\/auto_examples\/tree\/plot_cost_complexity_pruning.html\" rel=\"noopener noreferrer nofollow\">minimal cost complexity pruning<\/a>. \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043d\u0435 \u0434\u0430\u0432\u0430\u043b\u0430 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u042d\u0444\u0444\u0435\u043a\u0442 \u0436\u0435 \u0434\u0430\u043b \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0438 \u0434\u0430\u0436\u0435 \u0441\u043a\u043e\u0440\u0435\u0435 \u043d\u0435 \u043e\u0431\u0440\u0435\u0437\u043a\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u0434\u0435\u0440\u0433\u0438\u0432\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0442\u043a\u0438 \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432 \u043c\u043e\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/70a\/bca\/326\/70abca326e2182d19a6e3c66b7264f98.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439\" width=\"963\" height=\"944\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/70a\/bca\/326\/70abca326e2182d19a6e3c66b7264f98.png\"\/><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u043e \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u0430\u0432\u043e\u0439 \u0432\u0435\u0442\u043a\u0435 (\u043b\u0438\u0441\u0442\u044c\u044f \u0441\u0438\u043d\u0435\u0433\u043e \u0446\u0432\u0435\u0442\u0430). \u0422\u0430\u043a\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u043f\u043e\u0447\u0442\u0438 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u0445. \u041d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443 \u043c\u0435\u043d\u044f \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0438 \u0438\u0445 \u0432\u043f\u0435\u0440\u0435\u043c\u0435\u0448\u043a\u0443 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e, \u0447\u0442\u043e \u0432 \u043b\u0438\u0441\u0442\u0435 \u043f\u0440\u0430\u0432\u043e\u0439 \u0432\u0435\u0442\u043a\u0438 \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<p>\u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043c\u043d\u0435 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u0430\u0432\u0443\u044e \u0432\u0435\u0442\u043a\u0443 \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u2014 \u043d\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0435\u0441\u044f \u0434\u0435\u0440\u0435\u0432\u043e. \u0418 \u0447\u0442\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u0443\u0447\u0443 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u0440\u0430\u0432\u044b\u0445 \u0432\u0435\u0442\u043e\u043a \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u0438\u0445 \u0440\u043e\u0441\u0442, \u043f\u0443\u0441\u0442\u044c \u0442\u0430\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u0436\u0435 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043f\u043e\u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0442\u043e\u043a.\u00a0<\/p>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043a\u0443\u0447\u0443, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0432\u0441\u0435 \u0432\u0435\u0442\u043a\u0438, \u0430 \u0442\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u0435\u0442 (\u043f\u043e \u043e\u043f\u044b\u0442\u0443, \u0435\u0433\u043e \u0434\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 80%). \u0418 \u043d\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430, \u0430 \u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u0434\u043b\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u044d\u0442\u0430\u043a\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.\u00a0<\/p>\n<p>\u0418 \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0443\u0447\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0435\u0442\u043e\u043a, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:\u00a0\u0447\u0435\u043c \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0435\u0442\u043e\u043a \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u0435\u043c \u0432\u044b\u0448\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u043a \u0446\u0435\u043b\u0435\u0432\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443.<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e!<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 \u00ab\u043a\u0443\u0447\u0438 \u0432\u0435\u0442\u043e\u043a\u00bb:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9c1\/361\/264\/9c1361264f75af094d529b83b2038c33.png\" alt=\"\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch\" title=\"\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch\" width=\"487\" height=\"383\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9c1\/361\/264\/9c1361264f75af094d529b83b2038c33.png\"\/><\/p>\n<div><figcaption>\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch<\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u043f\u043e\u0441\u043e\u0431 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u0442. \u0435. \u0432 \u043b\u0435\u0432\u043e\u0439 \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0430. \u041e\u043d\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0432\u0435\u0434\u044c \u0441\u0430\u043c\u0438\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u043e\u0431\u0440\u0435\u0437\u043a\u0438 \u043c\u044b \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438. \u041d\u043e \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u043a \u0441\u0442\u044d\u043a\u0438\u043d\u0433 \u0432\u044b\u0445\u043e\u0434\u043e\u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043a\u0430\u043a \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435? <\/p>\n<p>\u041e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0434\u0430!\u00a0\u041f\u0440\u0438\u0447\u0435\u043c,\u00a0\u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Random Forest, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u0432 \u0447\u0435\u043c \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f.<\/p>\n<p>\u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0441\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0440\u0435\u0437\u043a\u0438.<\/p>\n<h2>Random Branch<\/h2>\n<p>\u041a\u043b\u0430\u0441\u0441 RandomBranchClassifier \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a RandomForestClassifier.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 RandomBranchClassifier<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re import numpy as np import pandas as pd from sklearn import tree from sklearn.base import BaseEstimator, ClassifierMixin from sklearn.metrics import precision_score from sklearn.model_selection import train_test_split from rich.progress import track  class RandomBranchClassifier(BaseEstimator, ClassifierMixin):     def __init__(self, n_estimators = 4000, max_features = 14, dataset_size = None,                  pruning_type = 'max_right', leaf_threshold = 0.8,                  include_left = False, min_positive = 0,                  tree_apply = 'cv', cv_size = 0.5, cv_stratify = False, cv_prec_threshold = 0,                  criterion = 'entropy', splitter = 'best', min_samples_leaf = 1, max_depth = None,                  min_samples_split = 2, max_leaf_nodes = None, min_weight_fraction_leaf = 0,                  plot_trees = False, feature_names = None, remove_duplicates = 'n'):                  self.n_estimators = n_estimators         self.max_features = max_features         self.dataset_size = dataset_size                  self.pruning_type = pruning_type          self.leaf_threshold = leaf_threshold                  self.include_left = include_left         self.min_positive = min_positive                  self.tree_apply = tree_apply          self.cv_size = cv_size         self.cv_stratify = cv_stratify         self.cv_prec_threshold = cv_prec_threshold          self.criterion = criterion          self.splitter = splitter          self.min_samples_leaf = min_samples_leaf         self.max_depth = max_depth         self.min_samples_split = min_samples_split         self.max_leaf_nodes = max_leaf_nodes         self.min_weight_fraction_leaf = min_weight_fraction_leaf                  self.plot_trees = plot_trees         self.feature_names = feature_names         self.remove_duplicates = remove_duplicates          self.features = []         self.conditions = []         self.conditions_a = []         self.conditions_b = []          self.tree_children_left = []         self.tree_children_right = []         self.tree_feature = []         self.tree_threshold = []                  self.feature_count = []         self.nbranches = []               def fit(self, X, y):                  if not isinstance(X, pd.DataFrame):             X = pd.DataFrame(X)                      if not isinstance(y, pd.Series):             y = pd.Series(y)                      if self.dataset_size != None:                          if self.dataset_size &lt; 1:                 self.dataset_size = round(len(y)*self.dataset_size)             X = X.iloc[:self.dataset_size,:]             y = y[:self.dataset_size]                  if self.feature_names != None:             self.features = self.feature_names         else:             self.features = X.columns                       self.feature_count = [0] * len(self.features)          for i in track(range(self.n_estimators), description=\"Processing...\"):                           random_features = np.random.choice(len(self.features), size=self.max_features, replace=False)             selected_features = [self.features[idx] for idx in random_features]                          if self.cv_stratify == True:                 x_train, x_cv, y_train, y_cv = train_test_split(                     X[selected_features], y, test_size=self.cv_size, random_state=i, stratify = y)             else:                 x_train, x_cv, y_train, y_cv = train_test_split(                     X[selected_features], y, test_size=self.cv_size, random_state=i)                          clf = tree.DecisionTreeClassifier(criterion=self.criterion, min_samples_leaf=self.min_samples_leaf,                                               max_depth = self.max_depth,                                               min_weight_fraction_leaf = self.min_weight_fraction_leaf,                                               max_leaf_nodes = self.max_leaf_nodes,                                               min_samples_split = self.min_samples_split,                                               splitter = self.splitter)                          clf.fit(x_train, y_train)                          if self.tree_apply == 'cv':                 leave_id = clf.apply(x_cv)                 y_for_metrics = y_cv.to_list()             else:                 leave_id = clf.apply(x_train)                  y_for_metrics = y_train.to_list()                          self.tree_children_left = clf.tree_.children_left             self.tree_children_right = clf.tree_.children_right             self.tree_feature = clf.tree_.feature             self.tree_threshold = clf.tree_.threshold                          paths = {}             for leaf in np.unique(leave_id):                 path_leaf = []                 self.find_path(0, path_leaf, leaf)                 paths[leaf] = np.unique(np.sort(path_leaf))                              rules = {}             for key in paths:                 rules[key] = self.get_rule(paths[key], selected_features)                                          y_pred = clf.predict(x_cv)             cv_prec_score = precision_score(y_cv, y_pred)                                      df_metrics = pd.DataFrame({'leave_id': leave_id, 'y': y_for_metrics})             df_metrics = df_metrics.groupby('leave_id').agg(positive=('y', 'sum'), total=('y', 'count')).reset_index()             df_metrics['precision'] = df_metrics['positive'] \/ df_metrics['total']             df_metrics.loc[df_metrics.positive &lt; self.min_positive,'positive'] = 0             df_metrics['custome_score'] = (df_metrics['precision'] > self.leaf_threshold).astype(int) * df_metrics['positive']                          if self.pruning_type == 'max_right' or self.pruning_type == 'max':                                   if cv_prec_score >= self.cv_prec_threshold and df_metrics.iloc[df_metrics['custome_score'].idxmax(), 4] != 0:                     self.conditions.append(rules[df_metrics.iloc[df_metrics['custome_score'].idxmax(), 0].item()])                                      elif self.pruning_type == 'right' or self.pruning_type == 'all':                                    for j in range(len(rules)):                       leaf_ratio = df_metrics.loc[df_metrics['leave_id'] == list(rules)[j],'precision'].item()                     leaf_positive_count = df_metrics.loc[df_metrics['leave_id'] == list(rules)[j],'positive'].item()                     if leaf_positive_count > self.min_positive and leaf_ratio >= self.leaf_threshold and cv_prec_score >= self.cv_prec_threshold:                         self.conditions.append(rules[list(rules)[j]])              else:                                  print(\"Error: please choose correct pruning type\")                 return None                                                       if self.plot_trees == True:                 x_size = round(clf.tree_.node_count \/ 2)                 plt.figure(figsize=(x_size,12))                  tree.plot_tree(clf, fontsize=7, feature_names=selected_features, filled = True)                 plt.show()                      if self.pruning_type == 'max_right' or self.pruning_type == 'right':                            if self.include_left == True:                 left_conditions = [item for item in self.conditions if \">\" not in item]                 self.conditions = [item for item in self.conditions if \"&lt;\" not in item]                 self.conditions.extend(left_conditions)             else:                 self.conditions = [item for item in self.conditions if \"&lt;\" not in item]                  for string in self.conditions:             self.feature_count = [count + res for count, res in zip(                 self.feature_count, self.count_features_in_conditions(self.features, string))]                           self.conditions_a = list(set(self.conditions))         self.conditions_b = self.remove_duplicates_from_conditions(self.conditions)                  if self.remove_duplicates == 'a':             self.conditions = self.conditions_a                          if self.remove_duplicates == 'b':             self.conditions = self.conditions_b                  self.nbranches = len(self.conditions)         return self          def predict(self, X, threshold = 0.2, remove_duplicates = 'n', exclude = 'use_feature_name'):           y_proba = self.predict_proba(X, remove_duplicates = remove_duplicates, exclude = exclude)         y_pred = np.where(y_proba[:, 1] >= threshold, 1, 0)         return y_pred      def predict_proba(self, X, remove_duplicates = 'n', exclude = 'use_feature_name'):                  if remove_duplicates == 'a':             conditions = self.conditions_a         elif remove_duplicates == 'b':              conditions = self.conditions_b         else:             conditions = self.conditions                  d = 0         predictions = np.zeros((X.shape[0], 2))         df = X         df['count'] = 0         for i in range(len(conditions)):             if (len(conditions[i]) > 0) and (exclude not in conditions[i]):                 d += 1                 df.loc[eval(conditions[i]),'count'] += 1          predictions[:, 1] = df['count'] \/ d         predictions[:, 0] = 1 - predictions[:, 1]                  return predictions          def find_path(self, node_numb, path, x):         path.append(node_numb)         if node_numb == x:             return True         left = False         right = False         if (self.tree_children_left[node_numb] !=-1):             left = self.find_path(self.tree_children_left[node_numb], path, x)         if (self.tree_children_right[node_numb] !=-1):             right = self.find_path(self.tree_children_right[node_numb], path, x)         if left or right :             return True         path.remove(node_numb)         return False          def get_rule(self, path, column_names):         mask = ''         for index, node in enumerate(path):             if index!=len(path)-1:                 if (self.tree_children_left[node] == path[index+1]):                     mask += \"(df['{}']&lt;= {}) \\t \".format(column_names[self.tree_feature[node]], self.tree_threshold[node])                 else:                     mask += \"(df['{}']> {}) \\t \".format(column_names[self.tree_feature[node]], self.tree_threshold[node])         mask = mask.replace(\"\\t\", \"&amp;\", mask.count(\"\\t\") - 1)         mask = mask.replace(\"\\t\", \"\")         return mask          def count_features_in_conditions(self, features, condition):         feature_counts = []          for feature in features:             pattern = r'\\b{}\\b'.format(feature)               matches = re.findall(pattern, condition)               feature_counts.append(len(set(matches)))            return feature_counts          def remove_duplicates_from_conditions(self, lst):         pattern = r\"df\\['(.*?)'\\]\"         extracted_lst = []         duplicates = set()         unique_lst = []                  for item in lst:             match = re.findall(pattern, item)             extracted_str = \" \".join(match)             extracted_lst.append(extracted_str)                          if extracted_str in unique_lst:                 duplicates.add(len(extracted_lst) - 1)             else:                 unique_lst.append(extracted_str)                  filtered_lst = [item for i, item in enumerate(lst) if i not in duplicates]         return filtered_lst<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u2014 \u044d\u0442\u043e <strong>pruning_type<\/strong> (\u0442\u0438\u043f \u043e\u0431\u0440\u0435\u0437\u043a\u0438), <strong>leaf_threshold<\/strong> (\u043f\u043e\u0440\u043e\u0433 \u0434\u043e\u043b\u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043b\u0438\u0441\u0442\u0435 \u0432\u0435\u0442\u043a\u0438) \u0438 <strong>min_positive<\/strong> (\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043b\u0438\u0441\u0442\u0435 \u0432\u0435\u0442\u043a\u0438).<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>pruning_type<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <strong>right<\/strong>, <strong>max_right<\/strong>, <strong>max<\/strong> \u0438\u043b\u0438 <strong>all<\/strong>.<\/p>\n<p><code>pruning_type = 'right'<\/code> \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e, \u0447\u0442\u043e \u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0432\u044b\u0448\u0435. \u0411\u0435\u0440\u0451\u043c \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u044b\u0435 \u0432\u0435\u0442\u043a\u0438 (\u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u043a \u00ab>\u00bb), \u0432 \u043b\u0438\u0441\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u044b\u0448\u0435\u00a0leaf_threshold \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 min_positive.<\/p>\n<p><code>pruning_type = 'max_right'<\/code> \u2014 \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 &#8216;right&#8217;, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0432\u0435\u0442\u043a\u0443 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435: \u0431\u0435\u0440\u0435\u043c \u043f\u0440\u0430\u0432\u0443\u044e \u0432\u0435\u0442\u043a\u0443, \u0435\u0441\u043b\u0438 \u0432 \u0435\u0451 \u043b\u0438\u0441\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043b\u0438\u0441\u0442\u044c\u0435\u0432, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0434\u043e\u043b\u0438 \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.\u00a0\u041f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u0440\u0430\u0432\u0430\u044f \u0432\u0435\u0442\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u043e\u0434\u043e\u0432\u0438\u0442\u043e\u0439 \u043d\u0430 \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441, \u043d\u043e \u0438 \u0441\u0430\u043c\u043e\u0439 \u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0438\u0437 \u0432\u0441\u0435\u0445 \u043f\u043b\u043e\u0434\u043e\u0432\u0438\u0442\u044b\u0445 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435.\u00a0\u042d\u0442\u043e\u0442 \u0442\u0438\u043f \u043e\u0431\u0440\u0435\u0437\u043a\u0438 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0435\u0449\u0451 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435, \u0447\u0435\u043c &#8216;right&#8217;. \u041e\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u0442, \u043f\u0443\u0441\u0442\u044c \u0438 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044e \u0434\u043e\u043b\u0438, \u043d\u043e \u0441\u043b\u0430\u0431\u044b\u0435 \u0432\u0435\u0442\u043a\u0438.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/081\/ec6\/a26\/081ec6a26298b749a8ede0f0d48fceba.jpeg\" alt=\"\u0412\u0435\u0442\u043a\u0430 \u0434\u043b\u044f max_right\" title=\"\u0412\u0435\u0442\u043a\u0430 \u0434\u043b\u044f max_right\" width=\"2560\" height=\"1780\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/081\/ec6\/a26\/081ec6a26298b749a8ede0f0d48fceba.jpeg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u0412\u0435\u0442\u043a\u0430 \u0434\u043b\u044f max_right<\/figcaption><\/div>\n<\/figure>\n<p><code>pruning_type = 'max'<\/code> \u2014 \u0438\u0437 \u0432\u0441\u0435\u0445 \u0432\u0435\u0442\u043e\u043a \u0432 \u0434\u0435\u0440\u0435\u0432\u0435, \u0432 \u043b\u0438\u0441\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u044b\u0448\u0435\u00a0leaf_threshold, \u0431\u0435\u0440\u0451\u043c \u0442\u0443, \u0432 \u043b\u0438\u0441\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 min_positive. \u0422.\u0435. \u044d\u0442\u043e \u043a\u0430\u043a &#8216;max_right&#8217;, \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0435\u0437 &#8216;right&#8217;.<\/p>\n<p><code>pruning_type = 'all'<\/code> \u2014 \u044d\u0442\u043e \u0432\u0441\u0435 \u0432\u0435\u0442\u043a\u0438 \u0434\u0435\u0440\u0435\u0432\u0430, \u0432 \u043b\u0438\u0441\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u044b\u0448\u0435\u00a0leaf_threshold \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 min_positive. \u0415\u0441\u043b\u0438 leaf_threshold = 0 \u0438 min_positive = 0, \u0442\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0435 \u0432\u0435\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432. \u041d\u043e \u0432\u0441\u0435 \u0432\u0435\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0442 Random Branch \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c Random Forest, \u0442\u0430\u043a \u043a\u0430\u043a \u0443 Random Branch \u0438\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f. \u042d\u0442\u043e\u0442 \u0442\u0438\u043f \u043e\u0431\u0440\u0435\u0437\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0min_positive.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f min_positive <strong>\u043d\u0435<\/strong> \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0440\u043e\u0441\u0442 \u0434\u0435\u0440\u0435\u0432\u0430 (min_samples_leaf). \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f min_positive, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0443\u0436\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u0434\u0435\u0440\u0435\u0432\u043e\u043c. \u0418 \u043d\u0435 \u0431\u0435\u0440\u0451\u043c \u0432\u0435\u0442\u043a\u0443, \u0435\u0441\u043b\u0438 \u0432 \u0435\u0451 \u043b\u0438\u0441\u0442\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0447\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u043e min_positive.<\/p>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043f\u043e \u043e\u043f\u044b\u0442\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u0441\u0430\u043c\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 max_right, \u043f\u043e\u0442\u043e\u043c right. \u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b &#8216;max&#8217; \u0438 &#8216;all&#8217; \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b. \u0425\u043e\u0442\u044f \u0432\u0430\u0440\u0438\u0430\u043d\u0442 &#8216;all&#8217; \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c min_positive \u0442\u043e\u0436\u0435 \u043d\u0435\u043f\u043b\u043e\u0445.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 <code>pruning_type = 'max_right',\u00a0leaf_threshold = 0.8, min_positive = 0<\/code>.<\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (\u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443):<\/p>\n<ul>\n<li>\n<p><code>n_estimators [ = 4000]<\/code> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432<\/p>\n<\/li>\n<li>\n<p><code>max_features [ = 14]<\/code> \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c\u043e\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><code>remove_duplicates [ = 'n' ]<\/code> \u2014 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 (\u043f\u0440\u0430\u0432\u0438\u043b, \u0432\u0435\u0442\u043e\u043a) \u0438\u043b\u0438 \u043d\u0435\u0442. <strong>n<\/strong> \u2014 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0442\u044c; <strong>a <\/strong>\u2014 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u0435 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b, \u043a\u043e\u0433\u0434\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u0442\u0430\u043a \u0438 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f; <strong>b<\/strong> \u2014 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442, \u0430 \u0432\u043e\u0442 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438. \u042d\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f\u00a0GridSearchCV. \u041f\u043e \u0444\u0430\u043a\u0442\u0443, \u043c\u043e\u0436\u043d\u043e \u0435\u0433\u043e \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u0442\u044c, \u0430 \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 predict \u0438\u043b\u0438 predict_proba \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0430\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u00a0remove_duplicates<\/p>\n<\/li>\n<li>\n<p><code>dataset_size [ = None]<\/code> \u2014 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0432\u0441\u0442\u0440\u043e\u0438\u043b \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u00a0GridSearchCV. \u041c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043b\u0438\u0431\u043e \u0434\u043e\u043b\u044e \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430, \u043b\u0438\u0431\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p><code>include_left [ = False]<\/code> \u2014 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043b\u0435\u0432\u044b\u0435 \u0432\u0435\u0442\u043a\u0438 \u0438\u043b\u0438 \u043d\u0435\u0442. \u0422\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0431\u0440\u0435\u0437\u043a\u0438 &#8216;right&#8217; \u0438\u043b\u0438 &#8216;max_right&#8217;.\u00a0\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432<\/p>\n<\/li>\n<li>\n<p><code>tree_apply [ = 'cv' ]<\/code> \u2014 \u0432\u0430\u0436\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c &#8216;cv&#8217; \u0438\u043b\u0438 &#8216;train&#8217;. \u0415\u0441\u043b\u0438 &#8216;train&#8217;, \u0442\u043e \u0434\u043e\u043b\u044e \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043b\u0438\u0441\u0442\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 \u0442\u0435\u0445 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430. \u0410 \u0435\u0441\u043b\u0438 &#8216;cv&#8217;, \u0442\u043e \u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u0434\u043b\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p><code>cv_size [ = 0.5 ]<\/code> \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u044f \u043e\u0442 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><code>cv_stratify [ = False ]<\/code> \u2014 \u0435\u0441\u043b\u0438\u00a0cv_stratify = True, \u0442\u043e \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u0438 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435<\/p>\n<\/li>\n<li>\n<p><code>cv_prec_threshold [ = 0 ]<\/code> \u2014 \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u0431\u043e\u0440\u0430 \u0432\u0435\u0442\u043e\u043a. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u0432\u0441\u0435\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0440\u043e\u0433 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0440\u0435\u0432\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u0440\u0430\u0442\u044c \u0432\u0435\u0442\u043a\u0438. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043b\u0438\u0431\u043e 0, \u043b\u0438\u0431\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0432\u043b\u0438\u044f\u043b, \u043d\u043e \u043f\u043e\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0438\u043b. \u0424\u0438\u043b\u044c\u0442\u0440 \u0441\u043b\u0430\u0431\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432<\/p>\n<\/li>\n<li>\n<p><code>plot_trees [ = False ]<\/code> \u2014 \u0435\u0441\u043b\u0438 True, \u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0441 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0410 \u044d\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435, \u043a\u0430\u043a \u0432\u00a0DecisionTreeClassifier (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c criterion, \u0435\u0433\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u043b \u043d\u0430 entropy):<\/p>\n<ul>\n<li>\n<p><code>criterion [ = 'entropy' ]<\/code><\/p>\n<\/li>\n<li>\n<p><code>splitter [ = 'best' ]<\/code><\/p>\n<\/li>\n<li>\n<p><code>min_samples_leaf [ = 1 ]<\/code><\/p>\n<\/li>\n<li>\n<p><code>max_depth [ = None ]<\/code><\/p>\n<\/li>\n<li>\n<p><code>min_samples_split [ = 2 ]<\/code><\/p>\n<\/li>\n<li>\n<p><code>max_leaf_nodes [ = None ]<\/code><\/p>\n<\/li>\n<li>\n<p><code>min_weight_fraction_leaf [ = 0 ]<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u00a0<strong>splitter<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0437\u043b\u0435. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c best \u0438\u043b\u0438 random.<\/p>\n<p>\u0423 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 predict \u0438 predict_proba \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p><code>remove_duplicates [ = 'n' ]<\/code> \u2014 \u043e\u043f\u0438\u0441\u0430\u043b \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0432\u0435\u0442\u043a\u0438 \u043a\u0430\u043a \u0441 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430\u043c\u0438, \u0442\u0430\u043a \u0438 \u0431\u0435\u0437<\/p>\n<\/li>\n<li>\n<p><code>exclude<\/code> \u2014 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u0435\u0442\u043a\u0438 \u0441 \u043d\u0438\u043c \u043f\u0440\u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0438<\/p>\n<\/li>\n<li>\n<p><code>threshold [ = 0.2 ]<\/code> \u2014 \u0443 \u043c\u0435\u0442\u043e\u0434\u0430 predict \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u043e\u0440\u043e\u0433\u0430 \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u043a \u043d\u0443\u0436\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f (\u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u0432\u0435\u0442\u043a\u0438) \u0431\u0443\u0434\u0443\u0442 \u0432 <strong>self.conditions<\/strong> (\u0430 \u0432 <strong>self.nbranches<\/strong> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0442\u043e\u043a), \u0431\u0435\u0437 \u043f\u043e\u043b\u043d\u044b\u0445 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u2014 \u0432\u00a0<strong>self.conditions_a<\/strong>, \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u2014 \u0432 <strong>self.conditions_b<\/strong>.<\/p>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u0421\u0440\u0435\u0434\u0438 \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c m (max_features) \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0440\u043e\u0438\u043c \u0434\u0435\u0440\u0435\u0432\u043e, \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438\u0449\u0435\u043c \u0441\u0440\u0435\u0434\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u043b\u0438\u0431\u043e \u043a \u0442\u0435\u043c \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u043b\u043e\u0441\u044c, \u043b\u0438\u0431\u043e \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 find_path \u0438 get_rule, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f (\u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u0432\u0435\u0442\u043a\u0438) \u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c (rules). \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0438\u0445 \u0434\u043e\u043b\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f (\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 df_metrics).<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0442 \u0432\u0441\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c (\u0432 self.conditions).\u00a0<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u0432\u0441\u0451 n \u0440\u0430\u0437 (n_estimators ). \u0414\u0430, n_estimators \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a random_state \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f\u00a0train_test_split.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u00a0count_features_in_conditions, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0438\u0441\u044c \u0432 \u043e\u0442\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445. \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 self.feature_count. \u041f\u043e\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 find_path \u0438 get_rule \u0432\u0437\u044f\u043b \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <strong>vlemaistre<\/strong> (\u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0435\u043c\u0443!) \u043d\u0430 <a href=\"https:\/\/stackoverflow.com\/questions\/56334210\/how-to-extract-sklearn-decision-tree-rules-to-pandas-boolean-conditions\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u0439\u0442\u0435 Stack Overflow<\/a>. \u0410 <a href=\"https:\/\/scikit-learn.org\/stable\/auto_examples\/tree\/plot_unveil_tree_structure.html\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e<\/a> \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0435\u0440\u0435\u0432\u0430. <\/p>\n<h2>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c!<\/h2>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 \u0441 Kaggle \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c Random Branch \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438 Random Forest.\u00a0\u0412 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u043b\u0441\u044f.<\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 <a href=\"https:\/\/www.kaggle.com\/datasets\/blastchar\/telco-customer-churn\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043e\u0442\u0442\u043e\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432<\/a> (\u0434\u043b\u044f \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0443\u0436\u043d\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f). <\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f Random Forest \u0432\u0437\u044f\u043b \u0438\u0437 <a href=\"https:\/\/www.kaggle.com\/code\/bhartiprasad17\/customer-churn-prediction\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/a>:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from sklearn.preprocessing import LabelEncoder from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import precision_recall_curve from sklearn.model_selection import GridSearchCV import matplotlib.pyplot as plt   df = pd.read_csv(\"C:\/WA_Fn-UseC_-Telco-Customer-Churn.csv\")   def object_to_int(dataframe_series):     if dataframe_series.dtype == 'object':         dataframe_series = LabelEncoder().fit_transform(dataframe_series)     return dataframe_series   df = df.apply(lambda x: object_to_int(x))  x = df.drop(columns=['Churn']) y = df['Churn'].values  x_train, x_test, y_train, y_test = train_test_split(     x, y, test_size=0.3, random_state=40, stratify=y)  # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 Random Forest  model = RandomForestClassifier(n_estimators=1000, oob_score=True, n_jobs=-1,                                random_state=50,                                max_leaf_nodes=30) model.fit(x_train, y_train)  y_pred_proba = model.predict_proba(x_test)[:, 1]  precision_rf, recall_rf, thresholds_rf = precision_recall_curve(     y_test, y_pred_proba)  fig, ax = plt.subplots() ax.plot(recall_rf, precision_rf, color='purple') ax.set_title('Precision-Recall Curve') ax.set_ylabel('Precision') ax.set_xlabel('Recall') plt.show()<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5f2\/f34\/c89\/5f2f34c89ee028185b9dbfa3f187d3b8.png\" alt=\" \u041a\u0440\u0438\u0432\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest\" title=\" \u041a\u0440\u0438\u0432\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest\" width=\"567\" height=\"453\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5f2\/f34\/c89\/5f2f34c89ee028185b9dbfa3f187d3b8.png\"\/><\/p>\n<div><figcaption> \u041a\u0440\u0438\u0432\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 Random Branch. \u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u00ab-\u00bb, \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u043d\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0442\u043e\u0436\u0435 \u043c\u043e\u0433 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u043f\u0440\u0430\u0432\u0443\u044e \u0432\u0435\u0442\u043a\u0443.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0add_rev:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def add_rev(df):     if not isinstance(df, pd.DataFrame):         df = pd.DataFrame(df)         df = df.add_prefix('ft_')      new_df = df.apply(lambda x: x * -1)     new_df = new_df.add_prefix('rev_')     return pd.concat([df, new_df], axis=1)   x_train_rev = add_rev(x_train) x_test_rev = add_rev(x_test)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043e\u0431\u0443\u0447\u0438\u043c Random Branch \u0441 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0442\u043e\u043b\u044c\u043a\u043e n_estimators \u043d\u0430 10 000. \u0410 \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c include_left = True, \u0442\u043e\u00a0n_estimators \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 5 000.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">model = RandomBranchClassifier(n_estimators=10000, max_leaf_nodes=30)  model.fit(x_train_rev, pd.Series(y_train))  print(\"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439: \", model.nbranches) print(\"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0431\u0435\u0437 \u043f\u043e\u043b\u043d\u044b\u0445 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432: \", len(model.conditions_a)) print(\"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432: \", len(model.conditions_b))<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430, \u0433\u0434\u0435 \u043f\u0440\u0430\u0432\u0430\u044f \u0432\u0435\u0442\u043a\u0430 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0432\u0441\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 max_right \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c leaf_threshold = 0.8. \u0414\u043e\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435 80%, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043b\u0438\u0441\u0442\u044c\u0435\u0432 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0434\u043e\u043b\u0435\u0439 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/895\/22c\/a2a\/89522ca2a878637adc9d879beef59aba.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439\" width=\"1570\" height=\"944\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/895\/22c\/a2a\/89522ca2a878637adc9d879beef59aba.png\"\/><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0436\u0435\u043c \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (\u0432\u0430\u0440\u0438\u0430\u043d\u0442 b):<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">y_pred_proba = model.predict_proba(x_test_rev, remove_duplicates='b')[:, 1]  precision_rb, recall_rb, thresholds_rb = precision_recall_curve(     y_test, y_pred_proba)  fig, ax = plt.subplots() ax.plot(recall_rf, precision_rf, color='green', label=\"Random Forest\") ax.plot(recall_rb, precision_rb, color='purple', label=\"Random Branch\") ax.legend(loc=\"upper right\") ax.set_title('Precision-Recall Curve') ax.set_ylabel('Precision') ax.set_xlabel('Recall') plt.show()<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0b7\/224\/8c6\/0b72248c6a77a41b1481ba1309e86d2b.png\" alt=\"\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch\" title=\"\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch\" width=\"567\" height=\"453\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0b7\/224\/8c6\/0b72248c6a77a41b1481ba1309e86d2b.png\"\/><\/p>\n<div><figcaption>\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u0440\u0438 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0441\u043b\u0430 \u043f\u043e\u043b\u043d\u043e\u0442\u0430. \u041d\u0430 10 000 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043c\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u043b\u0438 \u0432\u0441\u0435\u0433\u043e 263 \u0432\u0435\u0442\u043a\u0438, \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 228, \u0430 \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (\u0432\u0430\u0440\u0438\u0430\u043d\u0442 b) \u0432\u0441\u0435\u0433\u043e 140. \u0412 \u044d\u0442\u043e\u043c \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u0444\u0438\u0448\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u0430, \u0432\u0441\u0435\u0433\u043e 140 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043e 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from IPython.display import display_html   feature_frequency = pd.DataFrame() feature_frequency['feature'] = model.features feature_frequency['counts'] = model.feature_count feature_frequency['counts'] = feature_frequency['counts'] \/ model.nbranches  df_rev = feature_frequency[feature_frequency['feature'].str.startswith('rev_')] df_not_rev = feature_frequency[~feature_frequency['feature'].str.startswith('rev_')]  df1_styler = df_not_rev.style.bar(     subset=['counts'],     align='mid',     color=['coral', 'yellowgreen'],     vmin=feature_frequency['counts'].min(),     vmax=feature_frequency['counts'].max()     ).set_table_attributes(\"style='display:inline'\").set_caption('Direct')  df2_styler = df_rev.style.bar(     subset=['counts'],     align='mid',     color=['coral', 'yellowgreen'],     vmin=feature_frequency['counts'].min(),     vmax=feature_frequency['counts'].max()     ).set_table_attributes(\"style='display:inline'\").set_caption('Reverse')   display_html(df1_styler._repr_html_()+df2_styler._repr_html_(), raw=True)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u043b\u0435\u0432\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435, \u0441\u043f\u0440\u0430\u0432\u0430 \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u00ab-\u00bb:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0bf\/34a\/5e5\/0bf34a5e57bf6b566660826d679d5cde.png\" width=\"477\" height=\"498\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0bf\/34a\/5e5\/0bf34a5e57bf6b566660826d679d5cde.png\"\/><\/figure>\n<p>\u0410 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\u00a0GridSearchCV. \u041a\u0430\u043a \u043c\u0435\u0442\u0440\u0438\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0442\u0443 \u043f\u0440\u0438 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">model_empty = RandomBranchClassifier()  params = {'n_estimators': [10000],\\           'tree_apply': ['cv'],\\           'cv_size': [0.3,0.5],\\           'pruning_type': ['max_right'],\\           'cv_stratify': [True],\\           'max_leaf_nodes': [30],\\           'leaf_threshold': [0.8],\\           'splitter': ['best'],\\           'remove_duplicates': ['b']}  def recall_prec100_score(model, X, y):     y_proba = model.predict_proba(X)     precision, recall, thresholds = precision_recall_curve(y, y_proba[:, 1])     index = next((idx for idx, val in enumerate(precision) if val == 1), None)     r_100 = recall[index]     return r_100  scoring = {\"recall_100\": recall_prec100_score}  gs = GridSearchCV(model_empty, params, cv = 5, scoring=scoring, verbose = 3, refit=\"recall_100\", n_jobs=-1)  gs.fit(x_train_rev, y_train)  gs.best_params_<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u0440\u0430\u0437\u0443 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u043e\u043f \u043f\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">cvres = gs.cv_results_ sorted_indices = np.argsort(cvres['mean_test_recall_100'])[::-1]    for idx in sorted_indices:     score = cvres['mean_test_recall_100'][idx]     params = cvres['params'][idx]     print(round(score, 3), params)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c?<\/p>\n<ol>\n<li>\n<p>&#8216;pruning_type&#8217;: [&#8216;right&#8217;, &#8216;max_right&#8217;,&#8217;max&#8217;,&#8217;all&#8217;]<\/p>\n<\/li>\n<li>\n<p> &#8216;tree_apply&#8217;: [&#8216;train&#8217;,&#8217;cv&#8217;]<\/p>\n<\/li>\n<li>\n<p>&#8216;cv_size&#8217;: [0.1,0.3,0.5]<\/p>\n<\/li>\n<li>\n<p>&#8216;leaf_threshold&#8217;: [0.7,0.8,0.9]<\/p>\n<\/li>\n<li>\n<p>&#8216;splitter&#8217;: [&#8216;random&#8217;,&#8217;best&#8217;]<\/p>\n<\/li>\n<li>\n<p>&#8216;remove_duplicates&#8217;: [&#8216;n&#8217;,&#8217;a&#8217;,&#8217;b&#8217;]<\/p>\n<\/li>\n<li>\n<p>&#8216;max_features&#8217;<\/p>\n<\/li>\n<li>\n<p>&#8216;min_positives&#8217;<\/p>\n<\/li>\n<li>\n<p>&#8216;cv_prec_threshold&#8217;: [0,0.1,0.2&#8230;]<\/p>\n<\/li>\n<li>\n<p>&#8216;cv_stratify&#8217;: [True,False]<\/p>\n<\/li>\n<li>\n<p>&#8216;n_estimators&#8217;<\/p>\n<\/li>\n<\/ol>\n<p>\u0424\u0430\u0439\u043b \u0441 \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c <a href=\"https:\/\/github.com\/iwtkl\/random_branch\/tree\/main\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b, \u2014 \u044d\u0442\u043e <a href=\"https:\/\/www.kaggle.com\/datasets\/data855\/heart-disease\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0434\u0435\u0447\u043d\u044b\u0445 \u0437\u0430\u0431\u043e\u043b\u0435\u0432\u0430\u043d\u0438\u0439<\/a>. \u0411\u0430\u0437\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u0437\u044f\u043b <a href=\"https:\/\/www.kaggle.com\/code\/caesarmario\/listen-to-your-heart-a-disease-prediction\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e<\/a>. <\/p>\n<p>\u041a\u043e\u0434 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0443\u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443, \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, Random Branch \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438: <code>n_estimators = 4000, tree_apply = 'cv', pruning_type = 'max_right', cv_stratify = True, leaf_threshold = 0.8<\/code>. \u041f\u043e \u0441\u0443\u0442\u0438, \u0442\u043e\u0436\u0435 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0435. \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (\u0432\u0430\u0440\u0438\u0430\u043d\u0442 b). \u041d\u0430 4 000 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c 126 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 b. \u041f\u043e\u0447\u0442\u0438 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043e\u0442\u0442\u043e\u043a\u0430 \u043d\u0430 10 000 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/df8\/2fd\/821\/df82fd821f3a9f8618616e36a1dd9180.png\" alt=\"\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch\" title=\"\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch\" width=\"688\" height=\"505\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/df8\/2fd\/821\/df82fd821f3a9f8618616e36a1dd9180.png\"\/><\/p>\n<div><figcaption>\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch<\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u043d\u043e\u0432\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u043f\u043e\u043b\u043d\u043e\u0442\u0430 \u043f\u0440\u0438 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>Random Branch \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 (\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u043a \u0441\u0442\u044d\u043a\u0438\u043d\u0433), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0432\u044f\u0437\u044c: \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 (\u0438\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043a\u043b\u0430\u0441\u0441\u0430.\u00a0\u0411\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u043a, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0441\u043e 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e. \u0421\u043e\u0447\u0435\u0442\u0430\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, \u043c\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0438\u043b\u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041d\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043a\u0440\u0430\u044f\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u0442\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u043e 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e. \u0418, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430, \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u0431\u044f \u043e\u043f\u0440\u0430\u0432\u0434\u044b\u0432\u0430\u0435\u0442.<\/p>\n<p>\u041c\u043d\u0435 \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0441\u043d\u044f\u0442\u0438\u0435 \u043f\u0435\u043d\u043a\u0438.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/4db\/9f2\/8d8\/4db9f28d8c446709bb8e650ed52a6a3d.jpg\" width=\"1024\" height=\"768\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4db\/9f2\/8d8\/4db9f28d8c446709bb8e650ed52a6a3d.jpg\" data-blurred=\"true\"\/><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/800489\/\"> https:\/\/habr.com\/ru\/articles\/800489\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0411\u044b\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430: \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u2014 \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0438\u043b\u0438 \u043d\u0435\u0442. \u0418 \u043a\u0430\u043a \u0431\u044b \u044f \u043a \u044d\u0442\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043d\u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u043b\u0441\u044f, \u0441 \u043a\u0430\u043a\u043e\u0433\u043e \u0440\u0430\u043a\u0443\u0440\u0441\u0430 \u043d\u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u043b, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0443\u0432\u044b, \u043d\u0435 \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u044f\u043b. \u0414\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b\u043e \u043c\u0430\u043b\u043e, \u0430 \u0442\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e, \u043e\u0431\u043b\u0430\u0434\u0430\u043b\u043e \u0441\u043b\u0430\u0431\u043e\u0439 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u043b\u043e\u0439. \u0425\u043e\u0442\u044f \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0418 \u0432\u043e\u0442, \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043c\u0435\u043d\u044f \u043e\u0441\u0435\u043d\u0438\u043b\u043e \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e-\u043a\u0430 \u044f \u043e\u0431\u0440\u0435\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 Random Forest, \u0434\u043e \u043e\u0434\u043d\u043e\u0439, \u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0432\u0435\u0442\u043a\u0438. \u0418 \u2014 \u043e \u0447\u0443\u0434\u043e! \u2014 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u043a\u0430\u043a \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c (precision), \u0442\u0430\u043a \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u0430 (recall).\u00a0\u0418 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0442\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043b \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445. \u0418 \u0432\u0435\u0437\u0434\u0435 \u043f\u0440\u0438 100% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0432\u044b\u0440\u043e\u0441\u0442\u0430\u043b\u0430 \u043f\u043e\u043b\u043d\u043e\u0442\u0430. \u0427\u0442\u043e \u0436\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u043b?<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>\u0418\u0434\u0435\u044f<\/h2>\n<p>\u041e\u0431\u0440\u0435\u0437\u043a\u0430 \u0438\u043b\u0438 \u0441\u0442\u0440\u0438\u0436\u043a\u0430 (pruning) \u0434\u0435\u0440\u0435\u0432\u0430 \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u043e\u0440\u044c\u0431\u044b \u0441 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c. \u041e\u0431\u044b\u0447\u043d\u043e \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0440\u043e\u0441\u0442\u0430 (\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u0430, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043b\u0438\u0441\u0442\u0435 \u0438 \u0442. \u0434.).\u00a0\u042d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0435\u0437\u043a\u0430 (pre-pruning), \u0430 \u043f\u043e \u0441\u0443\u0442\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u043e\u0441\u0442\u0430.<\/p>\n<p>\u041d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u0438 _\u0432_\u0441\u0430\u043c\u043e\u043c_\u0434\u0435\u043b\u0435\u0448\u043d\u0430\u044f_ \u043e\u0431\u0440\u0435\u0437\u043a\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 (post-pruning). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u0445\u043d\u0438\u043a\u0430 <a href=\"https:\/\/scikit-learn.org\/stable\/auto_examples\/tree\/plot_cost_complexity_pruning.html\" rel=\"noopener noreferrer nofollow\">minimal cost complexity pruning<\/a>. \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043d\u0435 \u0434\u0430\u0432\u0430\u043b\u0430 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u042d\u0444\u0444\u0435\u043a\u0442 \u0436\u0435 \u0434\u0430\u043b \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0438 \u0434\u0430\u0436\u0435 \u0441\u043a\u043e\u0440\u0435\u0435 \u043d\u0435 \u043e\u0431\u0440\u0435\u0437\u043a\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u0434\u0435\u0440\u0433\u0438\u0432\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0442\u043a\u0438 \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432 \u043c\u043e\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u043e \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u0430\u0432\u043e\u0439 \u0432\u0435\u0442\u043a\u0435 (\u043b\u0438\u0441\u0442\u044c\u044f \u0441\u0438\u043d\u0435\u0433\u043e \u0446\u0432\u0435\u0442\u0430). \u0422\u0430\u043a\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u043f\u043e\u0447\u0442\u0438 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u0445. \u041d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443 \u043c\u0435\u043d\u044f \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0438 \u0438\u0445 \u0432\u043f\u0435\u0440\u0435\u043c\u0435\u0448\u043a\u0443 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e, \u0447\u0442\u043e \u0432 \u043b\u0438\u0441\u0442\u0435 \u043f\u0440\u0430\u0432\u043e\u0439 \u0432\u0435\u0442\u043a\u0438 \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<p>\u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043c\u043d\u0435 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u0430\u0432\u0443\u044e \u0432\u0435\u0442\u043a\u0443 \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u2014 \u043d\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0435\u0441\u044f \u0434\u0435\u0440\u0435\u0432\u043e. \u0418 \u0447\u0442\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u0443\u0447\u0443 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u0440\u0430\u0432\u044b\u0445 \u0432\u0435\u0442\u043e\u043a \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u0438\u0445 \u0440\u043e\u0441\u0442, \u043f\u0443\u0441\u0442\u044c \u0442\u0430\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u0436\u0435 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043f\u043e\u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0442\u043e\u043a.\u00a0<\/p>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043a\u0443\u0447\u0443, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0432\u0441\u0435 \u0432\u0435\u0442\u043a\u0438, \u0430 \u0442\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u0435\u0442 (\u043f\u043e \u043e\u043f\u044b\u0442\u0443, \u0435\u0433\u043e \u0434\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 80%). \u0418 \u043d\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430, \u0430 \u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u0434\u043b\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u044d\u0442\u0430\u043a\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.\u00a0<\/p>\n<p>\u0418 \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0443\u0447\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0435\u0442\u043e\u043a, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:\u00a0\u0447\u0435\u043c \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0435\u0442\u043e\u043a \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u0435\u043c \u0432\u044b\u0448\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u043a \u0446\u0435\u043b\u0435\u0432\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443.<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e!<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 \u00ab\u043a\u0443\u0447\u0438 \u0432\u0435\u0442\u043e\u043a\u00bb:<\/p>\n<figure class=\"\">\n<div><figcaption>\u041a\u0440\u0438\u0432\u044b\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0434\u043b\u044f Random Forest \u0438 Random Branch<\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u043f\u043e\u0441\u043e\u0431 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u0442. \u0435. \u0432 \u043b\u0435\u0432\u043e\u0439 \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0430. \u041e\u043d\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0432\u0435\u0434\u044c \u0441\u0430\u043c\u0438\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u043e\u0431\u0440\u0435\u0437\u043a\u0438 \u043c\u044b \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438. \u041d\u043e \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u043a \u0441\u0442\u044d\u043a\u0438\u043d\u0433 \u0432\u044b\u0445\u043e\u0434\u043e\u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043a\u0430\u043a \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435? <\/p>\n<p>\u041e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0434\u0430!\u00a0\u041f\u0440\u0438\u0447\u0435\u043c,\u00a0\u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Random Forest, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u0432 \u0447\u0435\u043c \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f.<\/p>\n<p>\u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0441\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0440\u0435\u0437\u043a\u0438.<\/p>\n<h2>Random Branch<\/h2>\n<p>\u041a\u043b\u0430\u0441\u0441 RandomBranchClassifier \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a RandomForestClassifier.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 RandomBranchClassifier<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re import numpy as np import pandas as pd from sklearn import tree from sklearn.base import BaseEstimator, ClassifierMixin from sklearn.metrics import precision_score from sklearn.model_selection import train_test_split from rich.progress import track  class RandomBranchClassifier(BaseEstimator, ClassifierMixin):     def __init__(self, n_estimators = 4000, max_features = 14, dataset_size = None,                  pruning_type = 'max_right', leaf_threshold = 0.8,                  include_left = False, min_positive = 0,                  tree_apply = 'cv', cv_size = 0.5, cv_stratify = False, cv_prec_threshold = 0,                  criterion = 'entropy', splitter = 'best', min_samples_leaf = 1, max_depth = None,                  min_samples_split = 2, max_leaf_nodes = None, min_weight_fraction_leaf = 0,                  plot_trees = False, feature_names = None, remove_duplicates = 'n'):                  self.n_estimators = n_estimators         self.max_features = max_features         self.dataset_size = dataset_size                  self.pruning_type = pruning_type          self.leaf_threshold = leaf_threshold                  self.include_left = include_left         self.min_positive = min_positive                  self.tree_apply = tree_apply          self.cv_size = cv_size         self.cv_stratify = cv_stratify         self.cv_prec_threshold = cv_prec_threshold          self.criterion = criterion          self.splitter = splitter          self.min_samples_leaf = min_samples_leaf         self.max_depth = max_depth         self.min_samples_split = min_samples_split         self.max_leaf_nodes = max_leaf_nodes         self.min_weight_fraction_leaf = min_weight_fraction_leaf                  self.plot_trees = plot_trees         self.feature_names = feature_names         self.remove_duplicates = remove_duplicates          self.features = []         self.conditions = []         self.conditions_a = []         self.conditions_b = []          self.tree_children_left = []         self.tree_children_right = []         self.tree_feature = []         self.tree_threshold = []                  self.feature_count = []         self.nbranches = []               def fit(self, X, y):                  if not isinstance(X, pd.DataFrame):             X = pd.DataFrame(X)                      if not isinstance(y, pd.Series):             y = pd.Series(y)                      if self.dataset_size != None:                          if self.dataset_size &lt; 1:                 self.dataset_size = round(len(y)*self.dataset_size)             X = X.iloc[:self.dataset_size,:]             y = y[:self.dataset_size]                  if self.feature_names != None:             self.features = self.feature_names         else:             self.features = X.columns                       self.feature_count = [0] * len(self.features)          for i in track(range(self.n_estimators), description=\"Processing...\"):                           random_features = np.random.choice(len(self.features), size=self.max_features, replace=False)             selected_features = [self.features[idx] for idx in random_features]                          if self.cv_stratify == True:                 x_train, x_cv, y_train, y_cv = train_test_split(                     X[selected_features], y, test_size=self.cv_size, random_state=i, stratify = y)             else:                 x_train, x_cv, y_train, y_cv = train_test_split(                     X[selected_features], y, test_size=self.cv_size, random_state=i)                          clf = tree.DecisionTreeClassifier(criterion=self.criterion, min_samples_leaf=self.min_samples_leaf,                                               max_depth = self.max_depth,                                               min_weight_fraction_leaf = self.min_weight_fraction_leaf,                                               max_leaf_nodes = self.max_leaf_nodes,                                               min_samples_split = self.min_samples_split,                                               splitter = self.splitter)                          clf.fit(x_train, y_train)                          if self.tree_apply == 'cv':                 leave_id = clf.apply(x_cv)                 y_for_metrics = y_cv.to_list()             else:                 leave_id = clf.apply(x_train)                  y_for_metrics = y_train.to_list()                          self.tree_children_left = clf.tree_.children_left             self.tree_children_right = clf.tree_.children_right             self.tree_feature = clf.tree_.feature             self.tree_threshold = clf.tree_.threshold                          paths = {}             for leaf in np.unique(leave_id):                 path_leaf = []                 self.find_path(0, path_leaf, leaf)                 paths[leaf] = np.unique(np.sort(path_leaf))                              rules = {}             for key in paths:                 rules[key] = self.get_rule(paths[key], selected_features)                                          y_pred = clf.predict(x_cv)             cv_prec_score = precision_score(y_cv, y_pred)                                      df_metrics = pd.DataFrame({'leave_id': leave_id, 'y': y_for_metrics})             df_metrics = df_metrics.groupby('leave_id').agg(positive=('y', 'sum'), total=('y', 'count')).reset_index()             df_metrics['precision'] = df_metrics['positive'] \/ df_metrics['total']             df_metrics.loc[df_metrics.positive &lt; self.min_positive,'positive'] = 0             df_metrics['custome_score'] = (df_metrics['precision'] > self.leaf_threshold).astype(int) * df_metrics['positive']                          if self.pruning_type == 'max_right' or self.pruning_type == 'max':                                   if cv_prec_score >= self.cv_prec_threshold and df_metrics.iloc[df_metrics['custome_score'].idxmax(), 4] != 0:                     self.conditions.append(rules[df_metrics.iloc[df_metrics['custome_score'].idxmax(), 0].item()])                                      elif self.pruning_type == 'right' or self.pruning_type == 'all':                                    for j in range(len(rules)):                       leaf_ratio = df_metrics.loc[df_metrics['leave_id'] == list(rules)[j],'precision'].item()                     leaf_positive_count = df_metrics.loc[df_metrics['leave_id'] == list(rules)[j],'positive'].item()                     if leaf_positive_count > self.min_positive and leaf_ratio >= self.leaf_threshold and cv_prec_score >= self.cv_prec_threshold:                         self.conditions.append(rules[list(rules)[j]])              else:<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-370893","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=370893"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370893\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}