{"id":381017,"date":"2024-06-29T03:25:45","date_gmt":"2024-06-29T03:25:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=381017"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=381017","title":{"rendered":"<span>\u0420\u0430\u0431\u043e\u0442\u044b \u043f\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e 3\u0418\u0421\u0438\u041f-19-1<\/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<h3>\u041f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435<\/p>\n<pre><code class=\"python\">data_frame = pd.read_csv('bank.csv') data_frame<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d20\/908\/135\/d20908135a7b90f74dc33e1edda87b18.png\" width=\"1434\" height=\"487\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d20\/908\/135\/d20908135a7b90f74dc33e1edda87b18.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">data_frame.info()<\/code><\/pre>\n<figure class=\"float bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5c5\/e32\/0cc\/5c5e320cce21bd302800d263fe3e23f5.png\" width=\"426\" height=\"558\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5c5\/e32\/0cc\/5c5e320cce21bd302800d263fe3e23f5.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044e \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e &#8212; \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 default, housing, loan.<\/p>\n<pre><code class=\"python\">data_frame['default'] = np.where(data_frame['default'] == 'yes', 1, 0) data_frame['housing'] = np.where(data_frame['housing'] == 'yes', 1, 0) data_frame['loan'] = np.where(data_frame['loan'] == 'yes', 1, 0)<\/code><\/pre>\n<p>\u041d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432\u00a0<strong>Day<\/strong>,\u00a0<strong>Mounth<\/strong>\u00a0\u0438\u00a0<strong>Contact<\/strong>\u00a0\u043f\u043e\u0434 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u0435\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u043b\u043e\u0433\u0438\u043a\u0435 \u044f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u043e, \u043a\u0430\u043a \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c. \u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u043d\u044f \u0438 \u043c\u0435\u0441\u044f\u0446\u0430 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u0434\u043d\u0435\u0439 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430. \u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u043d\u0435\u0442 \u043e\u043f\u043e\u0440\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0441\u0440\u043e\u043a\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0434\u0430\u0442\u0430, \u0434\u043e \u043a\u0430\u043a\u043e\u0439 \u0441\u0447\u0438\u0442\u0430\u0442\u044c. \u0422\u0430\u043a \u0447\u0442\u043e \u044f \u0438\u0445 \u0443\u0434\u0430\u043b\u044f\u044e.<\/p>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0430\u043d\u0430\u043b\u0438\u0437 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0431\u0435\u0437 \u043d\u0438\u0445, \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u0438\u0445 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"python\">data_frame.drop(['day', 'month', 'contact'], axis = 1, inplace = True)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u043d\u0430 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432\u044b\u0439<\/p>\n<pre><code class=\"python\">object_df = data_frame.select_dtypes(include=['object']).copy() value_df = data_frame.select_dtypes(include=[int]).copy() value_df<\/code><\/pre>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/598\/f67\/24f\/598f6724f745b4655a4abd098329573d.png\" width=\"869\" height=\"478\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/598\/f67\/24f\/598f6724f745b4655a4abd098329573d.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">object_df<\/code><\/pre>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/66e\/762\/ce8\/66e762ce8d278a43b7386eaa3e4b12cf.png\" width=\"557\" height=\"492\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/66e\/762\/ce8\/66e762ce8d278a43b7386eaa3e4b12cf.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#8216;\u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e&#8217;, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412\u0435\u0434\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a, \u043d\u043e \u0432\u0435\u0434\u044c \u043e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0438 \u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e \u0436\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u043f\u043e\u0434 \u0441\u043e\u0431\u043e\u0439 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442.<\/p>\n<pre><code class=\"python\">object_df['job'].value_counts()<\/code><\/pre>\n<figure class=\"float bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/18a\/dad\/1fd\/18adad1fd91315cddf2c5c5a2031f66a.png\" width=\"386\" height=\"310\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/18a\/dad\/1fd\/18adad1fd91315cddf2c5c5a2031f66a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0443\u0442 \u0442\u0430\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435 \u043c\u043d\u043e\u0433\u043e, \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u044d\u0442\u043e\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c. <br \/>\u0412 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0441\u0440\u0430\u0437\u0443 \u0443\u0431\u0435\u0440\u0443 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0446\u0435\u043b\u0438 \u0438 \u0437\u0430\u043d\u0435\u0441\u0443 \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<pre><code class=\"python\">target = value_df['y'] value_df.drop('y', axis = 1, inplace = True)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0421\u0434\u0435\u043b\u0430\u044e \u044d\u0442\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0430 \u0432\u0434\u0440\u0443\u0433 \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u0438 \u043d\u0435 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0434\u0430 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438<\/p>\n<pre><code class=\"python\">object_df_encoded = pd.get_dummies(object_df) object_df_encoded<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/73f\/b9b\/989\/73fb9b9891d57301420b70c27b96d6cd.png\" width=\"1479\" height=\"508\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/73f\/b9b\/989\/73fb9b9891d57301420b70c27b96d6cd.png\"\/><figcaption><\/figcaption><\/figure>\n<h4>\u0412\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u043d\u0430\u00a0&#8216;\u043f\u043e\u0434\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430 \u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0434\u0435\u043f\u043e\u0437\u0438\u0442&#8217;\u00a0\u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0445.<\/h4>\n<pre><code class=\"python\">from sklearn.ensemble import RandomForestClassifier from sklearn.feature_selection import SelectFromModel<\/code><\/pre>\n<pre><code class=\"python\">randomforest = RandomForestClassifier(random_state = 0, n_jobs = -1) selector = SelectFromModel(randomforest, threshold = 0.1) val_important = selector.fit_transform(value_df, target) val_important<\/code><\/pre>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/67a\/2fe\/01c\/67a2fe01c274db3e89ff312ae86c68ea.png\" width=\"555\" height=\"175\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/67a\/2fe\/01c\/67a2fe01c274db3e89ff312ae86c68ea.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a, \u0443\u0436\u0435 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u044b, \u0430 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0448\u043a\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/p>\n<pre><code class=\"python\">from sklearn.preprocessing import StandardScaler, Normalizer  scaler = StandardScaler() value_df_scaled = scaler.fit_transform(value_df)   normalizer = Normalizer() value_df_normalized = normalizer.fit_transform(value_df)  val_important_sc = selector.fit_transform(value_df_scaled, target) val_important_sc<\/code><\/pre>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e01\/06d\/c4d\/e0106dc4d34ce48b6ca53ec3b22e9036.png\" width=\"634\" height=\"176\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e01\/06d\/c4d\/e0106dc4d34ce48b6ca53ec3b22e9036.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a \u0438 \u0432\u044b\u044f\u0441\u043d\u044f\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u0448\u043a\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u0438. \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e<\/p>\n<pre><code class=\"python\">val_important_nr = selector.fit_transform(value_df_normalized, target) val_important_nr<\/code><\/pre>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/043\/c8d\/a65\/043c8da65a14504570908528fea07f8f.png\" width=\"743\" height=\"312\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/043\/c8d\/a65\/043c8da65a14504570908528fea07f8f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0441\u0442\u0430\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u041d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u043b\u0438 \u044d\u0442\u043e? \u041f\u0440\u043e\u0432\u0435\u0440\u044e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0435.<br \/>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438 \u043d\u0430 \u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443.<\/p>\n<pre><code class=\"python\">import matplotlib.pyplot as plt rf_model = randomforest.fit(value_df, target) names = value_df.columns.values ticks = [i for i in range(len(rf_model.feature_importances_))]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.bar(names, rf_model.feature_importances_) plt.xticks(ticks, names, rotation = 90) plt.show()<\/code><\/pre>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/347\/e15\/ed9\/347e15ed9fa492bc0de6dac432d5a367.png\" width=\"552\" height=\"405\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/347\/e15\/ed9\/347e15ed9fa492bc0de6dac432d5a367.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0432\u043e\u0442, \u0438 \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043b\u043e \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0432\u044b\u0432\u043e\u0434\u0438\u0442 SelectFromModel \u0441 \u043f\u043e\u0440\u043e\u0433\u043e\u043c 0.1. \u0410 \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f?<\/p>\n<pre><code class=\"python\">rf_model = randomforest.fit(value_df_normalized, target) names = value_df.columns.values ticks = [i for i in range(len(rf_model.feature_importances_))]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.bar(names, rf_model.feature_importances_) plt.xticks(ticks, names, rotation = 90) plt.show()<\/code><\/pre>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6be\/c41\/f6e\/6bec41f6ee0c162781faa9973d890383.png\" width=\"549\" height=\"418\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6be\/c41\/f6e\/6bec41f6ee0c162781faa9973d890383.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a-\u0442\u043e \u043d\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u0440\u0430\u0437\u0443 \u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0438 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0441\u0440\u0435\u0434\u0438 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439.<\/p>\n<pre><code class=\"python\">obj_important = selector.fit_transform(object_df_encoded, target) obj_important<\/code><\/pre>\n<figure class=\"float bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/87b\/0c0\/648\/87b0c06489c948846a6d46fdd5b5d9a5.png\" width=\"290\" height=\"167\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/87b\/0c0\/648\/87b0c06489c948846a6d46fdd5b5d9a5.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435 \u0433\u0443\u0441\u0442\u043e, \u043d\u0430\u0434\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443.<\/p>\n<pre><code class=\"python\">rf_model = randomforest.fit(object_df_encoded, target) names = object_df_encoded.columns.values ticks = [i for i in range(len(rf_model.feature_importances_))]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.bar(names, rf_model.feature_importances_) plt.xticks(ticks, names, rotation = 90) plt.show()<\/code><\/pre>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4c9\/ce1\/34b\/4c9ce134b6341ac839998a6a1194b08d.png\" alt=\"\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432\" title=\"\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432\" width=\"526\" height=\"472\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4c9\/ce1\/34b\/4c9ce134b6341ac839998a6a1194b08d.png\"\/><figcaption>\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432<\/figcaption><\/figure>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b, \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043b\u0438\u044f\u0435\u0442 \u0442\u043e, \u0443\u0434\u0430\u0447\u043d\u044b\u0439 \u043b\u0438 \u0431\u044b\u043b \u043e\u043f\u044b\u0442 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438.<\/p>\n<h3>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0432 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 80%, 20%.<\/h3>\n<pre><code class=\"python\">from sklearn.model_selection import train_test_split<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0441\u043a\u043b\u0435\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439, \u0430 \u043f\u043e\u0442\u043e\u043c \u044d\u0442\u043e\u0442 \u0435\u0434\u0438\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0443\u0436\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<pre><code class=\"python\">features = np.array(pd.DataFrame(val_important).join(pd.DataFrame(obj_important), rsuffix='_obj')) features_train, features_test, target_train, target_test = train_test_split(features, target, test_size = 0.20, random_state = 0)<\/code><\/pre>\n<h3>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430 \u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0434\u0435\u043f\u043e\u0437\u0438\u0442, \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/h3>\n<pre><code class=\"python\"># \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437 from sklearn.neighbors import KNeighborsClassifier  from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier from sklearn.naive_bayes import GaussianNB  # \u044d\u0442\u043e\u0442 \u043c\u0435\u0434\u043e\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 from sklearn.metrics import accuracy_score <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u0447\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u043e\u0431\u0443\u0447\u0438\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043d\u0438\u0445 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e\u0441\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435.<\/p>\n<pre><code class=\"python\">kn_model = KNeighborsClassifier(n_neighbors = 20) rfc_model = RandomForestClassifier(random_state = 0) ada_model = AdaBoostClassifier(random_state = 0) gnb_model = GaussianNB()<\/code><\/pre>\n<p>\u041e\u0431\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0438 \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445.<\/p>\n<pre><code class=\"python\">kn_model.fit(features_train, target_train) rfc_model.fit(features_train, target_train) ada_model.fit(features_train, target_train) gnb_model.fit(features_train, target_train)<\/code><\/pre>\n<figure class=\"float bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/387\/288\/898\/3872888980366fe1df06703605192a66.png\" width=\"240\" height=\"34\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/387\/288\/898\/3872888980366fe1df06703605192a66.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<pre><code class=\"python\">kn_predict = kn_model.predict(features_test) rfc_predict = rfc_model.predict(features_test) ada_predict = ada_model.predict(features_test) gnb_predict = gnb_model.predict(features_test)<\/code><\/pre>\n<p>\u0418 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u043e \u043e\u0442\u0432\u0435\u0442\u0430\u043c \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<pre><code class=\"python\">print('KNeighbors', accuracy_score(kn_predict, target_test)) print('RandomForest', accuracy_score(rfc_predict, target_test)) print('AdaBoost', accuracy_score(ada_predict, target_test)) print('GaussianNB', accuracy_score(gnb_predict, target_test))<\/code><\/pre>\n<figure class=\"float bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/aac\/249\/18a\/aac24918a365c647d817c585d6dc6dc2.png\" width=\"339\" height=\"101\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aac\/249\/18a\/aac24918a365c647d817c585d6dc6dc2.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439(\u0445\u043e\u0442\u044c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u043e\u0442\u044b\u0435).<\/p>\n<pre><code class=\"python\">names = ['KNeighbors', 'RandomForest', 'AdaBoost', 'GaussianNB'] ticks = [i for i in range(len(names))] values = [accuracy_score(kn_predict, target_test), accuracy_score(rfc_predict, target_test),          accuracy_score(ada_predict, target_test), accuracy_score(gnb_predict, target_test)]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.barh(names, values) plt.yticks(ticks, names, rotation = 0) plt.show()<\/code><\/pre>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5e5\/783\/04f\/5e578304f8eefc19bb66c5d863861fb7.png\" width=\"606\" height=\"365\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5e5\/783\/04f\/5e578304f8eefc19bb66c5d863861fb7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0430\u0443\u0441\u0441\u043e\u0432 \u043d\u0430\u0438\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0437 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430\u0438\u0432\u044b\u0441\u0448\u0443\u044e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u041d\u043e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u0434\u043e\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 \u0434\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0435\u0449\u0435 \u043a\u0443\u0447\u0443 \u043c\u043e\u0434\u0435\u043b\u0435\u0439? \u0422\u0430\u043a \u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u043e \u0441\u0430\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0442\u043e\u0438\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0438 \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\u0438. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0430\u0436\u0435 \u0442\u0430\u043a, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u0438 \u0435\u0433\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/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\/595429\/\"> https:\/\/habr.com\/ru\/articles\/595429\/<\/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<h3>\u041f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435<\/p>\n<pre><code class=\"python\">data_frame = pd.read_csv('bank.csv') data_frame<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">data_frame.info()<\/code><\/pre>\n<figure class=\"float bordered\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044e \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e &#8212; \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 default, housing, loan.<\/p>\n<pre><code class=\"python\">data_frame['default'] = np.where(data_frame['default'] == 'yes', 1, 0) data_frame['housing'] = np.where(data_frame['housing'] == 'yes', 1, 0) data_frame['loan'] = np.where(data_frame['loan'] == 'yes', 1, 0)<\/code><\/pre>\n<p>\u041d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432\u00a0<strong>Day<\/strong>,\u00a0<strong>Mounth<\/strong>\u00a0\u0438\u00a0<strong>Contact<\/strong>\u00a0\u043f\u043e\u0434 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u0435\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u043b\u043e\u0433\u0438\u043a\u0435 \u044f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u043e, \u043a\u0430\u043a \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c. \u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u043d\u044f \u0438 \u043c\u0435\u0441\u044f\u0446\u0430 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u0434\u043d\u0435\u0439 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430. \u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u043d\u0435\u0442 \u043e\u043f\u043e\u0440\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0441\u0440\u043e\u043a\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0434\u0430\u0442\u0430, \u0434\u043e \u043a\u0430\u043a\u043e\u0439 \u0441\u0447\u0438\u0442\u0430\u0442\u044c. \u0422\u0430\u043a \u0447\u0442\u043e \u044f \u0438\u0445 \u0443\u0434\u0430\u043b\u044f\u044e.<\/p>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0430\u043d\u0430\u043b\u0438\u0437 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0431\u0435\u0437 \u043d\u0438\u0445, \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u0438\u0445 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"python\">data_frame.drop(['day', 'month', 'contact'], axis = 1, inplace = True)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u043d\u0430 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432\u044b\u0439<\/p>\n<pre><code class=\"python\">object_df = data_frame.select_dtypes(include=['object']).copy() value_df = data_frame.select_dtypes(include=[int]).copy() value_df<\/code><\/pre>\n<figure class=\"bordered full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">object_df<\/code><\/pre>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#8216;\u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e&#8217;, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412\u0435\u0434\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a, \u043d\u043e \u0432\u0435\u0434\u044c \u043e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0438 \u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e \u0436\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u043f\u043e\u0434 \u0441\u043e\u0431\u043e\u0439 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442.<\/p>\n<pre><code class=\"python\">object_df['job'].value_counts()<\/code><\/pre>\n<figure class=\"float bordered\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0443\u0442 \u0442\u0430\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435 \u043c\u043d\u043e\u0433\u043e, \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u044d\u0442\u043e\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c. <br \/>\u0412 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0441\u0440\u0430\u0437\u0443 \u0443\u0431\u0435\u0440\u0443 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0446\u0435\u043b\u0438 \u0438 \u0437\u0430\u043d\u0435\u0441\u0443 \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<pre><code class=\"python\">target = value_df['y'] value_df.drop('y', axis = 1, inplace = True)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0421\u0434\u0435\u043b\u0430\u044e \u044d\u0442\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0430 \u0432\u0434\u0440\u0443\u0433 \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u0438 \u043d\u0435 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0434\u0430 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438<\/p>\n<pre><code class=\"python\">object_df_encoded = pd.get_dummies(object_df) object_df_encoded<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h4>\u0412\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u043d\u0430\u00a0&#8216;\u043f\u043e\u0434\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430 \u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0434\u0435\u043f\u043e\u0437\u0438\u0442&#8217;\u00a0\u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0445.<\/h4>\n<pre><code class=\"python\">from sklearn.ensemble import RandomForestClassifier from sklearn.feature_selection import SelectFromModel<\/code><\/pre>\n<pre><code class=\"python\">randomforest = RandomForestClassifier(random_state = 0, n_jobs = -1) selector = SelectFromModel(randomforest, threshold = 0.1) val_important = selector.fit_transform(value_df, target) val_important<\/code><\/pre>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a, \u0443\u0436\u0435 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u044b, \u0430 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0448\u043a\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/p>\n<pre><code class=\"python\">from sklearn.preprocessing import StandardScaler, Normalizer  scaler = StandardScaler() value_df_scaled = scaler.fit_transform(value_df)   normalizer = Normalizer() value_df_normalized = normalizer.fit_transform(value_df)  val_important_sc = selector.fit_transform(value_df_scaled, target) val_important_sc<\/code><\/pre>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a \u0438 \u0432\u044b\u044f\u0441\u043d\u044f\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u0448\u043a\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u0438. \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e<\/p>\n<pre><code class=\"python\">val_important_nr = selector.fit_transform(value_df_normalized, target) val_important_nr<\/code><\/pre>\n<figure class=\"float full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0441\u0442\u0430\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u041d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u043b\u0438 \u044d\u0442\u043e? \u041f\u0440\u043e\u0432\u0435\u0440\u044e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0435.<br \/>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438 \u043d\u0430 \u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443.<\/p>\n<pre><code class=\"python\">import matplotlib.pyplot as plt rf_model = randomforest.fit(value_df, target) names = value_df.columns.values ticks = [i for i in range(len(rf_model.feature_importances_))]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.bar(names, rf_model.feature_importances_) plt.xticks(ticks, names, rotation = 90) plt.show()<\/code><\/pre>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0432\u043e\u0442, \u0438 \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043b\u043e \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0432\u044b\u0432\u043e\u0434\u0438\u0442 SelectFromModel \u0441 \u043f\u043e\u0440\u043e\u0433\u043e\u043c 0.1. \u0410 \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f?<\/p>\n<pre><code class=\"python\">rf_model = randomforest.fit(value_df_normalized, target) names = value_df.columns.values ticks = [i for i in range(len(rf_model.feature_importances_))]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.bar(names, rf_model.feature_importances_) plt.xticks(ticks, names, rotation = 90) plt.show()<\/code><\/pre>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a-\u0442\u043e \u043d\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u0440\u0430\u0437\u0443 \u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0438 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0441\u0440\u0435\u0434\u0438 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439.<\/p>\n<pre><code class=\"python\">obj_important = selector.fit_transform(object_df_encoded, target) obj_important<\/code><\/pre>\n<figure class=\"float bordered\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435 \u0433\u0443\u0441\u0442\u043e, \u043d\u0430\u0434\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443.<\/p>\n<pre><code class=\"python\">rf_model = randomforest.fit(object_df_encoded, target) names = object_df_encoded.columns.values ticks = [i for i in range(len(rf_model.feature_importances_))]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.bar(names, rf_model.feature_importances_) plt.xticks(ticks, names, rotation = 90) plt.show()<\/code><\/pre>\n<figure class=\"float full-width\"><figcaption>\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432<\/figcaption><\/figure>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b, \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043b\u0438\u044f\u0435\u0442 \u0442\u043e, \u0443\u0434\u0430\u0447\u043d\u044b\u0439 \u043b\u0438 \u0431\u044b\u043b \u043e\u043f\u044b\u0442 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438.<\/p>\n<h3>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0432 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 80%, 20%.<\/h3>\n<pre><code class=\"python\">from sklearn.model_selection import train_test_split<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0441\u043a\u043b\u0435\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439, \u0430 \u043f\u043e\u0442\u043e\u043c \u044d\u0442\u043e\u0442 \u0435\u0434\u0438\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0443\u0436\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<pre><code class=\"python\">features = np.array(pd.DataFrame(val_important).join(pd.DataFrame(obj_important), rsuffix='_obj')) features_train, features_test, target_train, target_test = train_test_split(features, target, test_size = 0.20, random_state = 0)<\/code><\/pre>\n<h3>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430 \u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0434\u0435\u043f\u043e\u0437\u0438\u0442, \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/h3>\n<pre><code class=\"python\"># \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437 from sklearn.neighbors import KNeighborsClassifier  from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier from sklearn.naive_bayes import GaussianNB  # \u044d\u0442\u043e\u0442 \u043c\u0435\u0434\u043e\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 from sklearn.metrics import accuracy_score <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u0447\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u043e\u0431\u0443\u0447\u0438\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043d\u0438\u0445 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e\u0441\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435.<\/p>\n<pre><code class=\"python\">kn_model = KNeighborsClassifier(n_neighbors = 20) rfc_model = RandomForestClassifier(random_state = 0) ada_model = AdaBoostClassifier(random_state = 0) gnb_model = GaussianNB()<\/code><\/pre>\n<p>\u041e\u0431\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0438 \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445.<\/p>\n<pre><code class=\"python\">kn_model.fit(features_train, target_train) rfc_model.fit(features_train, target_train) ada_model.fit(features_train, target_train) gnb_model.fit(features_train, target_train)<\/code><\/pre>\n<figure class=\"float bordered\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<pre><code class=\"python\">kn_predict = kn_model.predict(features_test) rfc_predict = rfc_model.predict(features_test) ada_predict = ada_model.predict(features_test) gnb_predict = gnb_model.predict(features_test)<\/code><\/pre>\n<p>\u0418 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u043e \u043e\u0442\u0432\u0435\u0442\u0430\u043c \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<pre><code class=\"python\">print('KNeighbors', accuracy_score(kn_predict, target_test)) print('RandomForest', accuracy_score(rfc_predict, target_test)) print('AdaBoost', accuracy_score(ada_predict, target_test)) print('GaussianNB', accuracy_score(gnb_predict, target_test))<\/code><\/pre>\n<figure class=\"float bordered\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439(\u0445\u043e\u0442\u044c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u043e\u0442\u044b\u0435).<\/p>\n<pre><code class=\"python\">names = ['KNeighbors', 'RandomForest', 'AdaBoost', 'GaussianNB'] ticks = [i for i in range(len(names))] values = [accuracy_score(kn_predict, target_test), accuracy_score(rfc_predict, target_test),          accuracy_score(ada_predict, target_test), accuracy_score(gnb_predict, target_test)]  plt.figure() plt.title('\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432') plt.barh(names, values) plt.yticks(ticks, names, rotation = 0) plt.show()<\/code><\/pre>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0430\u0443\u0441\u0441\u043e\u0432 \u043d\u0430\u0438\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0437 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430\u0438\u0432\u044b\u0441\u0448\u0443\u044e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u041d\u043e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u0434\u043e\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 \u0434\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0435\u0449\u0435 \u043a\u0443\u0447\u0443 \u043c\u043e\u0434\u0435\u043b\u0435\u0439? \u0422\u0430\u043a \u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u043e \u0441\u0430\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0442\u043e\u0438\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0438 \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\u0438. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0430\u0436\u0435 \u0442\u0430\u043a, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u0438 \u0435\u0433\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/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\/595429\/\"> https:\/\/habr.com\/ru\/articles\/595429\/<\/a><br \/><\/br><\/br><\/p>\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-381017","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381017","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=381017"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381017\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=381017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=381017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=381017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}