{"id":344256,"date":"2023-01-20T15:05:10","date_gmt":"2023-01-20T15:05:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=344256"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=344256","title":{"rendered":"<span>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0435\u0441\u043e\u0432 \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 Random Forest \u0438 Decision Tree<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440 \u0421\u0435\u0440\u043e\u0432, \u044f Data Scientist \u0438 \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u043c\u00a0<a href=\"https:\/\/newtechaudit.ru\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 NTA<\/a>.\u00a0 \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443 \u00ab\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u00bb \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u0432 \u0441\u0432\u043e\u0435\u0439 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043c\u043e\u0449\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u2013 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 (Catboost, XBGR), \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0430 \u0441\u0442\u043e\u043b\u044c \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043b\u0435\u0433\u043a\u043e\u043c \u0438 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435, \u043a\u0430\u043a \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u0438\u043b\u0438 \u0436\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u041e\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0431\u043b\u043e\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0438\u0442\u0447\u0443 \u043f\u0440\u043e \u0432\u0435\u043d\u0438\u043a \u0438 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u0438, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u0436\u0435 \u043e\u0434\u043d\u043e \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Decision Tree \u0438 Random Forest \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 sklearn, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. <\/p>\n<p>\u0412 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u0438\u043f\u043e\u0442\u0435\u0437, \u0432 \u043c\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043d\u043e \u0438 \u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0435\u0441\u043e\u0432 &#8212; \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u041e\u0431\u0443\u0447\u0430\u0442\u044c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443 \u043d\u0430 \u0434\u0432\u0443\u0445 \u043d\u0430\u0431\u043e\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u0437\u044f\u0442\u044b\u0445 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 &#8212; Kaggle.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/www.kaggle.com\/datasets\/akshaydattatraykhare\/diabetes-dataset\" rel=\"noopener noreferrer nofollow\"><u>\u0414\u0430\u043d\u043d\u044b\u0435 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0434\u0438\u0430\u0431\u0435\u0442\u0430 \u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430<\/u><\/a>.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.kaggle.com\/datasets\/whenamancodes\/students-performance-in-exams\" rel=\"noopener noreferrer nofollow\"><u>\u0414\u0430\u043d\u043d\u044b\u0435 \u0441 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435<\/u><\/a>.\u00a0<\/p>\n<\/li>\n<\/ul>\n<h3>DecisionTree &#8212; \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h3>\n<pre><code>#  \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0434\u0438\u0430\u0431\u0435\u0442\u0443 import pandas as pd df_clf =  pd.read_csv('..\/input\/pima-indians-diabetes-database\/diabetes.csv') df_clf.head()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/3da\/f6e\/8dd\/3daf6e8dd319b7af811f5cb2b77a601e.jpg\" width=\"684\" height=\"181\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3da\/f6e\/8dd\/3daf6e8dd319b7af811f5cb2b77a601e.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0447\u043d\u0443 \u0441 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u0445, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d 1000 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0433\u0434\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0436\u0435\u043d\u0449\u0438\u043d\u044b \u0438\u0437 \u0438\u043d\u0434\u0435\u0439\u0441\u043a\u043e\u0433\u043e \u043f\u043b\u0435\u043c\u0435\u043d\u0438 \u041f\u0438\u043c\u0430. \u0418\u0437\u0443\u0447\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430:<\/p>\n<ul>\n<li>\n<p>Pregnancies \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>Glucose \u2013 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0430\u0446\u0438\u044f \u0433\u043b\u044e\u043a\u043e\u0437\u044b \u0432 \u043f\u043b\u0430\u0437\u043c\u0435 \u043a\u0440\u043e\u0432\u0438;<\/p>\n<\/li>\n<li>\n<p>BloodPressure \u2013 \u0434\u0438\u0441\u0442\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0440\u043e\u0432\u0438;<\/p>\n<\/li>\n<li>\n<p>SkinThickness \u2013 \u0442\u043e\u043b\u0449\u0438\u043d\u0430 \u043a\u043e\u0436\u0438 \u0442\u0440\u0438\u0446\u0435\u043f\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>Insulin \u2013 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0438\u043d\u0441\u0443\u043b\u0438\u043d\u0430 \u0432 \u043a\u0440\u043e\u0432\u0438;<\/p>\n<\/li>\n<li>\n<p>BMI \u2013 \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0430\u0441\u0441\u044b \u0442\u0435\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>DiabetesPedigreeFunction \u2013 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u0438\u0430\u0431\u0435\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>Age \u2013 \u0432\u043e\u0437\u0440\u0430\u0441\u0442;<\/p>\n<\/li>\n<li>\n<p>Outcome \u2013 \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0433\u0434\u0435 0 \u2013 \u043d\u0435\u0442 \u0434\u0438\u0430\u0431\u0435\u0442\u0430, 1 \u2013 \u0435\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0426\u0435\u043b\u044c, \u043a\u0430\u043a \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f &#171;Outcome&#187;, \u0442\u043e \u0435\u0441\u0442\u044c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e, \u0441 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438 71:29 (\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0440\u0430\u0437\u0431\u0440\u043e\u0441, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0445 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f).<\/p>\n<pre><code>from sklearn.model_selection import train_test_split  target_df_clf = df_clf['Outcome'] feature_df_clf = df_clf.drop(columns=['Outcome'])  X_train_clf, X_test_clf, y_train_clf, y_test_clf = train_test_split(feature_df_clf,                                                                      target_df_clf,                                                                     test_size=0.29,                                                                      random_state=11)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u0447\u043d\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u0438 DecisionTreeClassifier. \u042d\u0442\u043e \u0432\u0441\u0451 \u0442\u043e \u0436\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c GridSearchCV. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<pre><code>from sklearn.model_selection import GridSearchCV from sklearn.metrics import accuracy_score from sklearn.tree import DecisionTreeClassifier  tree_param = [{'criterion': ['entropy', 'gini'], 'max_depth': [i for i in range(1, 20)],               'min_samples_leaf': [i for i in range(1, 25)],                 'max_leaf_nodes': [i for i in range(1, 20)]}]   dtc_model = GridSearchCV(DecisionTreeClassifier(), tree_param, cv=10) dtc_model.fit(X = X_train_clf.values,           y = y_train_clf)  prediction_clf = dtc_model.best_estimator_.predict(X_test_clf) score = accuracy_score(y_test_clf, prediction_clf)  print(f'\u041b\u0443\u0447\u0448\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: {dtc_model.best_estimator_}') print(f'\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: {round(dtc_model.best_score_*100, 2)}') print(f'\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: {round(score*100, 2)}') <\/code><\/pre>\n<p>\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: 74.31<br \/>\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: 72.65<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 &#8212; 72%, \u0447\u0442\u043e \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u0430 \u044d\u0442\u043e \u0432\u0435\u0434\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0434\u0435\u0440\u0435\u0432\u043e. \u041a \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043f\u043e\u0440\u043e\u0433 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 (tresholding), \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u0436\u0438\u0437\u043d\u0438 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043b\u043e\u0436\u043d\u043e\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435. \u041d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u0430\u0436\u043d\u0430 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0430 \u0432\u0435\u0441\u0430 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430.<\/p>\n<pre><code>import matplotlib.pyplot as plt from sklearn.tree import plot_tree  plt.figure(figsize=(15,15)) plot_tree(dtc_model.best_estimator_, filled=True, impurity=True)  <\/code><\/pre>\n<p>\u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7df\/d09\/467\/7dfd094671abfe4aec2d94a57d2b4bf4.png\" width=\"560\" height=\"546\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7df\/d09\/467\/7dfd094671abfe4aec2d94a57d2b4bf4.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430\u0448\u0443 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0432\u044b\u0431\u0440\u0430\u043b\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u042d\u043d\u0442\u0440\u043e\u043f\u0438\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u043c\u044b \u0443\u0433\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u0433\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0430. \u0418 \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0443\u0436\u0430\u0442\u044c \u043a\u0440\u0443\u0433 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u044d\u0442\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 Gini:<\/p>\n<ul>\n<li>\n<p>\u0421 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0414\u0436\u0438\u043d\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0446\u0435\u043b\u0438 \u0434\u0435\u0440\u0435\u0432\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0438 \u043f\u043e\u0440\u043e\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/549\/ecf\/f39\/549ecff39d992c1cd145a1f41faa5f5a.png\" width=\"493\" height=\"126\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/549\/ecf\/f39\/549ecff39d992c1cd145a1f41faa5f5a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u043c\u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 dtreeviz, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0435\u0433\u043e. <\/p>\n<pre><code># %pip install dreeviz from dtreeviz.trees import dtreeviz  image_est = dtreeviz(dtc_model.best_estimator_,                x_data=X_train_clf,                y_data=y_train_clf,                target_name='class',                feature_names=[i for i in X_train_clf.columns],                class_names=['\u041d\u0435 \u0434\u0438\u0430\u0431\u0435\u0442', '\u0414\u0438\u0430\u0431\u0435\u0442'],                title=\"\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0432\u0435\u0441\u043e\u0432 Decision Tree\") image_est.save('dtreeviz.svg')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8d8\/552\/d5a\/8d8552d5a384e7894dd06d7aaeb29fb8.png\" width=\"623\" height=\"415\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8d8\/552\/d5a\/8d8552d5a384e7894dd06d7aaeb29fb8.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043d\u0444\u043e\u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e. \u0412\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0434\u0435\u0440\u0435\u0432\u043e \u043e\u0442\u0431\u0438\u0440\u0430\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0413\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e 3, \u0433\u0434\u0435 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u0432\u0441\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, \u0430 \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430.<\/p>\n<p>\u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441 \u043c\u0435\u0434\u0438\u0446\u0438\u043d\u0441\u043a\u0438\u043c\u0438 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430\u043c\u0438, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u0432\u043e\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0421\u0443\u0434\u044f \u0438\u0437 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432, \u043f\u0440\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0430\u0445\u0430\u0440\u0430 \u0432 \u043a\u0440\u043e\u0432\u0438 &#8212; \u0448\u0430\u043d\u0441 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0434\u0438\u0430\u0431\u0435\u0442\u0430 \u043f\u043e\u0432\u044b\u0448\u0435\u043d, \u0447\u0442\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<h4>DecisionTree \u2013 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/h4>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 (\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u0435. \u041e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c.<\/p>\n<ul>\n<li>\n<p>Gender \u2013 \u043f\u043e\u043b \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>Race\/ethnicity \u2013 \u044d\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430 (\u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0435\u0437\u043b\u0438\u0447\u0435\u043d\u044b);<\/p>\n<\/li>\n<li>\n<p>Parental level of education \u2013 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>Lunch \u2013 \u0442\u0438\u043f \u043f\u0438\u0442\u0430\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>Test preparation score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043a \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u0430\u043c;<\/p>\n<\/li>\n<li>\n<p>Math score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435;<\/p>\n<\/li>\n<li>\n<p>Reading score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e \u0447\u0442\u0435\u043d\u0438\u044e;<\/p>\n<\/li>\n<li>\n<p>Writing score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e \u043f\u0438\u0441\u044c\u043c\u0443.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b\u0431\u0435\u0440\u0443 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a &#8212; \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435 (math score), \u043c\u0435\u0442\u0440\u0438\u043a\u0443 &#8212; \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e LabelEncoder.<\/p>\n<pre><code>df_reg = pd.read_csv('..\/input\/students-performance-in-exams\/StudentsPerformance.csv') df_reg.head()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/574\/263\/30d\/57426330d90dccd1d782ea9959343d8d.png\" width=\"623\" height=\"143\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/574\/263\/30d\/57426330d90dccd1d782ea9959343d8d.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code>from sklearn.preprocessing import LabelEncoder  le = LabelEncoder() df_reg = df_reg.apply(le.fit_transform)  target_df_reg = df_reg['math score'] feature_df_reg = df_reg[[i for i in df_reg.columns if i != 'math score']]  X_train_reg, X_test_reg, y_train_reg, y_test_reg = train_test_split(feature_df_reg,                                                                     target_df_reg,                                                                      test_size=0.29,                                                                      random_state=11)<\/code><\/pre>\n<p>\u041e\u0431\u0443\u0447\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0430\u0432\u0442\u043e-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<pre><code>from sklearn.tree import DecisionTreeRegressor from sklearn.metrics import mean_absolute_error  tree_param = [{'criterion': ['squared_error', 'friedman_mse', 'absolute_error'],                'max_depth': [i for i in range(1, 20)],               'min_samples_leaf': [i for i in range(1, 25)],                'max_leaf_nodes': [i for i in range(2, 20)],               }]  dtr_model = GridSearchCV(DecisionTreeRegressor(), tree_param, cv=5) dtr_model.fit(X = X_train_reg.values,               y = y_train_reg)  prediction_reg = dtr_model.best_estimator_.predict(X_test_reg) score_reg = mean_absolute_error(prediction_reg, y_test_reg)  print(f'\u041b\u0443\u0447\u0448\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: {dtr_model.best_estimator_}') print(f'\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: {round(score_reg, 3)}') <\/code><\/pre>\n<p>\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: 5.722<\/p>\n<pre><code>plt.figure(figsize=(15,15)) plot_tree(dtr_model.best_estimator_, filled=True, impurity=True)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d49\/1d6\/455\/d491d64559520f6b23e28cc7097f833b.png\" width=\"624\" height=\"608\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d49\/1d6\/455\/d491d64559520f6b23e28cc7097f833b.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code>image_est2 = dtreeviz(dtr_model.best_estimator_,                x_data=X_train_reg,                y_data=y_train_reg,                target_name='class',                feature_names=[i for i in X_train_reg.columns],                title=\"\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0432\u0435\u0441\u043e\u0432 \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438\") image_est2.save('dtreeviz2.svg')<\/code><\/pre>\n<p>\u0414\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0433\u043b\u0443\u0431\u0436\u0435, \u0447\u0435\u043c \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0437\u0434\u0435\u0441\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0434\u0435\u0441\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u043b\u0430 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u041f\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0432\u043e\u0434\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0432\u044b\u043a\u0438 \u043f\u0438\u0441\u044c\u043c\u0430 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u044f\u0437\u044c \u0441 \u0433\u0435\u043d\u0434\u0435\u0440\u043e\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u0443\u044e\u0442.<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c*.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043e\u0446\u0435\u043d\u043a\u0438*.<\/p>\n<\/li>\n<\/ul>\n<p>&#171;*&#187; &#8212; \u0438\u043c\u0435\u044e\u0442 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0432\u044b\u0431\u0440\u0430\u043b\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0432 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c, \u0431\u044b\u043b\u0438 \u0431\u044b \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u043d\u0435 \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u044b, \u043d\u043e \u043f\u043e\u0441\u0442\u0440\u0430\u0434\u0430\u043b\u0430 \u0431\u044b \u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u0431\u0440\u043e\u0441 +-6 \u0431\u0430\u043b\u043b\u043e\u0432 \u0438\u0437 100.<\/p>\n<h3>Random Forest<\/h3>\n<p>\u0418 \u043d\u0430\u0441\u0442\u0430\u043b \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u0441\u043e\u0432 \u043d\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430. \u041e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 (\u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 random_seed) \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u0442 \u0438\u0445 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u041e\u0431\u0443\u0447\u0430\u0442\u044c \u0431\u0443\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u044b\u0432\u0435\u0434\u0443 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0441\u0435\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432 \u0435\u0433\u043e \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435.<\/p>\n<pre><code>def GridSearch_CV_RF\u0421(X_train, y_train):     from sklearn.ensemble import RandomForestClassifier as rfc      estimator = RandomForestClassifier()     param_tree = {              \"n_estimators\"      : [i for i in range(1, 21)],             \"max_features\"      : [\"auto\", \"sqrt\", \"log2\"],             \"min_samples_split\" : [2,4,8],             \"bootstrap\": [True, False],             \"max_depth\": [i for i in range(1, 15)],             'criterion': ['entropy', 'gini'],             'n_jobs': [-1]             }      model_rfc = GridSearchCV(estimator, param_tree, n_jobs=-1, cv=5)     model_rfc.fit(X_train, y_train)      return model_rfc.best_score_ , model_rfc.best_estimator_  def RFR(X_train, X_test, y_train, y_test, best_params):     from sklearn.ensemble import RandomForestRegressor          estimator = RandomForestRegressor(n_jobs=-1).set_params(**best_params)     estimator.fit(X_train,y_train)     y_predict = estimator.predict(X_test)          print (\"R2 score:\",r2(y_test,y_predict))          return y_test,y_predict<\/code><\/pre>\n<pre><code>score, model = GridSearch_CV_RF\u0421(X_train_clf, y_train_clf)<\/code><\/pre>\n<pre><code>print(f'\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: {round(score*100, 2)}%')<\/code><\/pre>\n<p>\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: 77.8%<\/p>\n<pre><code>plt.figure(figsize=(10,15)) fn = [i for i in X_train_clf.columns] cn = ['\u0414\u0438\u0430\u0431\u0435\u0442', '\u041d\u0435 \u0434\u0438\u0430\u0431\u0435\u0442'] # \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u043d\u0430\u0431\u043e\u0440 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 fig, axes = plt.subplots(nrows = 1,ncols = 5,figsize = (30,10))  for index in range(0, 5):     # \u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 1 \u0434\u0435\u0440\u0435\u0432\u0430, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0438\u0437 \u043e\u0431\u0449\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438        plot_tree(model.estimators_[index],                    feature_names = fn,                     class_names=cn,                    filled = True,                    ax = axes[index]);      axes[index].set_title('\u0414\u0435\u0440\u0435\u0432\u043e \u2116 ' + str(index+1), fontsize = 11) fig.savefig('rf_5trees.svg')<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c &#8212; \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441 72% \u0434\u043e 77%, \u0432 \u043e\u0431\u0449\u0435\u043c \u0438\u0442\u043e\u0433\u0435, \u0432 \u00ab\u043b\u0435\u0441\u0443\u00bb 12 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0432\u044b\u0432\u0435\u043b 5 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u0447\u0442\u043e\u0431\u044b \u0432 \u043e\u0431\u0449\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443. \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043b\u0443\u0447\u0448\u0435 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u00absvg\u00bb, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u043f\u043e\u0442\u0435\u0440\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430. \u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432\u0438\u0436\u0443, \u0447\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c \u0433\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u043e\u043d\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0434\u043e 7, \u0442\u0430\u043a\u0436\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0441\u0442\u0430\u043b\u0438 \u043d\u0435\u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u044b\u0435 (\u043e\u0434\u043d\u0430 \u0438\u0437 \u0432\u0435\u0442\u043e\u043a \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u0439).<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434<\/h3>\n<p>\u041e\u0431\u043e\u0431\u0449\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0432 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 &#8212; \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0431\u043b\u043e\u043a \u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0445 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u044f \u0435\u0433\u043e, \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u044e\u0442 \u043e\u0431\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#8212; \u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0435\u0441\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u043e \u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0434\u0438\u0430\u0431\u0435\u0442\u0430. \u041f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c, \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u043c \u0441 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\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\/post\/711770\/\"> https:\/\/habr.com\/ru\/post\/711770\/<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440 \u0421\u0435\u0440\u043e\u0432, \u044f Data Scientist \u0438 \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u043c\u00a0<a href=\"https:\/\/newtechaudit.ru\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 NTA<\/a>.\u00a0 \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443 \u00ab\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u00bb \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u0432 \u0441\u0432\u043e\u0435\u0439 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043c\u043e\u0449\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u2013 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 (Catboost, XBGR), \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0430 \u0441\u0442\u043e\u043b\u044c \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043b\u0435\u0433\u043a\u043e\u043c \u0438 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435, \u043a\u0430\u043a \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u0438\u043b\u0438 \u0436\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u041e\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0431\u043b\u043e\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0438\u0442\u0447\u0443 \u043f\u0440\u043e \u0432\u0435\u043d\u0438\u043a \u0438 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u0438, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u0436\u0435 \u043e\u0434\u043d\u043e \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Decision Tree \u0438 Random Forest \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 sklearn, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. <\/p>\n<p>\u0412 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u0438\u043f\u043e\u0442\u0435\u0437, \u0432 \u043c\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043d\u043e \u0438 \u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0435\u0441\u043e\u0432 &#8212; \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u041e\u0431\u0443\u0447\u0430\u0442\u044c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443 \u043d\u0430 \u0434\u0432\u0443\u0445 \u043d\u0430\u0431\u043e\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u0437\u044f\u0442\u044b\u0445 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 &#8212; Kaggle.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/www.kaggle.com\/datasets\/akshaydattatraykhare\/diabetes-dataset\" rel=\"noopener noreferrer nofollow\"><u>\u0414\u0430\u043d\u043d\u044b\u0435 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0434\u0438\u0430\u0431\u0435\u0442\u0430 \u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430<\/u><\/a>.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.kaggle.com\/datasets\/whenamancodes\/students-performance-in-exams\" rel=\"noopener noreferrer nofollow\"><u>\u0414\u0430\u043d\u043d\u044b\u0435 \u0441 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435<\/u><\/a>.\u00a0<\/p>\n<\/li>\n<\/ul>\n<h3>DecisionTree &#8212; \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h3>\n<pre><code>#  \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0434\u0438\u0430\u0431\u0435\u0442\u0443 import pandas as pd df_clf =  pd.read_csv('..\/input\/pima-indians-diabetes-database\/diabetes.csv') df_clf.head()<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0447\u043d\u0443 \u0441 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u0445, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d 1000 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0433\u0434\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0436\u0435\u043d\u0449\u0438\u043d\u044b \u0438\u0437 \u0438\u043d\u0434\u0435\u0439\u0441\u043a\u043e\u0433\u043e \u043f\u043b\u0435\u043c\u0435\u043d\u0438 \u041f\u0438\u043c\u0430. \u0418\u0437\u0443\u0447\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430:<\/p>\n<ul>\n<li>\n<p>Pregnancies \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>Glucose \u2013 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0430\u0446\u0438\u044f \u0433\u043b\u044e\u043a\u043e\u0437\u044b \u0432 \u043f\u043b\u0430\u0437\u043c\u0435 \u043a\u0440\u043e\u0432\u0438;<\/p>\n<\/li>\n<li>\n<p>BloodPressure \u2013 \u0434\u0438\u0441\u0442\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0440\u043e\u0432\u0438;<\/p>\n<\/li>\n<li>\n<p>SkinThickness \u2013 \u0442\u043e\u043b\u0449\u0438\u043d\u0430 \u043a\u043e\u0436\u0438 \u0442\u0440\u0438\u0446\u0435\u043f\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>Insulin \u2013 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0438\u043d\u0441\u0443\u043b\u0438\u043d\u0430 \u0432 \u043a\u0440\u043e\u0432\u0438;<\/p>\n<\/li>\n<li>\n<p>BMI \u2013 \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0430\u0441\u0441\u044b \u0442\u0435\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>DiabetesPedigreeFunction \u2013 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u0438\u0430\u0431\u0435\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>Age \u2013 \u0432\u043e\u0437\u0440\u0430\u0441\u0442;<\/p>\n<\/li>\n<li>\n<p>Outcome \u2013 \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0433\u0434\u0435 0 \u2013 \u043d\u0435\u0442 \u0434\u0438\u0430\u0431\u0435\u0442\u0430, 1 \u2013 \u0435\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0426\u0435\u043b\u044c, \u043a\u0430\u043a \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f &#171;Outcome&#187;, \u0442\u043e \u0435\u0441\u0442\u044c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e, \u0441 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438 71:29 (\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0440\u0430\u0437\u0431\u0440\u043e\u0441, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0445 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f).<\/p>\n<pre><code>from sklearn.model_selection import train_test_split  target_df_clf = df_clf['Outcome'] feature_df_clf = df_clf.drop(columns=['Outcome'])  X_train_clf, X_test_clf, y_train_clf, y_test_clf = train_test_split(feature_df_clf,                                                                      target_df_clf,                                                                     test_size=0.29,                                                                      random_state=11)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u0447\u043d\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u0438 DecisionTreeClassifier. \u042d\u0442\u043e \u0432\u0441\u0451 \u0442\u043e \u0436\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c GridSearchCV. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<pre><code>from sklearn.model_selection import GridSearchCV from sklearn.metrics import accuracy_score from sklearn.tree import DecisionTreeClassifier  tree_param = [{'criterion': ['entropy', 'gini'], 'max_depth': [i for i in range(1, 20)],               'min_samples_leaf': [i for i in range(1, 25)],                 'max_leaf_nodes': [i for i in range(1, 20)]}]   dtc_model = GridSearchCV(DecisionTreeClassifier(), tree_param, cv=10) dtc_model.fit(X = X_train_clf.values,           y = y_train_clf)  prediction_clf = dtc_model.best_estimator_.predict(X_test_clf) score = accuracy_score(y_test_clf, prediction_clf)  print(f'\u041b\u0443\u0447\u0448\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: {dtc_model.best_estimator_}') print(f'\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: {round(dtc_model.best_score_*100, 2)}') print(f'\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: {round(score*100, 2)}') <\/code><\/pre>\n<p>\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: 74.31<br \/>\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: 72.65<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 &#8212; 72%, \u0447\u0442\u043e \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u0430 \u044d\u0442\u043e \u0432\u0435\u0434\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0434\u0435\u0440\u0435\u0432\u043e. \u041a \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043f\u043e\u0440\u043e\u0433 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 (tresholding), \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u0436\u0438\u0437\u043d\u0438 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043b\u043e\u0436\u043d\u043e\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435. \u041d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u0430\u0436\u043d\u0430 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0430 \u0432\u0435\u0441\u0430 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430.<\/p>\n<pre><code>import matplotlib.pyplot as plt from sklearn.tree import plot_tree  plt.figure(figsize=(15,15)) plot_tree(dtc_model.best_estimator_, filled=True, impurity=True)  <\/code><\/pre>\n<p>\u00a0<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430\u0448\u0443 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0432\u044b\u0431\u0440\u0430\u043b\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u042d\u043d\u0442\u0440\u043e\u043f\u0438\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u043c\u044b \u0443\u0433\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u0433\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0430. \u0418 \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0443\u0436\u0430\u0442\u044c \u043a\u0440\u0443\u0433 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u044d\u0442\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 Gini:<\/p>\n<ul>\n<li>\n<p>\u0421 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0414\u0436\u0438\u043d\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0446\u0435\u043b\u0438 \u0434\u0435\u0440\u0435\u0432\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0438 \u043f\u043e\u0440\u043e\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u043c\u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 dtreeviz, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0435\u0433\u043e. <\/p>\n<pre><code># %pip install dreeviz from dtreeviz.trees import dtreeviz  image_est = dtreeviz(dtc_model.best_estimator_,                x_data=X_train_clf,                y_data=y_train_clf,                target_name='class',                feature_names=[i for i in X_train_clf.columns],                class_names=['\u041d\u0435 \u0434\u0438\u0430\u0431\u0435\u0442', '\u0414\u0438\u0430\u0431\u0435\u0442'],                title=\"\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0432\u0435\u0441\u043e\u0432 Decision Tree\") image_est.save('dtreeviz.svg')<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043d\u0444\u043e\u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e. \u0412\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0434\u0435\u0440\u0435\u0432\u043e \u043e\u0442\u0431\u0438\u0440\u0430\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0413\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e 3, \u0433\u0434\u0435 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u0432\u0441\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, \u0430 \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430.<\/p>\n<p>\u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441 \u043c\u0435\u0434\u0438\u0446\u0438\u043d\u0441\u043a\u0438\u043c\u0438 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430\u043c\u0438, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u0432\u043e\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0421\u0443\u0434\u044f \u0438\u0437 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432, \u043f\u0440\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0430\u0445\u0430\u0440\u0430 \u0432 \u043a\u0440\u043e\u0432\u0438 &#8212; \u0448\u0430\u043d\u0441 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0434\u0438\u0430\u0431\u0435\u0442\u0430 \u043f\u043e\u0432\u044b\u0448\u0435\u043d, \u0447\u0442\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<h4>DecisionTree \u2013 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/h4>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 (\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u0435. \u041e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c.<\/p>\n<ul>\n<li>\n<p>Gender \u2013 \u043f\u043e\u043b \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>Race\/ethnicity \u2013 \u044d\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430 (\u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0435\u0437\u043b\u0438\u0447\u0435\u043d\u044b);<\/p>\n<\/li>\n<li>\n<p>Parental level of education \u2013 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>Lunch \u2013 \u0442\u0438\u043f \u043f\u0438\u0442\u0430\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>Test preparation score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043a \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u0430\u043c;<\/p>\n<\/li>\n<li>\n<p>Math score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435;<\/p>\n<\/li>\n<li>\n<p>Reading score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e \u0447\u0442\u0435\u043d\u0438\u044e;<\/p>\n<\/li>\n<li>\n<p>Writing score \u2013 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e \u043f\u0438\u0441\u044c\u043c\u0443.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b\u0431\u0435\u0440\u0443 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a &#8212; \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435 (math score), \u043c\u0435\u0442\u0440\u0438\u043a\u0443 &#8212; \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e LabelEncoder.<\/p>\n<pre><code>df_reg = pd.read_csv('..\/input\/students-performance-in-exams\/StudentsPerformance.csv') df_reg.head()<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code>from sklearn.preprocessing import LabelEncoder  le = LabelEncoder() df_reg = df_reg.apply(le.fit_transform)  target_df_reg = df_reg['math score'] feature_df_reg = df_reg[[i for i in df_reg.columns if i != 'math score']]  X_train_reg, X_test_reg, y_train_reg, y_test_reg = train_test_split(feature_df_reg,                                                                     target_df_reg,                                                                      test_size=0.29,                                                                      random_state=11)<\/code><\/pre>\n<p>\u041e\u0431\u0443\u0447\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0430\u0432\u0442\u043e-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<pre><code>from sklearn.tree import DecisionTreeRegressor from sklearn.metrics import mean_absolute_error  tree_param = [{'criterion': ['squared_error', 'friedman_mse', 'absolute_error'],                'max_depth': [i for i in range(1, 20)],               'min_samples_leaf': [i for i in range(1, 25)],                'max_leaf_nodes': [i for i in range(2, 20)],               }]  dtr_model = GridSearchCV(DecisionTreeRegressor(), tree_param, cv=5) dtr_model.fit(X = X_train_reg.values,               y = y_train_reg)  prediction_reg = dtr_model.best_estimator_.predict(X_test_reg) score_reg = mean_absolute_error(prediction_reg, y_test_reg)  print(f'\u041b\u0443\u0447\u0448\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: {dtr_model.best_estimator_}') print(f'\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: {round(score_reg, 3)}') <\/code><\/pre>\n<p>\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: 5.722<\/p>\n<pre><code>plt.figure(figsize=(15,15)) plot_tree(dtr_model.best_estimator_, filled=True, impurity=True)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code>image_est2 = dtreeviz(dtr_model.best_estimator_,                x_data=X_train_reg,                y_data=y_train_reg,                target_name='class',                feature_names=[i for i in X_train_reg.columns],                title=\"\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0432\u0435\u0441\u043e\u0432 \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438\") image_est2.save('dtreeviz2.svg')<\/code><\/pre>\n<p>\u0414\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0433\u043b\u0443\u0431\u0436\u0435, \u0447\u0435\u043c \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0437\u0434\u0435\u0441\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0434\u0435\u0441\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u043b\u0430 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u041f\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0432\u043e\u0434\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0432\u044b\u043a\u0438 \u043f\u0438\u0441\u044c\u043c\u0430 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u044f\u0437\u044c \u0441 \u0433\u0435\u043d\u0434\u0435\u0440\u043e\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u0443\u044e\u0442.<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c*.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043e\u0446\u0435\u043d\u043a\u0438*.<\/p>\n<\/li>\n<\/ul>\n<p>&#171;*&#187; &#8212; \u0438\u043c\u0435\u044e\u0442 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0432\u044b\u0431\u0440\u0430\u043b\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0432 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c, \u0431\u044b\u043b\u0438 \u0431\u044b \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u043d\u0435 \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u044b, \u043d\u043e \u043f\u043e\u0441\u0442\u0440\u0430\u0434\u0430\u043b\u0430 \u0431\u044b \u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u0431\u0440\u043e\u0441 +-6 \u0431\u0430\u043b\u043b\u043e\u0432 \u0438\u0437 100.<\/p>\n<h3>Random Forest<\/h3>\n<p>\u0418 \u043d\u0430\u0441\u0442\u0430\u043b \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u0441\u043e\u0432 \u043d\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430. \u041e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e<\/p>\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-344256","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344256","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=344256"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344256\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=344256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=344256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=344256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}