{"id":301612,"date":"2020-04-09T21:00:25","date_gmt":"2020-04-09T21:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=301612"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=301612","title":{"rendered":"\u041f\u043e\u0434\u0431\u043e\u0440 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u0444\u0438\u0447 \u0434\u043b\u044f k-nearest neighbors (\u043d\u0443 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432) \u0441\u043f\u0443\u0441\u043a\u043e\u043c \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/496484\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/eg\/qm\/x6\/egqmx63h8mgrbxfytg9nmuaby-g.gif\" alt=\"\u0418\u0441\u0442\u0438\u043d\u043d\u044b\u0439 \u0435\u0440\u0443\u043d\u0434\u0443\u043a \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u043d\u0438\u043c\u043e\u0435, \u043d\u043e \u0438 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0435\u0440\u0435\u0433\u0430\u044e\u0449\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c\"><\/div>\n<p>  \u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044f \u0441 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u043a\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u0432 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u043e\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 18 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u043d\u0430 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0437\u044f\u0442\u044c \u0438 \u0433\u0440\u0443\u0431\u043e\u0439 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u0441\u0438\u043b\u043e\u0439.<\/p>\n<p>  \u041e\u0431\u0443\u0447\u0430\u044f\u0441\u044c \u0447\u0435\u043c\u0443-\u0442\u043e \u043c\u043d\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434. \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435. \u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043e \u0434\u043e \u043c\u0435\u043d\u044f. \u041d\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044f \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u043f\u0443\u0442\u044c \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u0434\u043e\u043b\u0433\u043e \u0434\u043e \u043c\u0435\u043d\u044f, \u0432 \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u044f \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0433\u043b\u0443\u0431\u0438\u043d\u043d\u044b\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439. \u041a \u0447\u0435\u043c\u0443 \u0438 \u0432\u0430\u0441 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e.<\/p>\n<p>  \u0412 Python \u0438 DS \u044f, \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u044f\u0433\u043a\u043e, \u043d\u043e\u0432\u0438\u0447\u043e\u043a, \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u0435\u0449\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0441\u043a\u043e\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0435 \u0434\u0435\u043b\u0430\u044e \u043a\u043e\u0434\u043e\u043c, \u0437\u0430 \u0447\u0442\u043e Python \u043d\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432 \u0440\u0430\u0437\u044b, \u0430 \u043d\u0430 \u043f\u043e\u0440\u044f\u0434\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0435\u0441\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u044f \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0435\u0442\u0435 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u2014 \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c, \u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u0442\u0430\u043c, \u0438\u043b\u0438 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. <a href=\"https:\/\/github.com\/kraidiky\/GDforHyperparameters\" rel=\"nofollow\">https:\/\/github.com\/kraidiky\/GDforHyperparameters<\/a><\/p>\n<p>  \u0422\u0435\u043c, \u043a\u0442\u043e \u0443\u0436\u0435 \u043a\u0440\u0443\u0442\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0430\u0442\u0430\u043d\u0438\u0441\u0442, \u0438 \u0432\u0441\u0451 \u0432 \u044d\u0442\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043d\u0435\u0431\u0435\u0437\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0431\u0443\u0434\u0435\u0442, \u044f \u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u043a\u0435.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>  \u0415\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043a\u0443\u0440\u0441 \u043f\u043e DS \u043e\u0442 ODS.ai \u0438 \u0442\u0430\u043c \u0442\u0440\u0435\u0442\u044c\u044f \u043b\u0435\u043a\u0446\u0438\u044f <a href=\"https:\/\/habr.com\/ru\/company\/ods\/blog\/322534\/\">\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f, \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439<\/a>. \u0422\u0430\u043c \u043d\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u0430\u0451\u0442 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c 94.5%, \u0430 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 k \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0439 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u0451\u0442 89%<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u043c\u043f\u043e\u0440\u0442 \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import numpy as np import pandas as pd from matplotlib import pyplot as plt %matplotlib inline import warnings warnings.filterwarnings('ignore')  df = pd.read_csv('data\/telecom_churn.csv') df['Voice mail plan'] = pd.factorize(df['Voice mail plan'])[0] df['International plan'] = pd.factorize(df['International plan'])[0] df['Churn'] = df['Churn'].astype('int32') states = df['State'] y = df['Churn'] df.drop(['State','Churn'], axis = 1, inplace=True) df.head() <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u0430 \u0441 knn<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time from sklearn.model_selection import train_test_split, StratifiedKFold from sklearn.tree import DecisionTreeClassifier from sklearn.neighbors import KNeighborsClassifier from sklearn.model_selection import GridSearchCV, cross_val_score from sklearn.metrics import accuracy_score  X_train, X_holdout, y_train, y_holdout = train_test_split(df.values, y, test_size=0.3, random_state=17)  tree = DecisionTreeClassifier(random_state=17, max_depth=5) knn = KNeighborsClassifier(n_neighbors=10)  tree_params = {'max_depth': range(1,11), 'max_features': range(4,19)} tree_grid = GridSearchCV(tree, tree_params, cv=10, n_jobs=-1, verbose=False) tree_grid.fit(X_train, y_train) tree_grid.best_params_, tree_grid.best_score_, accuracy_score(y_holdout, tree_grid.predict(X_holdout)) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  ({&#8216;max_depth&#8217;: 6, &#8216;max_features&#8217;: 16}, 0.944706386626661, 0.945)<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0442\u043e \u0436\u0435 \u0434\u043b\u044f knn<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler  knn_pipe = Pipeline([('scaler', StandardScaler()), ('knn', KNeighborsClassifier(n_jobs=-1))]) knn_params = {'knn__n_neighbors': range(1, 10)} knn_grid = GridSearchCV(knn_pipe, knn_params, cv=10, n_jobs=-1, verbose=False)  knn_grid.fit(X_train, y_train) knn_grid.best_params_, knn_grid.best_score_, accuracy_score(y_holdout, knn_grid.predict(X_holdout)) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  ({&#8216;knn__n_neighbors&#8217;: 9}, 0.8868409772824689, 0.891)<br \/>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043c\u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u043e\u0431\u0438\u0434\u043d\u043e \u0437\u0430 knn \u044f\u0432\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u043d\u0435\u0447\u0435\u0441\u0442\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0432\u0435\u0434\u044c \u0441 \u043c\u0435\u0442\u0440\u0438\u043a\u043e\u0439 \u0434\u043b\u0438\u043d\u043d\u044b \u043c\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438. \u042f \u043d\u0435 \u0441\u0442\u0430\u043b \u0434\u0443\u043c\u0430\u0442\u044c \u043c\u043e\u0437\u0433\u043e\u043c, \u0432\u0437\u044f\u043b feature_importances_ \u0443 \u0434\u0435\u0440\u0435\u0432\u0430 \u0438 \u043e\u0442\u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043d\u0435\u0433\u043e. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0427\u0435\u043c \u0444\u0438\u0447\u0430 \u0432\u0430\u0436\u043d\u0435\u0435 \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0435\u0451 \u0432\u043a\u043b\u0430\u0434 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u0430\u043c\u0438.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0430\u0440\u043c\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0444\u0438\u0447<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time feature_importances = pd.DataFrame({'features': df.columns, 'importance':tree_grid.best_estimator_.feature_importances_}) print(feature_importances.sort_values(by=['importance'], inplace=False, ascending=False))  scaler = StandardScaler().fit(X_train) X_train_transformed = scaler.transform(X_train) X_train_transformed = X_train_transformed * np.array(feature_importances['importance'])  X_holdout_transformed = scaler.transform(X_holdout) X_holdout_transformed = X_holdout_transformed * np.array(feature_importances['importance'])  knn_grid = GridSearchCV(KNeighborsClassifier(n_jobs=-1), {'n_neighbors': range(1, 11, 2)}, cv=5, n_jobs=-1, verbose=False) knn_grid.fit(X_train_transformed, y_train) print (knn_grid.best_params_, knn_grid.best_score_, accuracy_score(y_holdout, knn_grid.predict(X_holdout_transformed))) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td>5<\/td>\n<td>Total day minutes<\/td>\n<td>0.270386<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td>Customer service calls<\/td>\n<td>0.147185<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>Total eve minutes<\/td>\n<td>0.135475<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>International plan<\/td>\n<td>0.097249<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td>Total intl charge<\/td>\n<td>0.091671<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>Total intl calls<\/td>\n<td>0.090008<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Number vmail messages<\/td>\n<td>0.050646<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>Total eve charge<\/td>\n<td>0.038593<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>Total day charge<\/td>\n<td>0.026422<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Voice mail plan<\/td>\n<td>0.017068<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>Total night minutes<\/td>\n<td>0.014185<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td>Total night charge<\/td>\n<td>0.005742<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>Total night calls<\/td>\n<td>0.005502<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>Total eve calls<\/td>\n<td>0.003614<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>Total day calls<\/td>\n<td>0.002246<\/td>\n<\/tr>\n<tr>\n<td>14<\/td>\n<td>Total intl minutes<\/td>\n<td>0.002009<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>Account length<\/td>\n<td>0.001998<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>Area code<\/td>\n<td>0.000000<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>  {&#8216;n_neighbors&#8217;: 5} 0.909129875696528 0.913<\/p>\n<p>  \u0414\u0435\u0440\u0435\u0432\u043e \u0432\u0441\u0435\u0433\u043e \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u043f\u043e\u0434\u0435\u043b\u0438\u043b\u043e\u0441\u044c \u0441 knn \u0441\u0432\u043e\u0438\u043c\u0438 \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u0438 \u0432\u043e\u0442 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0443\u0436\u0435 91% \u0427\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 94.5% \u0443 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430. \u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u043c\u0435\u043d\u044f \u0438 \u043f\u043e\u0441\u0435\u0442\u0438\u043b\u0430 \u0438\u0434\u0435\u044f. \u0410 \u043a\u0430\u043a, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0430\u0434\u043e \u043e\u0442\u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0447\u0442\u043e\u0431\u044b knn \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430 \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442?<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0438\u043a\u0438\u043d\u0435\u043c \u0432 \u0443\u043c\u0435 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0442 \u044d\u0442\u043e \u0432\u043e\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u00ab\u0432 \u043b\u043e\u0431\u00bb. 18 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, 10 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u0442\u0443\u043f\u0435\u043d\u0435\u0439 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435\u0439 \u0432 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0448\u043a\u0430\u043b\u0435. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c 10\u043518 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432. \u041e\u0434\u0438\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043e \u0432\u0441\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043d\u0435\u0447\u0451\u0442\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 10 \u0438 \u043a\u0440\u043e\u0441\u0441\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 \u0442\u043e\u0436\u0435 10 \u0443 \u043c\u0435\u043d\u044f \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 1.5 \u0441\u0435\u043a\u0443\u043d\u0434\u044b. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f 42 \u043c\u043b\u0440\u0434. \u043b\u0435\u0442. \u041e\u0442 \u0438\u0434\u0435\u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u043e\u0447\u044c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f. \ud83d\ude42 \u0418 \u0432\u043e\u0442 \u0433\u0434\u0435-\u0442\u043e \u0442\u0443\u0442 \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u00ab\u042d\u0439! \u0422\u0430\u043a \u044f \u0449\u0430 \u0441\u0434\u0435\u043b\u0430\u044e \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0435\u0442\u0438\u0442!\u00bb<\/p>\n<h2>\u041e\u043a\u043e\u043b\u043e\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a<\/h2>\n<p>  \u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u0443 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c. \u041d\u0443 \u0442\u043e\u0435\u0441\u0442\u044c \u043d\u0435 \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0446\u0435\u043b\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043d\u043e \u043e\u043d\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0443 \u0438 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0443\u044e \u0442\u043e\u0447\u043a\u0443. \u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0431\u044b\u043b\u0430 \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u0435\u043d\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0437\u0430\u043f\u0438\u043b\u0438\u0442\u044c, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0430\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0435\u043b\u044c\u0435\u0444 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0451\u043d\u043d\u044b\u043c, \u0438 \u044d\u0442\u043e \u0431\u044b\u043b \u0431\u044b \u0443\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0436\u0435\u0447\u043a\u043e \u043f\u0435\u0440\u0435\u0431\u043e\u0440.<\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430. \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0442\u0435\u043b\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441\u043e \u0441\u043a\u0435\u0439\u043b\u0435\u0440\u0430\u043c\u0438. \u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f, \u043a\u0430\u043a \u0438 \u0432 \u0443\u0440\u043e\u043a\u0435, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b StandartScaler, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0447\u0435\u0431\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043e\u0442\u0446\u0435\u043d\u0442\u0440\u043e\u0432\u0430\u043b \u043f\u043e \u0441\u0440\u0435\u0434\u0435\u043d\u043c\u0443 \u0438 \u0441\u0434\u0435\u043b\u0430\u043b sigma = 1. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0435\u0451 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0445\u0438\u0442\u0440\u0435\u0435. \u042f \u043d\u0430\u0447\u0430\u043b \u0438\u0441\u043a\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043b\u0435\u0436\u0438\u0449\u0438\u0445 \u0432 sklearn.preprocessing \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u043a \u043c\u043e\u0435\u043c\u0443 \u0441\u043b\u0443\u0447\u0430\u044e, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0448\u0451\u043b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 StandartScaler \u043d\u0430\u0432\u0435\u0448\u0430\u0432 \u043d\u0430 \u043d\u0435\u0433\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0430\u0447\u043a\u0443 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435\u0439.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043d\u043e\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431 \u0441\u043b\u0435\u0433\u043a\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u0441 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u043e\u043c sklearn<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">from sklearn.base import TransformerMixin class StandardAndPoorScaler(StandardScaler, TransformerMixin):     #normalization = None     def __init__(self, copy=True, with_mean=True, with_std=True, normalization = None):         #print(&quot;new StandardAndPoorScaler(normalization=&quot;, normalization.shape if normalization is not None else normalization, &quot;) \/\/ &quot;, type(self))         self.normalization = normalization         super().__init__(copy, with_mean, with_std)     def fit(self, X, y=None):         #print(type(self),&quot;.fit(&quot;,X.shape, &quot;,&quot;, y.shape if y is not None else &quot;&lt;null&gt;&quot;,&quot;)&quot;)         super().fit(X, y)         return self     def partial_fit(self, X, y=None):         #print(type(self),&quot;.partial_fit(&quot;,X.shape, &quot;,&quot;, y.shape if y is not None else &quot;&lt;null&gt;)&quot;)         super().partial_fit(X, y)         if self.normalization is None:             self.normalization = np.ones((X.shape[1]))         elif type(self.normalization) != np.ndarray:             self.normalization = np.array(self.normalization)         if X.shape[1] != self.normalization.shape[0]:             raise &quot;X.shape[1]=&quot;+X.shape[1]+&quot; in equal self.scale.shape[0]=&quot;+self.normalization.shape[0]     def transform(self, X, copy=None):         #print(type(self),&quot;.transform(&quot;,X.shape,&quot;,&quot;,copy,&quot;).self.normalization&quot;, self.normalization)         Xresult = super().transform(X, copy)         Xresult *= self.normalization         return Xresult     def _reset(self):         #print(type(self),&quot;._reset()&quot;)         super()._reset()      scaler = StandardAndPoorScaler(normalization = feature_importances['importance']) scaler.fit(X = X_train, y = None) print(scaler.normalization) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time knn_pipe = Pipeline([('scaler', StandardAndPoorScaler()), ('knn', KNeighborsClassifier(n_jobs=-1))])  knn_params = {'knn__n_neighbors': range(1, 11, 4), 'scaler__normalization': [feature_importances['importance']]} knn_grid = GridSearchCV(knn_pipe, knn_params, cv=5, n_jobs=-1, verbose=False)  knn_grid.fit(X_train, y_train) knn_grid.best_params_, knn_grid.best_score_, accuracy_score(y_holdout, knn_grid.predict(X_holdout)) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  ({&#8216;knn__n_neighbors&#8217;: 5, &#8216;scaler__normalization&#8217;: Name: importance, dtype: float64}, 0.909558508358337, 0.913)<\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043c\u043e\u0438\u0445 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0439. \u041d\u0443 \u0442\u043e \u0435\u0441\u0442\u044c \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0412\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0437\u0430 \u0442\u0440\u0438 \u0447\u0430\u0441\u0430 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u043e\u0442\u0440\u043e\u0445\u0430\u043c\u0438 \u0441 \u043d\u0443\u043b\u044f, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e print \u043d\u0438\u0444\u0438\u0433\u0430 \u043d\u0435 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043d\u0435 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e sklearn \u043a\u0430\u043a-\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u043d, \u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e GridSearchCV \u043a\u043b\u043e\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0430 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0438 \u043e\u0431\u0443\u0447\u0430\u0435\u0442 \u0438\u0445 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445. \u0410 \u0432\u0441\u0451 \u0447\u0442\u043e \u0442\u0430\u043c \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0448\u044c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442 \u0432 \u043d\u0435\u0431\u044b\u0442\u0438\u0438. \u0410 \u0432\u043e\u0442 \u0435\u0441\u043b\u0438 n_jobs=1 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0442\u043e \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u0438\u043b\u044b\u0435. \u041e\u0447\u0435\u043d\u044c \u0434\u043e\u0440\u043e\u0433\u043e\u0435 \u0432\u044b\u0448\u043b\u043e \u0437\u043d\u0430\u043d\u0438\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u043e \u0443 \u0432\u0430\u0441 \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c, \u0438 \u0432\u044b \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u043b\u0438 \u0437\u0430 \u043d\u0435\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u043d\u0443\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  \u041b\u0430\u0434\u043d\u043e, \u043f\u043e\u0448\u043b\u0438 \u0434\u0430\u043b\u044c\u0448\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u044f \u0445\u043e\u0447\u0443 \u0434\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0430 \u043f\u043e\u0442\u043e\u043c \u0434\u0430\u0442\u044c \u0435\u0451 \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0442\u0430\u043a \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u0433\u0440\u0443\u0431\u044b \u0431\u0435\u0439\u0437\u043b\u0430\u0439\u043d \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043c\u043e\u0435\u0439 \u043c\u0435\u0447\u0442\u044b.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0432\u0437\u0432\u0435\u0448\u0438\u0432\u0430\u043d\u0438\u0439, \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">feature_base = feature_importances['importance'] searchArea = np.array([feature_base - .05, feature_base, feature_base + .05]) searchArea[searchArea &lt; 0] = 0 searchArea[searchArea &gt; 1] = 1 print(searchArea[2,:] - searchArea[0,:])  import itertools  affected_props = [2,3,4] parametrs_ranges = np.concatenate([     np.linspace(searchArea[0,affected_props], searchArea[1,affected_props], 2, endpoint=False),     np.linspace(searchArea[1,affected_props], searchArea[2,affected_props], 3, endpoint=True)]).transpose()  print(parametrs_ranges) # \u041f\u043e \u043f\u044f\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u0412\u0441\u0435\u0433\u043e 125 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 recombinations = itertools.product(parametrs_ranges[0],parametrs_ranges[1],parametrs_ranges[1])  variances = [] for item in recombinations: # \u041d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u043e\u0442 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0443\u0442 \u043c\u043e\u0438 \u043e\u043c\u0435\u0440\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 Python \u0446\u0438\u043a\u043b\u044b.     varince = feature_base.copy()     varince[affected_props] = item     variances.append(varince) print(variances[0]) print(len(variances)) # \u041c\u0435\u0442\u043e\u0434\u0443 knn \u0432\u0430\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u043b\u0438 \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a \u0434\u0440\u0443\u0433\u043e\u0439. <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041d\u0443 \u0432\u043e\u0442, \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430 \u0433\u043e\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u043f\u0440\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, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0445\u0441\u044f 15 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0431\u043d\u044b\u0439 \u043f\u043e\u0434\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043a\u0430\u043a \u0432 \u0441\u0442\u0430\u0442\u044c\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time #scale = np.ones([18]) knn_pipe = Pipeline([('scaler', StandardAndPoorScaler()), ('knn', KNeighborsClassifier(n_neighbors = 7 , n_jobs=-1))])  knn_params = {'scaler__normalization': variances} # 'knn__n_neighbors': range(3, 9, 2),  knn_grid = GridSearchCV(knn_pipe, knn_params, cv=10, n_jobs=-1, verbose=False)  knn_grid.fit(X_train, y_train) knn_grid.best_params_, knn_grid.best_score_, accuracy_score(y_holdout, knn_grid.predict(X_holdout))<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041d\u0443 \u0438 \u0432\u0441\u0451 \u043f\u043b\u043e\u0445\u043e, \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u0430 \u043f\u0440\u043e\u0440\u0432\u0430, \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432. \u042d\u0442\u043e \u0438 \u043f\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u043f\u043e X_holdout \u0432\u0438\u0434\u043d\u043e, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043b\u044f\u0448\u0435\u0442 \u043a\u0430\u043a \u0432 \u043a\u0430\u043b\u0435\u0439\u0434\u043e\u0441\u043a\u043e\u043f\u0435 \u043f\u0440\u0438 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0411\u0443\u0434\u0443 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u043e \u0437\u0430\u0442\u043e \u0441 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0435\u0439.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0435\u043d\u044f\u044e \u043e\u0434\u043d\u043e 4-\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time affected_property = 4 parametrs_range = np.concatenate([     np.linspace(searchArea[0,affected_property], searchArea[1,affected_property], 29, endpoint=False),     np.linspace(searchArea[1,affected_property], searchArea[2,affected_property], 30, endpoint=True)]).transpose()  print(searchArea[1,affected_property]) print(parametrs_range) # C\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443, \u0437\u0430\u0442\u043e \u043f\u043b\u043e\u0442\u043d\u043e.   variances = [] for item in parametrs_range: # \u041d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u043e\u0442 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0443\u0442 \u043c\u043e\u0438 \u043e\u043c\u0435\u0440\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 Python \u0446\u0438\u043a\u043b\u044b.     varince = feature_base.copy()     varince[affected_property] = item     variances.append(varince) print(variances[0]) print(len(variances)) # \u041c\u0435\u0442\u043e\u0434\u0443 knn \u0432\u0430\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u043b\u0438 \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a \u0434\u0440\u0443\u0433\u043e\u0439.  knn_pipe = Pipeline([('scaler', StandardAndPoorScaler()), ('knn', KNeighborsClassifier(n_neighbors = 7 , n_jobs=-1))])  knn_params = {'scaler__normalization': variances} # 'knn__n_neighbors': range(3, 9, 2),  knn_grid = GridSearchCV(knn_pipe, knn_params, cv=10, n_jobs=-1, verbose=False)  knn_grid.fit(X_train, y_train) knn_grid.best_params_, knn_grid.best_score_, accuracy_score(y_holdout, knn_grid.predict(X_holdout))<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  ({&#8216;scaler__normalization&#8217;: 4 0.079957 Name: importance, dtype: float64}, 0.9099871410201458, 0.913)<\/p>\n<p>  \u041d\u0443, \u0438 \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0441 \u0433\u0443\u0441\u044f? \u041f\u043e\u0434\u0432\u0438\u0436\u043a\u0438 \u0432 \u043e\u0434\u043d\u0443-\u0434\u0432\u0435 \u0434\u0435\u0441\u044f\u0442\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 \u043d\u0430 \u043a\u0440\u043e\u0441\u0441\u0432\u0430\u043b\u0438\u0430\u0434\u0430\u0446\u0438\u0438, \u0438 \u0441\u043a\u0430\u0447\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 \u043d\u0430 X_holdout \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 affected_property. \u0412\u0438\u0434\u0438\u043c\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0434\u0435\u0448\u0435\u0432\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0435\u0441\u043b\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0434\u0430\u0451\u0442 \u0434\u0435\u0440\u0435\u0432\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u0442\u0430\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439, \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0432\u0435\u0441\u043e\u0432\u043a\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442, \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0432 \u0446\u0438\u043a\u043b\u0435 \u043c\u0430\u043b\u044e\u0441\u0435\u043d\u044c\u043a\u0438\u043c\u0438 \u0448\u0430\u0436\u043e\u0447\u043a\u0430\u043c\u0438. \u041e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043a \u0447\u0435\u043c\u0443 \u043f\u0440\u0438\u0434\u0451\u043c.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">searchArea = np.array([np.zeros((18,)), np.ones((18,)) \/18, np.ones((18,))]) print(searchArea[:,0])  history_parametrs = [searchArea[1,:].copy()] scaler = StandardAndPoorScaler(normalization=searchArea[1,:]) scaler.fit(X_train) knn = KNeighborsClassifier(n_neighbors = 7 , n_jobs=-1) knn.fit(scaler.transform(X_train), y_train) history_holdout_score = [accuracy_score(y_holdout, knn.predict(scaler.transform(X_holdout)))]<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u043c\u0435\u043d\u044f\u044e\u0449\u0430\u044f \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 (\u0441 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u043c\u0438 \u043b\u043e\u0433\u0430\u043c\u0438)<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time def changePropertyNormalization(affected_property, points_count = 15):     test_range = np.concatenate([         np.linspace(searchArea[0,affected_property], searchArea[1,affected_property], points_count\/\/2, endpoint=False),         np.linspace(searchArea[1,affected_property], searchArea[2,affected_property], points_count\/\/2 + 1, endpoint=True)]).transpose()     variances = [searchArea[1,:].copy() for i in range(test_range.shape[0])]     for row in range(len(variances)):         variances[row][affected_property] = test_range[row]          knn_pipe = Pipeline([('scaler', StandardAndPoorScaler()), ('knn', KNeighborsClassifier(n_neighbors = 7 , n_jobs=-1))])     knn_params = {'scaler__normalization': variances} # 'knn__n_neighbors': range(3, 9, 2),      knn_grid = GridSearchCV(knn_pipe, knn_params, cv=10, n_jobs=-1, verbose=False)      knn_grid.fit(X_train, y_train)     holdout_score = accuracy_score(y_holdout, knn_grid.predict(X_holdout))     best_param = knn_grid.best_params_['scaler__normalization'][affected_property]     print(affected_property,           'property:', searchArea[1, affected_property], &quot;=&gt;&quot;, best_param,           'holdout:', history_holdout_score[-1], &quot;=&gt;&quot;, holdout_score, '(', knn_grid.best_score_, ')')     # \u0410 \u0432\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u043f\u043e\u0438\u0441\u043a\u0430.     before = searchArea[:, affected_property]     propertySearchArea = searchArea[:, affected_property].copy()     if best_param == propertySearchArea[0]:         print('|&lt;&lt;')         searchArea[0, affected_property] = best_param\/2 if best_param &gt; 0.01 else 0         searchArea[2, affected_property] = (best_param + searchArea[2, affected_property])\/2         searchArea[1, affected_property] = best_param     elif best_param == propertySearchArea[2]:         print('&gt;&gt;|')         searchArea[2, affected_property] = (best_param + 1)\/2 if best_param &lt; 0.99 else 1         searchArea[0, affected_property] = (best_param + searchArea[0, affected_property])\/2         searchArea[1, affected_property] = best_param     elif best_param &lt; (propertySearchArea[0] + propertySearchArea[1])\/2:         print('&lt;&lt;')         searchArea[0, affected_property] = max(propertySearchArea[0]*1.1 - .1*propertySearchArea[1], 0)         searchArea[2, affected_property] = (best_param + propertySearchArea[2])\/2         searchArea[1, affected_property] = best_param     elif best_param &gt; (propertySearchArea[1] + propertySearchArea[2])\/2:         print('&gt;&gt;')         searchArea[0, affected_property] = (best_param + propertySearchArea[0])\/2         searchArea[2, affected_property] = min(propertySearchArea[2]*1.1 - .1*propertySearchArea[1], 1)         searchArea[1, affected_property] = best_param     elif best_param &lt; propertySearchArea[1]:         print('&lt;')         searchArea[2, affected_property] = searchArea[1, affected_property]*.25 + .75*searchArea[2, affected_property]         searchArea[1, affected_property] = best_param     elif best_param &gt; propertySearchArea[1]:         print('&gt;')         searchArea[0, affected_property] = searchArea[1, affected_property]*.25 + .75*searchArea[0, affected_property]         searchArea[1, affected_property] = best_param     else:         print('=')         searchArea[0, affected_property] = searchArea[1, affected_property]*.25 + .75*searchArea[0, affected_property]         searchArea[2, affected_property] = searchArea[1, affected_property]*.25 + .75*searchArea[2, affected_property]     normalization = searchArea[1,:].sum() #\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0435 \u0443\u0431\u0435\u0433\u0430\u043b\u0438 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u044c.     searchArea[:,:] \/= normalization     print(before, &quot;=&gt;&quot;,searchArea[:, affected_property])     history_parametrs.append(searchArea[1,:].copy())     history_holdout_score.append(holdout_score)      changePropertyNormalization(1, 9) changePropertyNormalization(1, 9) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u042f \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0438 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b, \u0438 \u0432 \u0438\u0442\u043e\u0433\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0448\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0433 \u0443 \u043c\u0435\u043d\u044f \u0447\u0443\u0442\u044c \u043d\u0435 \u043f\u043e\u043b \u0447\u0430\u0441\u0430 \u0441\u0447\u0438\u0442\u0430\u043b\u0441\u044f:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\u0418 \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0435\u0451 \u0432 \u0446\u0438\u043a\u043b\u0435 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 40 \u0440\u0430\u0437.<\/p>\n<pre><code class=\"python\">%%time # \u041f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435  searchArea = np.array([np.zeros((18,)), np.ones((18,)) \/18, np.ones((18,))]) print(searchArea[:,0])  history_parametrs = [searchArea[1,:].copy()] scaler = StandardAndPoorScaler(normalization=searchArea[1,:]) scaler.fit(X_train) knn = KNeighborsClassifier(n_neighbors = 7 , n_jobs=-1) knn.fit(scaler.transform(X_train), y_train) history_holdout_score = [accuracy_score(y_holdout, knn.predict(scaler.transform(X_holdout)))]  for tick in range(40):     for p in range(searchArea.shape[1]):         changePropertyNormalization(p, 7)      print(searchArea[1,:]) print(history_holdout_score)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043e\u0442 knn: 91.9% \u041b\u0443\u0447\u0448\u0435 \u0447\u0435\u043c \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0440\u0430\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443 \u0434\u0435\u0440\u0435\u0432\u0430. \u0418 \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435. \u0421\u0440\u0430\u0432\u043d\u0438\u043c \u0442\u043e \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0444\u0438\u0447 \u043f\u043e \u043c\u043d\u0435\u043d\u0438\u044e \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u0444\u0438\u0447 \u043f\u043e \u043c\u043d\u0435\u043d\u0438\u044e knn<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">feature_importances['knn_importance'] = history_parametrs[-1] diagramma = feature_importances.copy() indexes = diagramma.index diagramma.index = diagramma['features'] diagramma.drop('features', 1, inplace = True) diagramma.plot(kind='bar'); plt.savefig(&quot;images\/pic1.png&quot;, format = 'png') plt.show() feature_importances<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/kk\/pe\/nf\/kkpenftrnyfl6dpu4p1qh2dnwqq.gif\"><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ui\/o2\/rp\/uio2rplq9j2p5cxppq7jb7h_mpk.gif\"><\/p>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0435? \u0414\u0430, \u043f\u043e\u0445\u043e\u0436\u0435. \u041d\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435. \u0412 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0438\u0447 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#8216;Total night minutes&#8217; \u0438 &#8216;Total night charge&#8217;. \u0422\u0430\u043a \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, knn \u0441\u0430\u043c\u0430 \u0432\u044b\u043f\u0438\u043b\u0438\u043b\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0444\u0438\u0447.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u0444\u0430\u0439\u043b, \u0430 \u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0440\u0430\u0431\u043e\u0442\u0435&#8230;.<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">parametrs_df = pd.DataFrame(history_parametrs) parametrs_df['scores'] = history_holdout_score parametrs_df.index.name = 'index' parametrs_df.to_csv('parametrs_and_scores.csv') <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>  \u041d\u0443 \u0447\u0442\u043e \u0436\u0435, \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 .919 \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u043f\u043b\u043e\u0445 \u0434\u043b\u044f knn, \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u043f\u043e\u043b\u0442\u043e\u0440\u0430 \u0440\u0430\u0437\u0430 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0432 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0438 \u043d\u0430 7% \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u0433\u0434\u0430 feature_importance \u043c\u044b \u0432\u0437\u044f\u043b\u0438 \u0443 \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0433\u043e\u043d\u044f\u0442\u044c. \u041d\u043e \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c feature_importance \u043f\u043e \u043c\u043d\u0435\u043d\u0438\u044e \u0441\u0430\u043c\u043e\u0433\u043e knn. \u041e\u043d \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0441\u043a\u0430\u0437\u0430\u043b\u043e \u0434\u0435\u0440\u0435\u0432\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u043e \u0438 knn \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u043d\u0435\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0438\u0437 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0441 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0432\u0430\u0436\u043d\u044b.<\/p>\n<p>  \u041d\u0443 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f \u043d\u043e\u0432\u043e\u0435 \u0438 \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e\u0435, \u043e\u0431\u043b\u0430\u0434\u0430\u044f \u0437\u0430\u043f\u0430\u0441\u043e\u043c \u0437\u043d\u0430\u043d\u0438\u044f \u0442\u0440\u0451\u0445 \u043b\u0435\u043a\u0446\u0438\u0439 mlcourse.ai<\/p>\n<p>  ods \u0438 \u0433\u0443\u0433\u043b\u043e\u043c \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043f\u0438\u0442\u043e\u043d\u0443. \u041f\u043e-\u043c\u043e\u0435\u043c\u0443 \u043d\u0435\u043f\u043b\u043e\u0445\u043e.<\/p>\n<h2>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043b\u0430\u0439\u0434\u044b<\/h2>\n<p>  \u041f\u043e\u0431\u043e\u0447\u043d\u044b\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u043f\u0440\u043e\u0448\u0451\u043b. \u041f\u0443\u0442\u044c, \u043f\u0440\u0430\u0432\u0434\u0430, 18-\u043c\u0435\u0440\u043d\u044b\u0439, \u0447\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0436\u0435\u0447\u043a\u043e \u043c\u0435\u0448\u0430\u0435\u0442 \u0435\u0433\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u0438\u044e, \u043d\u0443 \u0438 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0432 \u0440\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0447\u0442\u043e \u0442\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u0435\u043b\u0430\u0435\u0442, \u0443\u0447\u0438\u0442\u0441\u044f \u0438\u043b\u0438 \u0444\u0438\u0433\u043d\u0451\u0439 \u0437\u0430\u043d\u044f\u0442, \u043d\u0435 \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u043e. \u041f\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 \u044d\u0442\u043e, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0438\u0434\u043d\u043e. \u041e\u0448\u0438\u0431\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0435 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0437\u0430\u043c\u0435\u0442\u043d\u043e, \u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u043d\u044f\u0442, \u043f\u043e\u043b\u0437\u0451\u0442 \u0432\u0434\u043e\u043b\u044c \u0434\u043b\u0438\u043d\u043d\u043e\u0439 \u0443\u0437\u043a\u043e\u0439 \u0434\u043e\u043b\u0438\u043d\u044b \u0432 \u0430\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044e, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u2014 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043f\u0440\u043e\u0435\u0446\u0438\u0440\u0443\u044e 18-\u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043d\u0430 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0435 \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u0430\u0434\u044b \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0445 \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u044b\u043b\u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u043c\u0438. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 18-\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e, \u0432 \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/221049\/\">\u041f\u043e\u0434\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0435\u043c \u0437\u0430 \u043c\u0435\u0442\u0430\u043d\u0438\u044f\u043c\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/a> \u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043b\u044e\u0431\u043e\u0432\u0430\u043b\u0441\u044f \u0437\u0430 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e\u043c \u0432\u0435\u0441\u043e\u0432 \u0432\u0441\u0435\u0445 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u0443 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0441\u0438\u043d\u0430\u043f\u0441\u043e\u0432 \u0438 \u043d\u0438\u0447\u0451 \u0442\u0430\u043a, \u0431\u044b\u043b\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u0435\u043d\u044c\u043a\u043e.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0441\u044c \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u0438\u043d\u043e\u0432\u0430\u0432 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u0430\u043f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">parametrs_df = pd.read_csv('parametrs_and_scores.csv', index_col = 'index') history_holdout_score = np.array(parametrs_df['scores']) parametrs_df.drop('scores',axis=1) history_parametrs = np.array(parametrs_df.drop('scores',axis=1))<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0451\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f c \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430. \u0422\u0443\u0442 \u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0442\u0430\u043d\u043e\u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0432\u0441\u044e \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0436\u0438\u0437\u043d\u044c, \u043d\u043e \u043c\u043d\u0435 \u0443\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0436\u0435\u0447\u043a\u043e \u043d\u0435\u043a\u043e\u0433\u0434\u0430. \ud83d\ude41<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0447\u0438\u0442\u044c\u0441\u044f.<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">last = history_holdout_score[-1] steps = np.arange(0, history_holdout_score.shape[0])[history_holdout_score != last].max() print(steps\/18)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  35.55555555555556<br \/>  \u0417\u0430 \u0440\u0430\u0437 \u043c\u044b \u043c\u0435\u043d\u044f\u043b\u0438 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0446\u0438\u043a\u043b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 18 \u0448\u0430\u0433\u043e\u0432. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e 36 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043e\u043a\u043e\u043b\u043e \u0442\u043e\u0433\u043e. \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 \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0443\u0447\u0430\u043b\u0441\u044f \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time # \u0417\u0430\u0434\u0430\u0451\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438: import matplotlib.pyplot as plt %matplotlib inline import random import math random.seed(17) property_projection = np.array([[math.sin(a), math.cos(a)] for a in [random.uniform(-math.pi, math.pi) for i in range(history_parametrs[0].shape[0])]]).transpose() history = np.array(history_parametrs[::18]) # \u041f\u043e\u043b\u043d\u044b\u0439 \u0446\u0438\u043a\u043b - 18 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. # \u041c\u043d\u0435 \u043c\u043e\u0437\u0433\u043e\u0432 \u043d\u0435 \u0437\u0432\u0430\u0442\u0430\u0435\u0442 \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u043d\u043e \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0435 \u043f\u043e\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u0431\u0435\u0437 \u0446\u0438\u043a\u043b\u043e\u0432. :( points = np.array([(history[i] * property_projection).sum(axis=1) for i in range(history.shape[0])]) plt.plot(points[:36,0],points[0:36,1]); plt.savefig(&quot;images\/pic2.png&quot;, format = 'png') plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jt\/zs\/rc\/jtzsrcgk60i_aeqhcvxjq9atvee.png\"><\/p>\n<p>  \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0443\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u0437\u0430 \u043f\u0435\u0440\u0432\u044b\u0445 \u0447\u0435\u0442\u044b\u0440\u0435 \u0448\u0430\u0433\u0430. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0443\u0442\u044c \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u0435\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 4-\u0445 \u0442\u043e\u0447\u0435\u043a<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">plt.plot(points[4:36,0],points[4:36,1]); plt.savefig(&quot;images\/pic3.png&quot;, format = 'png')<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/gq\/xh\/wa\/gqxhwawt9nnsmypgk3tkry9vbpw.png\"><\/p>\n<p>  \u041f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u043c \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0443\u0442\u0438 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043e\u0431\u0443\u0447\u0430\u043b\u043a\u0430 \u0434\u0435\u043b\u0430\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0430 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0435\u043c\u0441\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">plt.plot(points[14:36,0],points[14:36,1]); plt.savefig(&quot;images\/pic4.png&quot;, format = 'png') plt.show() plt.plot(points[24:36,0],points[24:36,1]); plt.plot(points[35:,0],points[35:,1], color = 'red'); plt.savefig(&quot;images\/pic5.png&quot;, format = 'png') plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/a5\/kq\/6m\/a5kq6mq5yxl3roojyjfzdw8wq8a.png\"><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g5\/lo\/gs\/g5logsa_jmna5lveoc-w0679koy.png\"><\/p>\n<p>  \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u043d\u043e \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f. \u041f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0441\u0432\u043e\u044e \u043f\u0443\u043d\u043a\u0442 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0442 \u0440\u0430\u043d\u0434\u043e\u043c\u0430 \u043f\u0440\u0438 \u043a\u0440\u043e\u0441\u0441\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442. \u041d\u043e \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043e\u0431\u0449\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0451\u0449\u0435\u0433\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u0430.<\/p>\n<p>  \u042f, \u043a\u0441\u0442\u0430\u0442\u0438, \u0440\u0430\u043d\u044c\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u0430\u043a\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u043a \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. <br \/>  \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0432\u0441\u044f \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0441\u043a\u043e\u043b\u044c-\u043a\u043e \u0442\u043e \u0448\u0430\u0433\u043e\u0432 \u0441\u043e \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430. \u041f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u00ab\u041f\u043e\u0434\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0435\u043c \u0437\u0430 \u043c\u0435\u0442\u0430\u043d\u0438\u044f\u043c\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438\u00bb. \u0418 \u0434\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0442\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0440\u0430\u0437\u0443 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442, \u0430 \u043f\u043e\u0447\u0435\u043c\u0443 \u0443 \u0432\u0441\u0435\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0432\u0435\u0441, \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c, \u0442\u043e \u0443 \u043d\u0438\u0445 \u0440\u0430\u0437\u043d\u0430\u044f. \u0412 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0440\u0430\u0437 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u0432\u0437\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u043d\u0430\u043f\u0441\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043c\u0435\u043d\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0432\u043e\u043e\u0440\u0443\u0436\u0451\u043d\u043d\u044b\u0439 \u043d\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e t-SNE \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0432 \u0442\u0430\u043a\u0443\u044e \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0451 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0443\u0447\u0448\u0435.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">t-SNE<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time import sklearn.manifold as manifold tsne = manifold.TSNE(random_state=19) tsne_representation = tsne.fit_transform(history) plt.plot(tsne_representation[:, 0], tsne_representation[:, 1]) plt.savefig(&quot;images\/pic6.png&quot;, format = 'png') plt.show();<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qe\/bp\/nn\/qebpnnz71ywbxgqvhzj3fpv8vzc.png\"><\/p>\n<p>  t-Sne \u043f\u043e\u0445\u043e\u0436\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u043b \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u0441\u0442\u043e \u0441\u044a\u0435\u043b \u043c\u0430\u0441\u0448\u0442\u0430\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u043e \u0442\u0435\u043c \u0444\u0438\u0447\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u0438 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u0447\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u043b \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0439. \u0412\u044b\u0432\u043e\u0434 \u2014 \u043d\u0435 \u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u043f\u043e\u0434\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0432 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0435.:\\<\/p>\n<h2>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u0442\u044c<\/h2>\n<p>  \u042f \u0435\u0449\u0451 \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044e \u0432\u043d\u0443\u0442\u0440\u044c tsne \u0447\u0442\u043e\u0431\u044b \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u0430. \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435 \u043a\u0440\u0430\u0441\u043e\u0442\u0430, \u0444\u0438\u0433\u043d\u044f \u043a\u0430\u043a\u0430\u044f-\u0442\u043e. \u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0412 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0432\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0443\u0447\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u0434\u0430 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u044a\u0435\u043a\u0438\u0438 \u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043d\u0438 \u043d\u0435 \u0440\u0430 \u0431\u043e\u0442\u0430\u044e\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e\u0441\u044f \u0432 <b>sklearn.manifold.t_sne<\/b> \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>_gradient_descent<\/b>, \u0430 \u043e\u043d\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043f\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u0442\u0430\u043a \u0438 \u043f\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044e \u0441 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438. \u0422\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0445\u043e\u0434\u0438 \u0443 \u0441\u0435\u0431\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0432\u044b\u043a\u043e\u0432\u044b\u0440\u0438\u0432\u0430\u0435\u043c \u043e\u0442\u0442\u0443\u0434\u0430 \u0432\u0430\u0448\u0443 \u0432\u0435\u0440\u0441\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u0451 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043c\u043f\u044b \u0432 \u0432\u0430\u0448\u0443 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0432\u0430\u0448\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e:<\/p>\n<p>  positions.append(p.copy()) # We save the current position.<\/p>\n<p>  \u0410 \u043f\u043e\u0442\u043e\u043c \u0442\u0438\u043f\u0430 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0442\u043e \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">from time import time from scipy import linalg # This list will contain the positions of the map points at every iteration. positions = [] def _gradient_descent(objective, p0, it, n_iter,                       n_iter_check=1, n_iter_without_progress=300,                       momentum=0.8, learning_rate=200.0, min_gain=0.01,                       min_grad_norm=1e-7, verbose=0, args=None, kwargs=None):     # The documentation of this function can be found in scikit-learn's code.     if args is None:         args = []     if kwargs is None:         kwargs = {}      p = p0.copy().ravel()     update = np.zeros_like(p)     gains = np.ones_like(p)     error = np.finfo(np.float).max     best_error = np.finfo(np.float).max     best_iter = i = it      tic = time()     for i in range(it, n_iter):         positions.append(p.copy()) # We save the current position.                  check_convergence = (i + 1) % n_iter_check == 0         # only compute the error when needed         kwargs['compute_error'] = check_convergence or i == n_iter - 1          error, grad = objective(p, *args, **kwargs)         grad_norm = linalg.norm(grad)          inc = update * grad &lt; 0.0         dec = np.invert(inc)         gains[inc] += 0.2         gains[dec] *= 0.8         np.clip(gains, min_gain, np.inf, out=gains)         grad *= gains         update = momentum * update - learning_rate * grad         p += update          if check_convergence:             toc = time()             duration = toc - tic             tic = toc              if verbose &gt;= 2:                 print(&quot;[t-SNE] Iteration %d: error = %.7f,&quot;                       &quot; gradient norm = %.7f&quot;                       &quot; (%s iterations in %0.3fs)&quot;                       % (i + 1, error, grad_norm, n_iter_check, duration))              if error &lt; best_error:                 best_error = error                 best_iter = i             elif i - best_iter &gt; n_iter_without_progress:                 if verbose &gt;= 2:                     print(&quot;[t-SNE] Iteration %d: did not make any progress &quot;                           &quot;during the last %d episodes. Finished.&quot;                           % (i + 1, n_iter_without_progress))                 break             if grad_norm &lt;= min_grad_norm:                 if verbose &gt;= 2:                     print(&quot;[t-SNE] Iteration %d: gradient norm %f. Finished.&quot;                           % (i + 1, grad_norm))                 break      return p, error, i  manifold.t_sne._gradient_descent = _gradient_descent<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c &#39;&#39;\u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439&#39;&#39; t-SNE<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">tsne_representation = manifold.TSNE(random_state=17).fit_transform(history) X_iter = np.dstack(position.reshape(-1, 2) for position in positions) position_reshape = [position.reshape(-1, 2) for position in positions] print(position_reshape[0].shape) print('[0] min', position_reshape[0][:,0].min(),'max', position_reshape[0][:,0].max()) print('[1] min', position_reshape[1][:,0].min(),'max', position_reshape[1][:,0].max()) print('[2] min', position_reshape[2][:,0].min(),'max', position_reshape[2][:,0].max()) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  (41, 2)<br \/>  [0] min -0.00018188123 max 0.00027207955<br \/>  [1] min -0.05136269 max 0.032607622<br \/>  [2] min -4.392309 max 7.9074526<br \/>  \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043b\u044f\u0448\u0443\u0442 \u0432 \u043e\u0447\u0435\u043d\u044c \u0448\u0438\u0440\u043e\u043a\u0438\u0445 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0438\u0445 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u044e \u0438\u0445. \u041d\u0430 \u0446\u0438\u043a\u043b\u0430\u0445 \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043f\u0435\u0446 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e. \ud83d\ude41<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u044e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time from sklearn.preprocessing import MinMaxScaler minMaxScaler = MinMaxScaler() minMaxScaler.fit_transform(position_reshape[0]) position_reshape = [minMaxScaler.fit_transform(frame) for frame in position_reshape] position_reshape[0].min(), position_reshape[0].max()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410\u043d\u0438\u043c\u0438\u0440\u0443\u044e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">%%time  from matplotlib.animation import FuncAnimation, PillowWriter #plt.style.use('seaborn-pastel')  fig = plt.figure()  ax = plt.axes(xlim=(0, 1), ylim=(0, 1)) line, = ax.plot([], [], lw=3)  def init():     line.set_data([], [])     return line, def animate(i):     x = position_reshape[i][:,0]     y = position_reshape[i][:,1]     line.set_data(x, y)     return line,  anim = FuncAnimation(fig, animate, init_func=init, frames=36, interval=20, blit=True, repeat_delay = 1000) anim.save('images\/animate_tsne_learning.gif', writer=PillowWriter(fps=5)) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/lh\/dq\/g6\/lhdqg6khzhplw6jtkei6y0s3pdu.gif\"><\/p>\n<p>  \u041f\u043e\u0443\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u043f\u043b\u0430\u043d\u0435 \u043d\u0430\u0432\u044b\u043a\u043e\u0432, \u043d\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u0438 \u043d\u0435\u043a\u0440\u0430\u0441\u0438\u0432\u043e.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u044f \u043f\u0440\u043e\u0449\u0430\u044e\u0441\u044c \u0441 \u0432\u0430\u043c\u0438. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0438\u0434\u0435\u044f, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0438\u0437 knn \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0446\u0435\u0434\u0438\u0442\u044c \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0443\u0441\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430, \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u043e\u0440\u0430\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 \u044d\u0442\u043e\u043c \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0438\u0440\u0443 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0447\u0443\u043c\u044b.<\/p><\/div>\n<p> \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\/496484\/\"> https:\/\/habr.com\/ru\/post\/496484\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/496484\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/eg\/qm\/x6\/egqmx63h8mgrbxfytg9nmuaby-g.gif\" alt=\"\u0418\u0441\u0442\u0438\u043d\u043d\u044b\u0439 \u0435\u0440\u0443\u043d\u0434\u0443\u043a \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u043d\u0438\u043c\u043e\u0435, \u043d\u043e \u0438 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0435\u0440\u0435\u0433\u0430\u044e\u0449\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c\"><\/div>\n<p>  \u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044f \u0441 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u043a\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u0432 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u043e\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 18 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u043d\u0430 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0437\u044f\u0442\u044c \u0438 \u0433\u0440\u0443\u0431\u043e\u0439 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u0441\u0438\u043b\u043e\u0439.<\/p>\n<p>  \u041e\u0431\u0443\u0447\u0430\u044f\u0441\u044c \u0447\u0435\u043c\u0443-\u0442\u043e \u043c\u043d\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434. \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435. \u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043e \u0434\u043e \u043c\u0435\u043d\u044f. \u041d\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044f \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u043f\u0443\u0442\u044c \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u0434\u043e\u043b\u0433\u043e \u0434\u043e \u043c\u0435\u043d\u044f, \u0432 \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u044f \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0433\u043b\u0443\u0431\u0438\u043d\u043d\u044b\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439. \u041a \u0447\u0435\u043c\u0443 \u0438 \u0432\u0430\u0441 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e.<\/p>\n<p>  \u0412 Python \u0438 DS \u044f, \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u044f\u0433\u043a\u043e, \u043d\u043e\u0432\u0438\u0447\u043e\u043a, \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u0435\u0449\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0441\u043a\u043e\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0435 \u0434\u0435\u043b\u0430\u044e \u043a\u043e\u0434\u043e\u043c, \u0437\u0430 \u0447\u0442\u043e Python \u043d\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432 \u0440\u0430\u0437\u044b, \u0430 \u043d\u0430 \u043f\u043e\u0440\u044f\u0434\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0435\u0441\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u044f \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0435\u0442\u0435 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u2014 \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c, \u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u0442\u0430\u043c, \u0438\u043b\u0438 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. <a href=\"https:\/\/github.com\/kraidiky\/GDforHyperparameters\" rel=\"nofollow\">https:\/\/github.com\/kraidiky\/GDforHyperparameters<\/a><\/p>\n<p>  \u0422\u0435\u043c, \u043a\u0442\u043e \u0443\u0436\u0435 \u043a\u0440\u0443\u0442\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0430\u0442\u0430\u043d\u0438\u0441\u0442, \u0438 \u0432\u0441\u0451 \u0432 \u044d\u0442\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043d\u0435\u0431\u0435\u0437\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0431\u0443\u0434\u0435\u0442, \u044f \u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u043a\u0435.  <\/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-301612","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301612","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=301612"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301612\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=301612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=301612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=301612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}