{"id":379641,"date":"2024-06-25T03:19:06","date_gmt":"2024-06-25T03:19:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=379641"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=379641","title":{"rendered":"<span>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div class=\"floating-image\">\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c12\/7e4\/466\/c127e4466dcf0d60f7a18712fcd19883.png\" width=\"767\" height=\"436\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c12\/7e4\/466\/c127e4466dcf0d60f7a18712fcd19883.png\"\/><\/figure>\n<p>\u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0435\u0451 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u043c \u0432\u044b\u0432\u043e\u0434\u0430\u043c \u0438, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u043a \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044e \u043d\u0435 \u0441\u0430\u043c\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0435\u0442\u0440\u0438\u043a, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043a\u0430\u043a bias-variance decomposition. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u0435\u0442\u0440\u0438\u043a \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0443\u0447\u043d\u044b\u0435 \u0440\u0430\u0441\u0447\u0451\u0442\u044b \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043d\u0443\u043b\u044f \u043d\u0430 Python, \u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/div>\n<blockquote>\n<p><strong>? <em>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c:<\/em><\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/804605\/\" rel=\"noopener noreferrer nofollow\"><em>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ML-\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0441 \u043d\u0443\u043b\u044f \u043d\u0430 Python<\/em><\/a><\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p><em>\u041d\u043e\u0443\u0442\u0431\u0443\u043a \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043d\u0430<\/em> <strong><em>GitHub<\/em><\/strong> (<a href=\"https:\/\/github.com\/egaoharu-kensei\/ML-algorithms-from-scratch.-Course-for-beginners\/blob\/main\/Notebooks%20%5Brus%5D\/08%29%20%D0%9C%D0%B5%D1%82%D1%80%D0%B8%D0%BA%D0%B8%20%D0%BA%D0%B0%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%B0%20%D0%B8%20%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7%20%D0%BE%D1%88%D0%B8%D0%B1%D0%BE%D0%BA%20%D0%B2%20ML.ipynb\" rel=\"noopener noreferrer nofollow\"><em>rus<\/em><\/a><em>, <\/em><a href=\"https:\/\/github.com\/egaoharu-kensei\/ML-algorithms-from-scratch.-Course-for-beginners\/blob\/main\/Notebooks%20%5Beng%5D\/08%29%20Quality%20metrics%20and%20error%20analysis%20in%20ML.ipynb\" rel=\"noopener noreferrer nofollow\"><em>eng<\/em><\/a>) \u0438 <strong><em>Kaggle<\/em><\/strong> (<a href=\"https:\/\/www.kaggle.com\/code\/egazakharenko\/quality-metrics-and-error-analysis-in-ml-guide\" rel=\"noopener noreferrer nofollow\"><em>eng<\/em><\/a>)<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<h3>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h3>\n<ul>\n<li>\n<p><a href=\"#classification_metrics\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#regression_metrics\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#bias-variance\" rel=\"noopener noreferrer nofollow\">\u0410\u043d\u0430\u043b\u0438\u0437 \u043e\u0448\u0438\u0431\u043e\u043a (bias-variance decomposition)<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#clustering_metrics\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#additional_sources\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/a><\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><a class=\"anchor\" name=\"classification_metrics\" id=\"classification_metrics\"><\/a><\/p>\n<h3>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0441\u0442\u043e\u0438\u0442 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a (confusion matrix) \u0438 \u0435\u0451 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/359\/341\/fa9\/359341fa958b373e332686254b4e84d4.png\" width=\"1215\" height=\"609\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/359\/341\/fa9\/359341fa958b373e332686254b4e84d4.png\"\/><\/figure>\n<p>\u041d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (TP) \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (TN) \u043a\u043b\u0430\u0441\u0441\u044b, \u0430 \u043d\u0430 \u043f\u043e\u0431\u043e\u0447\u043d\u043e\u0439 \u2014 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0451 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e (FP) \u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e (FN) \u0440\u043e\u0434\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0443\u0447\u0438\u043c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044e \u043d\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 <a href=\"https:\/\/www.kaggle.com\/datasets\/uciml\/breast-cancer-wisconsin-data\" rel=\"noopener noreferrer nofollow\">Breast Cancer Wisconsin<\/a> \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0435\u0451 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u0434\u0430\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0441\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0432 scikit-learn \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0448\u0435, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0443\u0442\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e: <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"| TN \\ \\ FP | \\\\ | FN  \\ \\ TP |\" alt=\"| TN \\ \\ FP | \\\\ | FN  \\ \\ TP |\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4bc\/e15\/62d\/4bce1562d5b3deef7fdc5537965ae0f1.svg\" width=\"697\" height=\"50\"\/><\/p>\n<p><strong>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/strong>  <\/p>\n<pre><code class=\"python\">import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import confusion_matrix from sklearn.preprocessing import LabelEncoder from sklearn.metrics import (accuracy_score, precision_score, recall_score, f1_score,                              fbeta_score, roc_curve, roc_auc_score, precision_recall_curve,                              auc, average_precision_score, classification_report)<\/code><\/pre>\n<p><strong>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/strong><\/p>\n<pre><code class=\"python\">df_path = \"\/content\/drive\/MyDrive\/breast_cancer.csv\" breast_cancer = pd.read_csv(df_path) breast_cancer.drop(columns=['id','Unnamed: 32'], inplace=True) print(breast_cancer)  X = breast_cancer.drop(columns='diagnosis', axis=1) y = breast_cancer['diagnosis'] y = LabelEncoder().fit_transform(y)  # 1 - Malignant, 0 - Benign X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)       diagnosis  radius_mean  texture_mean  perimeter_mean  area_mean  \\ 0           M        17.99         10.38          122.80     1001.0    1           M        20.57         17.77          132.90     1326.0    2           M        19.69         21.25          130.00     1203.0    3           M        11.42         20.38           77.58      386.1    4           M        20.29         14.34          135.10     1297.0    ..        ...          ...           ...             ...        ...    564         M        21.56         22.39          142.00     1479.0    565         M        20.13         28.25          131.20     1261.0    566         M        16.60         28.08          108.30      858.1    567         M        20.60         29.33          140.10     1265.0    568         B         7.76         24.54           47.92      181.0          smoothness_mean  compactness_mean  concavity_mean  concave points_mean  \\ 0            0.11840           0.27760         0.30010              0.14710    1            0.08474           0.07864         0.08690              0.07017    2            0.10960           0.15990         0.19740              0.12790    3            0.14250           0.28390         0.24140              0.10520    4            0.10030           0.13280         0.19800              0.10430    ..               ...               ...             ...                  ...    564          0.11100           0.11590         0.24390              0.13890    565          0.09780           0.10340         0.14400              0.09791    566          0.08455           0.10230         0.09251              0.05302    567          0.11780           0.27700         0.35140              0.15200    568          0.05263           0.04362         0.00000              0.00000          symmetry_mean  ...  radius_worst  texture_worst  perimeter_worst  \\ 0           0.2419  ...        25.380          17.33           184.60    1           0.1812  ...        24.990          23.41           158.80    2           0.2069  ...        23.570          25.53           152.50    3           0.2597  ...        14.910          26.50            98.87    4           0.1809  ...        22.540          16.67           152.20    ..             ...  ...           ...            ...              ...    564         0.1726  ...        25.450          26.40           166.10    565         0.1752  ...        23.690          38.25           155.00    566         0.1590  ...        18.980          34.12           126.70    567         0.2397  ...        25.740          39.42           184.60    568         0.1587  ...         9.456          30.37            59.16          area_worst  smoothness_worst  compactness_worst  concavity_worst  \\ 0        2019.0           0.16220            0.66560           0.7119    1        1956.0           0.12380            0.18660           0.2416    2        1709.0           0.14440            0.42450           0.4504    3         567.7           0.20980            0.86630           0.6869    4        1575.0           0.13740            0.20500           0.4000    ..          ...               ...                ...              ...    564      2027.0           0.14100            0.21130           0.4107    565      1731.0           0.11660            0.19220           0.3215    566      1124.0           0.11390            0.30940           0.3403    567      1821.0           0.16500            0.86810           0.9387    568       268.6           0.08996            0.06444           0.0000          concave points_worst  symmetry_worst  fractal_dimension_worst   0                  0.2654          0.4601                  0.11890   1                  0.1860          0.2750                  0.08902   2                  0.2430          0.3613                  0.08758   3                  0.2575          0.6638                  0.17300   4                  0.1625          0.2364                  0.07678   ..                    ...             ...                      ...   564                0.2216          0.2060                  0.07115   565                0.1628          0.2572                  0.06637   566                0.1418          0.2218                  0.07820   567                0.2650          0.4087                  0.12400   568                0.0000          0.2871                  0.07039    [569 rows x 31 columns]<\/code><\/pre>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/strong> <\/p>\n<pre><code class=\"python\">model = LogisticRegression(max_iter=10000) model.fit(X_train, y_train) y_pred = model.predict(X_test) print(y_pred)   [1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0  1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 0 0  1 0 0 0 0 0 1 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 1 0  1 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1]<\/code><\/pre>\n<p><strong>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f confusion matrix<\/strong><\/p>\n<pre><code class=\"python\">conf_matrix = confusion_matrix(y_test, y_pred)  sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Reds') plt.title('Confusion Matrix') plt.xlabel('Predicted Label') plt.ylabel('True Label') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bca\/6f8\/104\/bca6f8104ede3cdb2d59ad0a5ef5bf9b.png\" width=\"530\" height=\"455\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bca\/6f8\/104\/bca6f8104ede3cdb2d59ad0a5ef5bf9b.png\"\/><\/figure>\n<p>\u0413\u043b\u044f\u0434\u044f \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>(True Positive) \u2014 52 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u043d\u044b\u0435 \u0438 \u043e\u043d\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u0435\u0440\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>(True Negative) \u2014 84 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0437\u0434\u043e\u0440\u043e\u0432\u044b\u0435 \u0438 \u043e\u043d\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u0435\u0440\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>(False Positive) \u2014 6 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u043d\u044b\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u0438\u043c\u0435\u044e\u0442 \u0437\u043b\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u043f\u0443\u0445\u043e\u043b\u044c), \u043d\u043e \u043e\u043d\u0438 \u0437\u0434\u043e\u0440\u043e\u0432\u044b\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043f\u0443\u0445\u043e\u043b\u044c \u0434\u043e\u0431\u0440\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f);<\/p>\n<\/li>\n<li>\n<p>(False Negative) \u2014 1 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043a\u0430\u043a \u0437\u0434\u043e\u0440\u043e\u0432\u044b\u0439, \u043d\u043e \u043e\u043d \u0431\u043e\u043b\u0435\u043d (\u0442\u043e \u0435\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442 \u0437\u043b\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u043f\u0443\u0445\u043e\u043b\u044c).<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u0441\u0430\u043c\u0438\u043c \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c.<\/p>\n<h4>Accuracy<\/h4>\n<p>\u0421\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f\u00a0<strong>Accuracy<\/strong>\u00a0\u0438\u043b\u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u043e\u043b\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{Accuracy} = \\frac{1}{N} \\sum_{i=1}^{N} I [y_i = \\hat y_i] = \\frac{TP + TN}{TP + TN + FP + FN}\" alt=\"\\text{Accuracy} = \\frac{1}{N} \\sum_{i=1}^{N} I [y_i = \\hat y_i] = \\frac{TP + TN}{TP + TN + FP + FN}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/11a\/6ae\/914\/11a6ae9146968fa4890e067eaea12bd3.svg\" width=\"465\" height=\"60\"\/><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Accuracy \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\frac{52 + 84}{52 + 84 + 6 + 1} = 0.951048951048951\" alt=\"\\frac{52 + 84}{52 + 84 + 6 + 1} = 0.951048951048951\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/80b\/e78\/df3\/80be78df348e9221e35c333b261b22eb.svg\" width=\"321\" height=\"44\"\/><\/p>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u043e\u043b\u044e \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439\u00a0<strong>Error rate<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"1 - \\text{Accuracy} = 1 - 0.951048951048951 = 0.04895104895104896\" alt=\"1 - \\text{Accuracy} = 1 - 0.951048951048951 = 0.04895104895104896\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9c1\/bab\/8fc\/9c1bab8fcf9439f9225f32718e70adee.svg\" width=\"535\" height=\"20\"\/><\/p>\n<pre><code class=\"python\">accuracy = accuracy_score(y_test, y_pred) error_rate = 1 - accuracy print(f'Accuracy: {accuracy}') print(f'Error rate: {error_rate}')   Accuracy: 0.951048951048951 Error rate: 0.04895104895104896<\/code><\/pre>\n<p>\u041d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0441\u0432\u043e\u044e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c, Accuracy \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u0432: \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0430\u0434 \u0434\u0440\u0443\u0433\u0438\u043c, \u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0430 \u0432 \u0435\u0433\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u0443, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0430\u0436\u0430\u0442\u044c \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0434\u0430\u0451\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0438\u043f\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u043b\u043e\u0436\u043d\u043e\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0446\u0435\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u043e\u0440\u043e\u0433\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438.<\/p>\n<h4>Precision<\/h4>\n<p>\u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u0442 \u0434\u043e\u043b\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u043a\u0430\u043a \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{Precision} = TPR = \\frac{TP}{TP + FP} = \\frac{52}{52 + 6} = 0.896551724137931\" alt=\"\\text{Precision} = TPR = \\frac{TP}{TP + FP} = \\frac{52}{52 + 6} = 0.896551724137931\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/292\/4d5\/181\/2924d5181bf2f5e794c45dff48cc3b0e.svg\" width=\"529\" height=\"44\"\/><\/p>\n<pre><code class=\"python\">precision = precision_score(y_test, y_pred) print(precision)   0.896551724137931<\/code><\/pre>\n<h4>Recall (TPR)<\/h4>\n<p>\u0415\u0449\u0451 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u043a\u0430\u043a True Positive Rate, \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u043e\u043b\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{Recall} = \\frac{TP}{TP + FN} = \\frac{52}{52 + 1} = 0.9811320754716981\" alt=\"\\text{Recall} = \\frac{TP}{TP + FN} = \\frac{52}{52 + 1} = 0.9811320754716981\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/91b\/ec2\/682\/91bec268296ec683d84380c25bc444d3.svg\" width=\"448\" height=\"44\"\/><\/p>\n<pre><code class=\"python\">recall = recall_score(y_test, y_pred) print(recall)   0.9811320754716981<\/code><\/pre>\n<p>\u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043b\u043e\u0436\u043d\u043e\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432, \u0442\u0435\u043c \u0432\u044b\u0448\u0435 Recall \u0438\u043b\u0438 TPR. \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0440\u0430\u043a\u0430 \u0433\u0440\u0443\u0434\u0438, \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u043c\u0438, \u0447\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u043a\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0437\u043b\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0443\u0445\u043e\u043b\u0435\u0439 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c.  <\/p>\n<h4>FPR<\/h4>\n<p>False Positive Rate \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u0442 \u0434\u043e\u043b\u044e \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u0431\u043e\u043b\u0435\u0432\u0430\u043d\u0438\u044f (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u043a\u0430 \u0433\u0440\u0443\u0434\u0438), \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442 (\u0434\u043e\u0431\u0440\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0437\u0446\u044b, \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u0440\u0430\u043a\u043e\u0432\u044b\u0435 \u043e\u0442 \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u0431\u0440\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432).<\/p>\n<p>\u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a \u0441\u0442\u043e\u0438\u0442 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ecb\/dba\/c5f\/ecbdbac5f89ecb0bc48ce6562416b702.png\" width=\"924\" height=\"409\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ecb\/dba\/c5f\/ecbdbac5f89ecb0bc48ce6562416b702.png\"\/><\/figure>\n<h4>F1-score<\/h4>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0433\u0430\u0440\u043c\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043c\u0435\u0436\u0434\u0443 Precision \u0438 Recall, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0431\u0430\u043b\u0430\u043d\u0441, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0437\u043b\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438, \u043d\u043e \u0438 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0437\u043b\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0443\u0445\u043e\u043b\u0435\u0439.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{F1-score} = 2 \\cdot \\frac{precision \\cdot recall}{precision + recall} \\approx 2 \\frac{0.8966 \\cdot 0.9811}{0.8966 + 0.9811} \\approx 0.936948671246738\" alt=\"\\text{F1-score} = 2 \\cdot \\frac{precision \\cdot recall}{precision + recall} \\approx 2 \\frac{0.8966 \\cdot 0.9811}{0.8966 + 0.9811} \\approx 0.936948671246738\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/714\/580\/c0e\/714580c0eed5a40e621c8037d2a6b7b8.svg\" width=\"636\" height=\"46\"\/><\/p>\n<pre><code class=\"python\">f1 = f1_score(y_test, y_pred) print(f1)   0.9369369369369369<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e F1-score \u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e Precision \u0438 Recall \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0432\u0435\u0441) \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043c\u0435\u0442\u0440\u0438\u043a, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{F}_{\\beta}\" alt=\"\\text{F}_{\\beta}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dbd\/77c\/ea3\/dbd77cea365fd5551edb1efd4446e7ae.svg\" width=\"22\" height=\"22\"\/><strong>&#8212; score<\/strong>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{F}_{\\beta}= (1 + \\beta^2) \\cdot \\frac{precision \\cdot recall}{\\beta^2 \\cdot precision + recall}\" alt=\"\\text{F}_{\\beta}= (1 + \\beta^2) \\cdot \\frac{precision \\cdot recall}{\\beta^2 \\cdot precision + recall}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ace\/2ba\/c67\/ace2bac67eff6240c54778763fe99ba3.svg\" width=\"321\" height=\"47\"\/><\/p>\n<p>\u041f\u0440\u0438\u00a0<img class=\"formula inline\" source=\"\\beta > 1&#8243; alt=&#187;\\beta > 1&#8243; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/da3\/d7c\/877\/da3d7c877f3fddeb24980b580247ee22.svg&#187; width=&#187;46&#8243; height=&#187;20&#8243;\/>\u00a0\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0434\u0430\u0451\u0442\u0441\u044f Recall, \u0430 \u043f\u0440\u0438\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\beta &lt; 1\" alt=\"\\beta &lt; 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bcf\/6ff\/9eb\/bcf6ff9eb58d85ec56609388efad6219.svg\" width=\"46\" height=\"20\"\/>\u00a0\u2014 Precision. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0443\u0445\u043e\u043b\u044f\u0445, \u0442\u043e \u043c\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\beta\" alt=\"\\beta\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/666\/45e\/767\/66645e7676d393ae6a79c37ff54bcc10.svg\" width=\"11\" height=\"20\"\/>, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 (\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u043d\u0435\u0442 \u0440\u0430\u043a\u0430, \u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u0442\u044c), \u0442\u043e \u043c\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\beta\" alt=\"\\beta\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/675\/9ee\/cd0\/6759eecd0564230cde937a872aa6b613.svg\" width=\"11\" height=\"20\"\/>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\beta = 2\" alt=\"\\beta = 2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/022\/cca\/3cd\/022cca3cdd914ddbc76df5662fb6ee70.svg\" width=\"46\" height=\"20\"\/>\u00a0\u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"F_2 \\approx (1 + 2^2) \\cdot \\frac{0.8966 \\cdot 0.9811}{2^2 \\cdot 0.8966 + 0.9811} \\approx 0.9629493814997262\" alt=\"F_2 \\approx (1 + 2^2) \\cdot \\frac{0.8966 \\cdot 0.9811}{2^2 \\cdot 0.8966 + 0.9811} \\approx 0.9629493814997262\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1d0\/177\/811\/1d0177811e4b19d42bd5014d80dd1692.svg\" width=\"492\" height=\"46\"\/><\/p>\n<pre><code class=\"python\">f2 = fbeta_score(y_test, y_pred, beta=2) print(f2)   0.9629629629629629<\/code><\/pre>\n<h4>ROC-AUC<\/h4>\n<p>\u0412\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u043e\u0433\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f AUC-\u043f\u043b\u043e\u0449\u0430\u0434\u044c (Area Under Curve) \u043f\u043e\u0434 ROC-\u043a\u0440\u0438\u0432\u043e\u0439 (Receiver Operating Characteristics curve), \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043d\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 (TPR) \u043a \u0434\u043e\u043b\u0438 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 (FPR).<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/395\/2ec\/91c\/3952ec91c41a5170f20b7ba0a8b5de48.png\" width=\"629\" height=\"345\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/395\/2ec\/91c\/3952ec91c41a5170f20b7ba0a8b5de48.png\"\/><\/figure>\n<p>\u0412 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 ROC-\u043a\u0440\u0438\u0432\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u0432 \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u043b\u0435\u0432\u044b\u0439 \u0443\u0433\u043e\u043b (TPR=1 \u0438 FPR=0), \u0430 \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e\u0434 \u043d\u0435\u0439 (AUC) \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0435. \u041f\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u043f\u043b\u043e\u0449\u0430\u0434\u0438 0.5 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c\u0443 \u0443\u0433\u0430\u0434\u044b\u0432\u0430\u043d\u0438\u044e, \u043d\u0443 \u0430 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 0.5, \u0442\u043e, \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c \u2014 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043b\u043e\u0449\u0430\u0434\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 0.5.<\/p>\n<p>\u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0434\u0430\u043d\u043d\u0443\u044e \u043c\u0435\u0442\u0440\u0438\u043a\u0443 \u0441 \u043d\u0443\u043b\u044f. \u0412 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0448\u0430\u0433\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>1) \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>2) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f (\u0431\u0438\u043d\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u044f) \u043c\u0435\u0442\u043e\u043a \u043d\u0430 1 \u0438 0, \u0430 \u043d\u0430 \u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f FPR \u0438 TPR;<\/p>\n<\/li>\n<li>\n<p>3) \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 FPR \u0438 TPR \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 AUC \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0440\u0430\u043f\u0435\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"AUC = \\sum_{i=1}^{n-1} \\frac{TPR_i + TPR_{i+1}}{2} (FPR_{i+1} - FPR_i)\" alt=\"AUC = \\sum_{i=1}^{n-1} \\frac{TPR_i + TPR_{i+1}}{2} (FPR_{i+1} - FPR_i)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/703\/1a4\/2fc\/7031a42fc5ecc4bb8ab7cfe23f5d0585.svg\" width=\"404\" height=\"60\"\/><\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 ROC-\u043a\u0440\u0438\u0432\u043e\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u043e\u0440\u043e\u0433\u0438, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435. \u0427\u0442\u043e \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442? \u041f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u0430\u044f \u0438 \u0435\u0441\u043b\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u0442\u043e\u0447\u043a\u0430, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u043d\u0430 \u0442\u043e\u043c \u0436\u0435 \u0443\u0440\u043e\u0432\u043d\u0435, \u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 ROC-\u043a\u0440\u0438\u0432\u043e\u0439. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f ROC-\u043a\u0440\u0438\u0432\u043e\u0439 \u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043f\u043b\u043e\u0449\u0430\u0434\u0438 \u043f\u043e\u0434 \u043d\u0435\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043b\u0438\u0448\u044c \u0443\u0433\u043b\u043e\u0432\u044b\u0435 \u0442\u043e\u0447\u043a\u0438, \u0447\u0442\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043b\u0451\u0433\u043a\u0438\u0435 ROC-\u043a\u0440\u0438\u0432\u044b\u0435. \u0414\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ul>\n<li>\n<p>1) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0440\u043e\u0433\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u0438\u043d\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u043a, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f FP \u0438 TP;<\/p>\n<\/li>\n<li>\n<p>2) \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 FP \u0438 TP \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0439;<\/p>\n<\/li>\n<li>\n<p>3) \u0432 \u043c\u0435\u0441\u0442\u0430\u0445, \u0433\u0434\u0435 \u0432\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f \u043d\u0435 \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e, \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0443\u0433\u043b\u043e\u0432\u044b\u0435 \u0442\u043e\u0447\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p>4) \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0443\u0433\u043b\u043e\u0432\u044b\u0445 \u0442\u043e\u0447\u0435\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u043e\u0432, FP \u0438 TP;<\/p>\n<\/li>\n<li>\n<p>5) \u043a \u0441\u043f\u0438\u0441\u043a\u0443 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 FP \u0438 TP \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0443\u043b\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e, \u0447\u0442\u043e\u0431\u044b ROC-\u043a\u0440\u0438\u0432\u0430\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u0447\u043a\u0435 (0, 0); \u0430 \u043a \u0441\u043f\u0438\u0441\u043a\u0443 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u043e\u0432 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 y_score + 1, \u0447\u0442\u043e\u0431\u044b ROC-\u043a\u0440\u0438\u0432\u0430\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u0435\u0434\u0438\u043d\u0438\u0446\u0435 \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u043e\u0431\u0440\u0430\u0437\u0446\u044b \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b;<\/p>\n<\/li>\n<li>\n<p>6) \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 FP \u0438 TP \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 FPR \u0438 TPR, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 AUC \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0440\u0430\u043f\u0435\u0446\u0438\u0439.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043d\u0443\u043b\u044f<\/strong>  <\/p>\n<pre><code class=\"python\">def binary_roc_curve(y_true, y_score):     thresholds = np.sort(y_score)[::-1]     tps = np.array([])   # True positives     fps = np.array([])   # False positives      for threshold in thresholds:         # predictions binarization by each threshold         y_pred = (y_score >= threshold).astype(int)         tp = np.sum((y_true == 1) &amp; (y_pred == 1))         fp = np.sum((y_true == 0) &amp; (y_pred == 1))         tps = np.append(tps, tp)         fps = np.append(fps, fp)      # find optimal (corner) points (thresholds)     corner_point = True     d2_fps = np.diff(fps, 2)   # is used as a \"second derivative\"     d2_tps = np.diff(tps, 2)     is_corner_points = np.r_[corner_point, np.logical_or(d2_fps, d2_tps), corner_point]     optimal_indexes = np.where(is_corner_points == corner_point)[0]      # add an extra threshold position to optimal values to make sure that the curve starts     # at (0, 0) and also ends in 1 even if all samples are incorrectly classified     optimal_fps = np.r_[0, fps[optimal_indexes]]     optimal_tps = np.r_[0, tps[optimal_indexes]]     optimal_thresholds = np.r_[max(y_score) + 1, thresholds[optimal_indexes]]      optimal_fpr = optimal_fps \/ optimal_fps[-1]     optimal_tpr = optimal_tps \/ optimal_tps[-1]      return optimal_fpr, optimal_tpr, optimal_thresholds   def area_by_trapz(y, x):     dx = np.diff(x)   # height      return 0.5 * ((y[1:] + y[:-1]) * dx).sum()   def binary_roc_auc_score(y_test, y_pred):     fpr, tpr, _ = binary_roc_curve(y_test, y_pred)      return area_by_trapz(tpr, fpr)   y_pred_probas = model.predict_proba(X_test)[:, 1] roc_auc = binary_roc_auc_score(y_test, y_pred_probas) fpr, tpr, thresholds = binary_roc_curve(y_test, y_pred_probas)  print(f'AUC: {roc_auc}', '', sep='\\n') print('Optimal False Positive Rates:', fpr, '', sep='\\n') print('Optimal True Positive Rates:', tpr, '', sep='\\n') print('Optimal thresholds:', thresholds, sep='\\n')  plt.figure(figsize=(8, 6)) plt.plot(fpr, tpr, label=f'ROC Curve (AUC = {roc_auc})', color='fuchsia') plt.plot([0, 1], [0, 1], 'r--')  # Dashed diagonal line plt.fill_between(fpr, tpr, color='lightblue', alpha=0.9) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('ROC Curve') plt.legend(loc='lower right') plt.show()   AUC: 0.9951781970649896  Optimal False Positive Rates: [0.         0.         0.         0.01111111 0.01111111 0.04444444  0.04444444 0.12222222 0.12222222 1.        ]  Optimal True Positive Rates: [0.         0.01886792 0.86792453 0.86792453 0.94339623 0.94339623  0.98113208 0.98113208 1.         1.        ]  Optimal thresholds: [2.00000000e+00 1.00000000e+00 9.39251068e-01 9.28758892e-01  8.62519599e-01 7.34708679e-01 6.73824037e-01 2.39038287e-01  2.23663185e-01 1.80054591e-06]<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4b1\/cf3\/db8\/4b1cf3db8e8fab679b10ccb6ed8b6bd7.png\" width=\"691\" height=\"547\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4b1\/cf3\/db8\/4b1cf3db8e8fab679b10ccb6ed8b6bd7.png\"\/><\/figure>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f scikit-learn<\/strong> <\/p>\n<pre><code class=\"python\">sk_roc_auc = roc_auc_score(y_test, y_pred_probas) sk_fpr, sk_tpr, sk_thresholds = roc_curve(y_test, y_pred_probas)  print(f'AUC (scikit-learn): {sk_roc_auc}', '', sep='\\n') print('Optimal False Positive Rates (scikit-learn):', sk_fpr, '', sep='\\n') print('Optimal True Positive Rates (scikit-learn):', sk_tpr, '', sep='\\n') print('Optimal thresholds (scikit-learn):', sk_thresholds, sep='\\n')   AUC (scikit-learn): 0.9951781970649896  Optimal False Positive Rates (scikit-learn): [0.         0.         0.         0.01111111 0.01111111 0.04444444  0.04444444 0.12222222 0.12222222 1.        ]  Optimal True Positive Rates (scikit-learn): [0.         0.01886792 0.86792453 0.86792453 0.94339623 0.94339623  0.98113208 0.98113208 1.         1.        ]  Optimal thresholds (scikit-learn): [2.00000000e+00 1.00000000e+00 9.39251068e-01 9.28758892e-01  8.62519599e-01 7.34708679e-01 6.73824037e-01 2.39038287e-01  2.23663185e-01 1.80054591e-06]<\/code><\/pre>\n<p>ROC-AUC \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u044b \u043d\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0438\u043d\u043e\u0442\u0435\u0430\u0442\u0440 \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0434\u043b\u0435\u0432\u0430\u0442\u044c \u043c\u0435\u0441\u044f\u0447\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u0430 \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0435\u0442\u043a\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u043c\u0435\u043d\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0434\u043b\u044f \u0438\u0445 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e ROC-AUC \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u043e\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u0432\u0441\u0451 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e ROC-AUC \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u0441\u0438\u043b\u044c\u043d\u044b\u043c \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 (TN), \u0447\u0442\u043e \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u0440\u0430\u0441\u0447\u0451\u0442\u043e\u0432 FPR. \u041f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u044b\u0441\u043e\u043a\u0438\u0439 TPR, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 (FPR).<\/p>\n<h4>PR-AUC \u0438 Average Precision (AP)<\/h4>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u0432 \u043e\u0441\u044f\u0445 Precision Recall, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u043a\u0430\u043a\u00a0<strong>PR-AUC<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0438\u043b\u044c\u043d\u044b\u043c \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e PR-AUC \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u043b\u043e\u0436\u043d\u043e\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0447\u0442\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043b\u0443\u0447\u0448\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0433\u0434\u0435 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0444\u0438\u043b\u044c\u043c\u044b, PR-AUC \u0431\u0443\u0434\u0435\u0442 \u043b\u0443\u0447\u0448\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0444\u0438\u043b\u044c\u043c\u044b (TP), \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a ROC-AUC \u043c\u043e\u0436\u0435\u0442 \u0443\u0447\u0435\u0441\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0444\u0438\u043b\u044c\u043c\u044b (TN). \u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 ROC-AUC, \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 PR-AUC \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u044b\u0439 \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0443\u0433\u043e\u043b, \u0430 \u0435\u0451 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">precisions, recalls, _ = precision_recall_curve(y_test, y_pred_probas) pr_auc_score = auc(recalls, precisions) print(pr_auc_score)   0.9924452566260418<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0438 \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u0432\u0441\u0451 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0430\u0441\u0447\u0451\u0442 PR-AUC \u0442\u0430\u043a\u0436\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u0435 \u0442\u0440\u0430\u043f\u0435\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u0438\u043d\u0435\u0439\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044e. \u0427\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043b\u043e\u0445\u043e\u0433\u043e? \u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0432 ROC-\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0432 \u0438\u0445 \u043f\u0440\u044f\u043c\u043e\u0439 \u043b\u0438\u043d\u0438\u0435\u0439, \u0442\u043e \u0432 PR-\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c. \u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0443\u0440\u043e\u0432\u043d\u044f Recall, \u043c\u0435\u0442\u0440\u0438\u043a\u0430 Precision \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 FP \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 FN \u0432 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u0435 Precision. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u0439 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 PR-AUC \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0430\u0432\u044b\u0448\u0435\u043d\u043d\u0443\u044e \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e\u0434 \u043a\u0440\u0438\u0432\u043e\u0439.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 scikit-learn \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u0430\u044f (\u0438 \u043e\u0447\u0435\u043d\u044c \u0441\u0445\u043e\u0436\u0430\u044f) \u043c\u0435\u0442\u0440\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0<strong>Average Precision<\/strong>. \u0415\u0451 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044f. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043a\u0440\u0438\u0432\u0430\u044f Precision-Recall \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Precisions, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430, \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0435\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 Recall \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u043f\u043e\u0440\u043e\u0433\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{AP} = \\sum_n (R_n - R_{n-1}) P_n\" alt=\"\\text{AP} = \\sum_n (R_n - R_{n-1}) P_n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/22d\/4f3\/259\/22d4f3259c86d920e0ee0087f69acd1e.svg\" width=\"209\" height=\"44\"\/><\/p>\n<pre><code class=\"python\">ap_score = average_precision_score(y_test, y_pred_probas) print(ap_score)   0.992511694643552<\/code><\/pre>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0432\u0443\u0445<\/h4>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043d\u0430\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f4f\/1cd\/631\/f4f1cd63171652b2e0c8d3730673474f.svg\" width=\"17\" height=\"17\"\/>\u00a0\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/77a\/69e\/d7a\/77a69ed7a4198f8947f382244a573d83.svg\" width=\"10\" height=\"17\"\/>\u00a0\u043e\u0442 \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0440\u0430\u0441\u0447\u0451\u0442\u043e\u043c consufion matrix \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0443\u0441\u0440\u0435\u0434\u043d\u0451\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>1)\u00a0<strong>\u041c\u0438\u043a\u0440\u043e-\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 (micro-averaging)<\/strong>\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043e\u043c accuracy \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b consufion matrix \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430\u043c\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Precision \u0438 Recall \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{Precision}_{\\text{(micro)}} = \\frac{\\sum_{k=1}^{K} \\text{TP}_k}{\\sum_{k=1}^{K} (\\text{TP}_k + \\text{FP}_k)} \\\\ \\text{Recall}_{\\text{(micro)}} = \\frac{\\sum_{k=1}^{K} \\text{TP}_k}{\\sum_{k=1}^{K} (\\text{TP}_k + \\text{FN}_k)}\" alt=\"\\text{Precision}_{\\text{(micro)}} = \\frac{\\sum_{k=1}^{K} \\text{TP}_k}{\\sum_{k=1}^{K} (\\text{TP}_k + \\text{FP}_k)} \\\\ \\text{Recall}_{\\text{(micro)}} = \\frac{\\sum_{k=1}^{K} \\text{TP}_k}{\\sum_{k=1}^{K} (\\text{TP}_k + \\text{FN}_k)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9ef\/70a\/b34\/9ef70ab34fe3df01454d2527f7a02ced.svg\" width=\"697\" height=\"125\"\/><\/p>\n<ul>\n<li>\n<p>2)\u00a0<strong>\u041c\u0430\u043a\u0440\u043e-\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 (macro-averaging)<\/strong>\u00a0\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0436\u0435\u043d \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u0430:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{Precision}_{\\text{(macro)}} = \\frac{1}{K} \\sum_{k=1}^{K} \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FP}_k} \\\\ \\text{Recall}_{\\text{(macro)}} = \\frac{1}{K} \\sum_{k=1}^{K} \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FN}_k}\" alt=\"\\text{Precision}_{\\text{(macro)}} = \\frac{1}{K} \\sum_{k=1}^{K} \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FP}_k} \\\\ \\text{Recall}_{\\text{(macro)}} = \\frac{1}{K} \\sum_{k=1}^{K} \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FN}_k}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/14f\/4a2\/164\/14f4a216495c93fd62cdb60b29425f20.svg\" width=\"697\" height=\"125\"\/><\/p>\n<ul>\n<li>\n<p>3)\u00a0<strong>\u0412\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 (weighted averaging)<\/strong>\u00a0\u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0442\u0430\u043a\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0436\u043d\u044b \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b. \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435\u043c \u0438\u043c \u0432\u0435\u0441\u043e\u0432. \u0412\u0435\u0441 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<strong>w_k<\/strong>\u00a0\u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0434\u043e\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{Precision}_{\\text{(weighted)}} = \\sum_{k=1}^{K} w_k \\cdot \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FP}_k} \\\\ \\text{Recall}_{\\text{(weighted)}} = \\sum_{i=1}^{K} w_k \\cdot \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FN}_k}\" alt=\"\\text{Precision}_{\\text{(weighted)}} = \\sum_{k=1}^{K} w_k \\cdot \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FP}_k} \\\\ \\text{Recall}_{\\text{(weighted)}} = \\sum_{i=1}^{K} w_k \\cdot \\frac{\\text{TP}_k}{\\text{TP}_k + \\text{FN}_k}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aef\/43f\/e10\/aef43fe10374c2419faf4aedf9dd5ef7.svg\" width=\"697\" height=\"125\"\/><\/p>\n<p>\u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u043e\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <a href=\"https:\/\/www.kaggle.com\/datasets\/uciml\/red-wine-quality-cortez-et-al-2009\/data\" rel=\"noopener noreferrer nofollow\">Red Wine Quality<\/a>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 classification_report \u0438\u0437 scikit-learn.<\/p>\n<p><strong>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/strong>  <\/p>\n<pre><code class=\"python\">red_wine = pd.read_csv(\"\/content\/drive\/MyDrive\/winequality-red.csv\") print(red_wine)  X = red_wine.drop(columns='quality', axis=1) y = red_wine['quality']  X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)         fixed acidity  volatile acidity  citric acid  residual sugar  chlorides  \\ 0               7.4             0.700         0.00             1.9      0.076    1               7.8             0.880         0.00             2.6      0.098    2               7.8             0.760         0.04             2.3      0.092    3              11.2             0.280         0.56             1.9      0.075    4               7.4             0.700         0.00             1.9      0.076    ...             ...               ...          ...             ...        ...    1594            6.2             0.600         0.08             2.0      0.090    1595            5.9             0.550         0.10             2.2      0.062    1596            6.3             0.510         0.13             2.3      0.076    1597            5.9             0.645         0.12             2.0      0.075    1598            6.0             0.310         0.47             3.6      0.067           free sulfur dioxide  total sulfur dioxide  density    pH  sulphates  \\ 0                    11.0                  34.0  0.99780  3.51       0.56    1                    25.0                  67.0  0.99680  3.20       0.68    2                    15.0                  54.0  0.99700  3.26       0.65    3                    17.0                  60.0  0.99800  3.16       0.58    4                    11.0                  34.0  0.99780  3.51       0.56    ...                   ...                   ...      ...   ...        ...    1594                 32.0                  44.0  0.99490  3.45       0.58    1595                 39.0                  51.0  0.99512  3.52       0.76    1596                 29.0                  40.0  0.99574  3.42       0.75    1597                 32.0                  44.0  0.99547  3.57       0.71    1598                 18.0                  42.0  0.99549  3.39       0.66           alcohol  quality   0         9.4        5   1         9.8        5   2         9.8        5   3         9.8        6   4         9.4        5   ...       ...      ...   1594     10.5        5   1595     11.2        6   1596     11.0        6   1597     10.2        5   1598     11.0        6    [1599 rows x 12 columns]<\/code><\/pre>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432<\/strong><\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e, \u0432 \u0446\u0435\u043b\u043e\u043c, \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u0438\u0437-\u0437\u0430 \u0441\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0435 \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0431\u044b\u043b\u0438 \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043d\u0443\u043b\u044f\u043c\u0438.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u0438\u043a\u0440\u043e-\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 (accuracy) \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e \u0437\u0430\u0432\u044b\u0448\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0430 \u0432\u043e\u0442 \u043c\u0430\u043a\u0440\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u043c\u0435\u044e\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0430\u043a\u0436\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0430\u044f.<\/p>\n<pre><code class=\"python\">ovr_model = LogisticRegression(multi_class='ovr', max_iter=1000) ovr_model.fit(X_train, y_train) y_pred = ovr_model.predict(X_test)  clf_report = classification_report(y_test, y_pred) print(clf_report)       accuracy                           0.62       400    macro avg       0.29      0.27      0.27       400 weighted avg       0.58      0.62      0.59       400<\/code><\/pre>\n<hr\/>\n<p><a class=\"anchor\" name=\"regression_metrics\" id=\"regression_metrics\"><\/a><\/p>\n<h3>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/h3>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043f\u0440\u0438\u0440\u043e\u0434\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043f\u043e\u0433\u043e\u0434\u044b, \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0430\u043a\u0446\u0438\u0439, \u0446\u0435\u043d\u0430 \u043d\u0430 \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u044c \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043c\u0435\u0442\u0440\u0438\u043a \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043e\u0446\u0435\u043d\u043a\u0443 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043e\u0434\u043d\u0430\u043a\u043e, \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0445 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e, \u043e\u0431\u0443\u0447\u0438\u0432 \u043b\u0438\u043d\u0435\u0439\u043d\u0443\u044e \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445\u00a0<a href=\"https:\/\/www.google.com\/url?q=https%3A%2F%2Fwww.kaggle.com%2Fdatasets%2Fmirichoi0218%2Finsurance%2Fdata\" rel=\"noopener noreferrer nofollow\">Medical Cost Personal<\/a>.<\/p>\n<p><strong>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/strong>  <\/p>\n<pre><code class=\"python\">import numpy as np import pandas as pd from sklearn.preprocessing import LabelEncoder from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import (mean_absolute_error, mean_absolute_percentage_error,                              mean_squared_error, mean_squared_log_error, r2_score)<\/code><\/pre>\n<p><strong>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/strong>  <\/p>\n<pre><code class=\"python\">df_path = \"\/content\/drive\/MyDrive\/insurance.csv\" insurance_cost = pd.read_csv(df_path) print(insurance_cost)  X = insurance_cost.drop(columns='charges', axis=1) y = insurance_cost['charges']  cat_features_list = X.select_dtypes(include=['object']).columns X[cat_features_list] = X[cat_features_list].apply(LabelEncoder().fit_transform)  X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)         age     sex     bmi  children smoker     region      charges 0      19  female  27.900         0    yes  southwest  16884.92400 1      18    male  33.770         1     no  southeast   1725.55230 2      28    male  33.000         3     no  southeast   4449.46200 3      33    male  22.705         0     no  northwest  21984.47061 4      32    male  28.880         0     no  northwest   3866.85520 ...   ...     ...     ...       ...    ...        ...          ... 1333   50    male  30.970         3     no  northwest  10600.54830 1334   18  female  31.920         0     no  northeast   2205.98080 1335   18  female  36.850         0     no  southeast   1629.83350 1336   21  female  25.800         0     no  southwest   2007.94500 1337   61  female  29.070         0    yes  northwest  29141.36030  [1338 rows x 7 columns]<\/code><\/pre>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/strong>  <\/p>\n<pre><code class=\"python\">model = LinearRegression() model.fit(X_train, y_train) y_pred = model.predict(X_test) print(y_pred)   [10947.91401491  9764.82733066 38027.18625354 16076.26656375   7003.05093861  4162.38974052  1745.17453352 14273.5330135   9022.7490154   7548.70107263  4742.33662827 10290.75344147   8592.56051588  4173.37165612 27970.0324915  11026.04778351  11286.00941429  6197.06911697  8269.51468144 27263.01056172  33686.9512703  14247.8812616  11735.79293452 32419.5578177   4475.57228648  9264.65728706  1336.5408973  10083.42064465   4134.01766875 10422.0367284   9033.04363126 40177.36502272  15327.89185262 13541.84076855 24979.41529438  5273.0794857  12809.44891047 30538.99654744 33503.98483751  3477.84775709   4169.03343497  4346.93367013 30642.90398321 39366.95813634  28066.36347631  5110.98142166 10919.49675465  7870.63024919   3790.77872548 10529.86942143  5758.50260778  3526.36470247  32837.53966438 38431.60954739 16119.53210068  7198.88399648   6010.47765564  9455.45703492  9323.82247057 11736.15685931   1745.70435635 38856.13381995 15133.33969997 11575.03834933  14071.5724629  13696.5272597  26189.53137674 32224.3994756   1285.84165993 10192.3389615  12103.18984314 11812.13268915  25146.32331141 15738.43743924 11190.33714978 12666.511048   6443.77417808  9893.21714388 30312.26136507 38774.44771196  12063.1199766  37348.74819938  4280.83232304  9194.1511214  34855.84194627 29249.62417709  8369.44588068  4945.57095651  11829.89576319 30234.75411865 10099.95369361 11152.51466685   8345.39483062  9216.66152856  8456.71908548  7389.90572249  36031.82502924 32995.87707694  7647.03076484 14761.02404168   4335.42273688  8790.6336137   6626.82252505 31798.31619795  33017.1906077   2094.40570673  8884.5733591   6639.27260791  14530.96799671 36943.676041   10209.36205958 10754.28354013  10198.39675302 27099.34704068 39995.94299687  8600.67413204    283.08058982  8834.31659717 14929.5620573   9589.03267786  35399.75956117  7345.60983793 16567.9444266   9694.5508457   8068.18149856  3097.01655573 33001.67961343 31570.2503123  39236.13757102  5563.9838186   9605.43014551  3923.56950664   7936.19344017  8758.93978756 31529.93069335 29783.93576815  30140.52767905  9084.18593446 32774.6651671   3447.8282725   3714.75872713 11106.90396946 13347.95952139 12853.99458907   5528.91820808 15704.83891849 15079.88363053  2544.67843054    185.77752153 10942.26089435  7512.81091318 32029.66886541  12399.16046026  2715.99117956  6398.9448798   8153.13247564   4485.58951977  2502.88912184 11354.3765072  12473.86448172   7378.57534425 16486.02707379 11773.13898945 13764.75456224   3381.59967736  7414.52171201 23083.99616223  7702.25146492   5640.00381695  5423.20666932  6771.22658553  5369.21237435   9978.65825664  5651.47058169  5617.05819013  6992.25772557   3927.54466569  5677.34987188 38108.35355982  1687.47789286  12570.90785396  8990.57884784 13663.12241126  5692.74305794   5400.09622194 36497.28911925  4499.38119881  1950.64760943  15075.82279197 12681.99346283 35147.22262059  5131.27114327   5547.26999983 31572.7189971   6167.37488999  2062.03461108   8544.26381135 10074.42722051  8266.17437786  5850.88787567  13147.1222075  38635.78272386 13659.93211399 28800.64409693   6812.19498243 35711.06603231  3973.45030397 12098.25000178   9304.02766868  6456.8508697  11306.30379171 14517.23252599   5259.7484308   4261.74861629  7739.96622866  1287.11803755   8007.7029553   4603.7389562  13174.33476059  4491.67379326   9853.36083563  7375.34455594  9072.2189463   2578.72399596  12933.69851212 16674.51032722 15098.07149349 10382.93145759   5750.15941467  2634.44325287  2301.36074417 13447.00625685  14203.53207008  5171.47470846  4159.8794872   9287.91215283  10048.86025637 28387.85591072  7761.85208288 10586.09180311   6147.09690682 29867.2455107  10866.38256904  7609.85428543  10248.41393685 12190.90620035  3216.69032739 10786.13583408   1735.08998421  7194.492167   28788.15185516 38398.20353488   6171.96169948  8372.97420985  2665.38796458   675.24311869  10324.23779113  4464.24740958  5084.62925272  2765.12366764   7255.30324083 33205.81109315 38215.02085724 14677.52426265   8294.91587575 16028.83595951 33133.59667833  9623.53886742  33401.64850545  3686.52411934 30843.71540422  8001.71986381  14179.94621339  4211.35722232 32497.0827103   8443.10889356  11460.8623175   9434.21047718  4321.92599873 12464.24068476  11701.49681152  8483.560458   13344.98515219  2972.12577494  10675.86128124  5389.8245388  11159.3820939  31723.46535925  10047.84307228  1472.76142561   717.98703914 39821.97375226   9812.26823742  7166.20953879 13905.32236228 13428.33354475  27218.10087176  7033.74308314  6785.64013095 11933.98289128   3038.43915783  4022.38383321 25307.2029606  26414.33042405  13250.32827696  3471.9145674   5176.44334405  9222.66486622  12506.28838182 23844.27532952 30900.61492849  9893.41699449  24249.49669032  3004.11445538 11542.47299099  7624.09099954   8366.614262     502.36290308  7920.24301719 35599.63593964   6316.23859849  6413.28197074   427.51684841 10843.82978818   6793.9564125   9939.5724268  38715.2046951  27842.86075012  11591.34753748 35624.43529894 14993.0317229   6934.89010657  10983.73053465  6810.5049236  36668.7011676 ]<\/code><\/pre>\n<h4>MAE<\/h4>\n<p><strong>Mean Absolute Error<\/strong>\u00a0\u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u043a\u043b\u043e\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{MAE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N |y_i - \\hat y_i|\" alt=\"\\text{MAE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N |y_i - \\hat y_i|\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/60c\/88d\/aac\/60c88daac005b5fba28519077e4d2c35.svg\" width=\"241\" height=\"60\"\/><\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u0438 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u0430 \u043a \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431 (\u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u043b\u0438\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435) \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a (\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439).<\/p>\n<pre><code class=\"python\">def mae_score(y_true, y_pred):     n = len(y_true)      return 1 \/ n * np.sum(np.abs(y_true - y_pred))   mae = mae_score(y_test, y_pred) sk_mae = mean_absolute_error(y_test, y_pred) print(f'mae: {mae}') print(f'mae(scikit-learn): {sk_mae}')   mae: 3998.2715408869726 mae(scikit-learn): 3998.2715408869726<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043a\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0448\u0438\u0431\u0430\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 MAE \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u0438\u043c, \u0442\u0430\u043a \u0438 \u043f\u043b\u043e\u0445\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u043a\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0441\u0435\u0442\u044c \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u043e\u0432 \u043f\u0440\u043e\u0434\u0430\u0441\u0442 \u0431\u0430\u043d\u0430\u043d\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043a \u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 10000.  <\/p>\n<pre><code class=\"python\">true_sales = y_test + 10_000 pred_sales = y_pred + 10_000  mae_for_sales = mean_absolute_error(true_sales, pred_sales) print(f'mae(for sales): {mae_for_sales}')   mae(for sales): 3998.2715408869726<\/code><\/pre>\n<p>\u041d\u0435\u0442\u0440\u0443\u0434\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 MAE, \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c. \u0412 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043d\u0435 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0443\u044e, \u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445.  <\/p>\n<h4>MAPE &amp; SMAPE<\/h4>\n<p><strong>Mean Absolute Percentage Error<\/strong>\u00a0\u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\u0445 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{MAPE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N \\frac{|y_i - \\hat y_i|}{|y_i|}\" alt=\"\\text{MAPE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N \\frac{|y_i - \\hat y_i|}{|y_i|}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/536\/abd\/1f3\/536abd1f369b9fe705f059c606df7c6c.svg\" width=\"261\" height=\"60\"\/><\/p>\n<pre><code class=\"python\">def mape_score(y_true, y_pred):     n = len(y_true)     numerator = np.abs(y_true - y_pred)     denominator = np.abs(y_true)      return  1 \/ n * np.sum(numerator \/ denominator)   mape = mape_score(y_test, y_pred) sk_mape = mean_absolute_percentage_error(y_test, y_pred) mape_for_sales = mean_absolute_percentage_error(true_sales, pred_sales)  print(f'mape: {mape}') print(f'mape(scikit-learn): {sk_mape}') print(f'mape(for sales): {mape_for_sales}')   mape: 0.4138713715103651 mape(scikit-learn): 0.4138713715103651 mape(for sales): 0.15963240527305983<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u0430\u0435\u0442\u0441\u044f \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0441\u0438\u043b\u044c\u043d\u0435\u0435, \u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f MAE. \u041e\u0434\u043d\u0430\u043a\u043e MAPE \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u043b\u044e, \u0447\u0442\u043e \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0444\u043e\u0440\u043c\u0443\u043b\u044b. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0443\u044e MAPE, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u043a\u0430\u043a\u00a0<strong>Symmetric Mean Absolute Percentage Error<\/strong>: <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{SMAPE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N \\frac{2 |y_i - \\hat y_i|}{y_i + \\hat y_i}\" alt=\"\\text{SMAPE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N \\frac{2 |y_i - \\hat y_i|}{y_i + \\hat y_i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a31\/e22\/9b5\/a31e229b5a920c4f9715764315695e48.svg\" width=\"282\" height=\"60\"\/><\/p>\n<pre><code class=\"python\">def smape_score(y_true, y_pred):     n = len(y_true)     numerator = 2 * np.abs(y_true - y_pred)     denominator = (y_true + y_pred)      return  1 \/ n * np.sum(numerator \/ denominator)   smape = smape_score(y_test, y_pred) print(f'smape: {smape}')   smape: 0.3573799807309885<\/code><\/pre>\n<h4>WAPE<\/h4>\n<p>\u041a\u0430\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, MAPE \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u043d\u0435 \u0432\u043e \u0432\u0441\u0435\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d\u0430 \u043f\u043b\u043e\u0445\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0441 \u0441\u0435\u0437\u043e\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u044f\u043c\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0438 \u043f\u043b\u043e\u0445\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0414\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442\u00a0<strong>Weighted Average Percentage Error<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u043a \u043e\u0431\u0449\u0435\u0439 \u0441\u0443\u043c\u043c\u0435 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{WAPE}(y, \\hat y) = \\frac{\\sum_{i=1}^N |y_i - \\hat y_i|}{\\sum_{i=1}^N |y_i|}\" alt=\"\\text{WAPE}(y, \\hat y) = \\frac{\\sum_{i=1}^N |y_i - \\hat y_i|}{\\sum_{i=1}^N |y_i|}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/398\/6dc\/b10\/3986dcb10305eb569a6cd0451ac9fb5a.svg\" width=\"253\" height=\"60\"\/><\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043e\u0433\u043e \u0438\u043c\u0435\u044e\u0442 \u044f\u0440\u043a\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043d\u0443\u044e \u0441\u0435\u0437\u043e\u043d\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0432 \u043b\u0435\u0442\u043d\u0438\u0435 \u043c\u0435\u0441\u044f\u0446\u044b \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0448\u0435, \u0447\u0435\u043c \u0432 \u0437\u0438\u043c\u043d\u0438\u0435. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 WAPE \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0431\u0443\u0434\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0441\u044f\u0446\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0451\u043c\u0430 \u043f\u0440\u043e\u0434\u0430\u0436, \u0447\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043b\u0443\u0447\u0448\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0435\u0440\u044b\u0432\u0438\u0441\u0442\u044b\u043c\u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0430\u043c\u0438.  <\/p>\n<pre><code class=\"python\">def wape_score(y_true, y_pred):     numerator = np.sum(np.abs(y_true - y_pred))     denominator = np.sum(np.abs(y_true))      return numerator \/ denominator   wape = wape_score(y_test, y_pred) print(f'wape: {wape}')   wape: 0.29762832405759587<\/code><\/pre>\n<h4>MSE &amp; RMSE<\/h4>\n<p><strong>Mean Squared Error<\/strong>\u00a0\u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u043a\u043b\u043e\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{MSE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N (y_i - \\hat y_i)^2\" alt=\"\\text{MSE}(y, \\hat y) = \\frac{1}{N} \\sum_{i=1}^N (y_i - \\hat y_i)^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cdb\/d05\/56d\/cdbd0556dea29e6cb56369d48dc9e987.svg\" width=\"247\" height=\"60\"\/><\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043a\u0446\u0435\u043d\u0442 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438\u0445 \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0438\u0437-\u0437\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u0432\u044b\u0448\u0435, MSE \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0430 \u043a \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0430 \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 MAE.  <\/p>\n<pre><code class=\"python\">def mse_score(y_true, y_pred):     n = len(y_true)      return 1 \/ n * np.sum((y_true - y_pred) ** 2)   mse = mse_score(y_test, y_pred) sk_mse = mean_squared_error(y_test, y_pred) print(f'mse: {mse}') print(f'mse(scikit-learn): {sk_mse}')   mse: 32073628.560109198 mse(scikit-learn): 32073628.560109198<\/code><\/pre>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e MSE \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0437 \u043d\u0435\u0433\u043e \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0439 \u043a\u043e\u0440\u0435\u043d\u044c. \u0422\u0430\u043a\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0<strong>Root Mean Squared Error<\/strong>\u00a0\u0438 \u0435\u0451 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043b\u0443\u0447\u0448\u0435\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 MSE: <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{RMSE}(y, \\hat y) = \\sqrt{\\frac{1}{N} \\sum_{i=1}^N (y_i - \\hat y_i)^2}\" alt=\"\\text{RMSE}(y, \\hat y) = \\sqrt{\\frac{1}{N} \\sum_{i=1}^N (y_i - \\hat y_i)^2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/481\/46f\/cdb\/48146fcdbaeebe2a4a3643eb01f8449e.svg\" width=\"282\" height=\"65\"\/><\/p>\n<pre><code class=\"python\">rmse = np.sqrt(mse) print(f'rmse: {rmse}')   rmse: 5663.358417062193<\/code><\/pre>\n<h4>MSLE &amp; RMSLE<\/h4>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0432 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0432\u00a0<strong>Mean Squared Logarithmic Error<\/strong>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{MSLE}(y, \\hat y |c) = \\frac{1}{N} \\sum_{i=1}^N (\\text{ln}(y_i + c) - \\text{ln}(\\hat y_i + c))^2\" alt=\"\\text{MSLE}(y, \\hat y |c) = \\frac{1}{N} \\sum_{i=1}^N (\\text{ln}(y_i + c) - \\text{ln}(\\hat y_i + c))^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d83\/e95\/29e\/d83e9529e960d639eb560e96376b79c3.svg\" width=\"399\" height=\"60\"\/><\/p>\n<p>\u0433\u0434\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"c\" alt=\"c\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ba1\/4db\/42a\/ba14db42a97a97a15634d0405f9b73e4.svg\" width=\"8\" height=\"12\"\/>\u00a0\u2014  \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 (\u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0432\u043d\u0430 1), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0430 \u043d\u0443\u043b\u044f.<\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0431\u043e\u043b\u0435\u0435 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u0430 \u043a \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0438 \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u043c. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, MSLE \u0442\u0440\u0443\u0434\u043d\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u043c\u0435\u0442\u044c \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043e\u043d\u0430 \u0443\u0434\u0435\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0437\u0430\u043d\u0438\u0436\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439.<\/p>\n<pre><code class=\"python\">def msle_score(y_true, y_pred, c=1):     n = len(y_true)      return 1 \/ n * np.sum((np.log(y_true + c) - np.log(y_pred + c)) ** 2)   msle = msle_score(y_test, y_pred) sk_msle = mean_squared_log_error(y_test, y_pred) print(f'msle: {msle}') print(f'msle(scikit-learn): {sk_msle}')   msle: 0.2966547825040618 msle(scikit-learn): 0.2966547825040618<\/code><\/pre>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 MSLE \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f\u00a0<strong>Root Mean Squared Logarithmic Error<\/strong>:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{RMSLE}(y, \\hat y |c) = \\sqrt{\\frac{1}{N} \\sum_{i=1}^N (\\text{ln}(y_i + c) - \\text{ln}(\\hat y_i + c))^2}\" alt=\"\\text{RMSLE}(y, \\hat y |c) = \\sqrt{\\frac{1}{N} \\sum_{i=1}^N (\\text{ln}(y_i + c) - \\text{ln}(\\hat y_i + c))^2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c75\/e17\/acf\/c75e17acf0fba336b24baf19d953534c.svg\" width=\"434\" height=\"65\"\/><\/p>\n<pre><code class=\"python\">rmsle = np.sqrt(msle) print(f'rmsle {rmsle}')   rmsle 0.5446602450189125<\/code><\/pre>\n<h4>R2 &amp; Adjusted R2<\/h4>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0438\u043b\u0438 \u043f\u043b\u043e\u0445\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0441\u043c\u044b\u0441\u043b\u0435 \u0430\u043d\u0430\u043b\u043e\u0433 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\u0445, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0442\u0430\u043a\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u044d\u0442\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0446\u0438\u0438\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2\" alt=\"\\text{R}^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/08e\/1db\/e36\/08e1dbe361b1a91eb669c039e78f1703.svg\" width=\"23\" height=\"21\"\/> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a\u0430\u044f \u0434\u043e\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c\u044e:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{R}^2 = \\frac{SST - SSR}{SST} = 1 - \\frac{SSR}{SST} = 1 - \\frac{\\sum_{i=1}^N(y_i - \\hat y_i)^2}{\\sum_{i=1}^N(y_i - \\overline y)^2}\" alt=\"\\text{R}^2 = \\frac{SST - SSR}{SST} = 1 - \\frac{SSR}{SST} = 1 - \\frac{\\sum_{i=1}^N(y_i - \\hat y_i)^2}{\\sum_{i=1}^N(y_i - \\overline y)^2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2e4\/bb9\/b27\/2e4bb9b277b80307ee34210b9beb423b.svg\" width=\"454\" height=\"60\"\/><\/p>\n<p>\u0433\u0434\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SSR\" alt=\"SSR\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/704\/ca4\/30d\/704ca430d6edd566184a1a4d8a700a38.svg\" width=\"40\" height=\"17\"\/>\u00a0\u2014 Sum of Squared Residuals, \u0430\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SST\" alt=\"SST\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c2d\/f8b\/e35\/c2df8be35bd847004b6a8815a117f2e6.svg\" width=\"38\" height=\"17\"\/>\u00a0\u2014 Sum of Squares Total.<\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043c\u0435\u0442\u0440\u0438\u043a, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u043b\u0443\u0447\u0448\u0435\u043c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2\" alt=\"\\text{R}^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/98c\/cfc\/c20\/98ccfcc208d4e1f5ab7f7dd7cbe6d617.svg\" width=\"23\" height=\"21\"\/> \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>1)\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2 = 1\" alt=\"\\text{R}^2 = 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a1d\/e7a\/025\/a1de7a025fe0b6ba92e065c5402b89f4.svg\" width=\"58\" height=\"21\"\/>\u00a0\u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435;<\/p>\n<\/li>\n<li>\n<p>2)\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2 = 0\" alt=\"\\text{R}^2 = 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/330\/d74\/6f8\/330d746f886f10fa127a66a38b7ab219.svg\" width=\"58\" height=\"21\"\/>\u00a0\u2014 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0440\u0435\u0434\u043d\u0435\u043c\u0443 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>3)\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2 &lt; 0\" alt=\"\\text{R}^2 &lt; 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3c7\/632\/9d0\/3c76329d0388bdce1b4f357d8d6c3d2c.svg\" width=\"58\" height=\"21\"\/>\u00a0\u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (\u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0430\u043b\u0430\u0441\u044c \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0432\u044b\u0431\u0440\u043e\u0441\u044b).<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">def manual_r2_score(y_true, y_pred):     ssr = np.sum((y_true - y_pred) ** 2)     sst = np.sum((y_true - y_true.mean()) ** 2)      return 1 - ssr \/ sst   r2 = manual_r2_score(y_test, y_pred) sk_r2 = r2_score(y_test, y_pred) print(f'r2: {r2}') print(f'r2(scikit-learn): {sk_r2}')   r2: 0.7962732059725786 r2(scikit-learn): 0.7962732059725786<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2\" alt=\"\\text{R}^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/097\/59d\/371\/09759d371e637aba63e5a07c0b979e40.svg\" width=\"23\" height=\"21\"\/>\u00a0\u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f. \u0415\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438,\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2\" alt=\"\\text{R}^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bc2\/0e6\/dbf\/bc20e6dbf93d61fa16b632b8eeb7789f.svg\" width=\"23\" height=\"21\"\/>\u00a0\u0438\u043c\u0435\u0435\u0442 \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044e \u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u044e\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439\u00a0<strong>Adjusted\u00a0<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\text{R}^2\" alt=\"\\text{R}^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/632\/c1c\/8a4\/632c1c8a4870266b94637da6448e616a.svg\" width=\"23\" height=\"21\"\/>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0448\u0442\u0440\u0430\u0444\u0430 \u0437\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{R}_{adj}^2 = 1 - \\frac{SSR \\cdot (n-1)}{SST \\cdot (n - k - 1)} = 1 - \\frac{(1 - R^2) (n - 1)}{n - k - 1}\" alt=\"\\text{R}_{adj}^2 = 1 - \\frac{SSR \\cdot (n-1)}{SST \\cdot (n - k - 1)} = 1 - \\frac{(1 - R^2) (n - 1)}{n - k - 1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4fa\/0cd\/507\/4fa0cd50721793dc5e4dd44091226d65.svg\" width=\"445\" height=\"51\"\/><\/p>\n<p>\u0433\u0434\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n\" alt=\"n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/696\/711\/13d\/69671113dc7d83884792326046a13178.svg\" width=\"12\" height=\"12\"\/>\u00a0\u2014 \u0447\u0438\u0441\u043b\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u0430\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d60\/c1d\/c93\/d60c1dc9389ced1d42db6fd7bb3ce683.svg\" width=\"10\" height=\"17\"\/>\u00a0\u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. <\/p>\n<pre><code class=\"python\">def adjusted_r2_score(y_true, y_pred, x_shape):     n, k = x_shape     ssr = np.sum((y_true - y_pred) ** 2)     sst = np.sum((y_true - y_true.mean()) ** 2)     r2 = 1 - ssr \/ sst      return 1 - (1 - r2) * (n - 1) \/ (n - k - 1)   r2_adj = adjusted_r2_score(y_test, y_pred, X.shape) print(f'r2 adjusted: {r2_adj}')   r2 adjusted: 0.7953548282384204<\/code><\/pre>\n<hr\/>\n<p><a class=\"anchor\" name=\"bias-variance\" id=\"bias-variance\"><\/a><\/p>\n<h3>Bias-Variance Decomposition<\/h3>\n<p>\u041d\u0435 \u043e\u0442\u0445\u043e\u0434\u044f \u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 \u0442\u0435\u043c\u044b \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0440\u0430\u0437\u0431\u0440\u043e\u0441 \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0448\u0443\u043c \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043e\u0431\u0449\u0435\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0435\u0451 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f MSE<\/h4>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0441\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u043f\u043e\u0442\u0435\u0440\u044c. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"y\" alt=\"y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9af\/305\/5d3\/9af3055d382d79ab53f5749aad511458.svg\" width=\"10\" height=\"15\"\/>\u00a0\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f\" alt=\"f\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/147\/f5f\/39e\/147f5f39e9e9deece7dddfd71389065d.svg\" width=\"11\" height=\"20\"\/>\u00a0\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"y = f(x) + \\varepsilon\" alt=\"y = f(x) + \\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a6d\/567\/852\/a6d567852876400303b7b60aba8fc4f1.svg\" width=\"104\" height=\"22\"\/><\/p>\n<p>\u0433\u0434\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\varepsilon\" alt=\"\\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9de\/2d6\/ac3\/9de2d6ac385bdaab25c0a5d3ba073b2c.svg\" width=\"9\" height=\"12\"\/>\u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0448\u0443\u043c, \u043f\u0440\u0438\u0447\u0451\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"E [\\varepsilon] = 0, \\ E [\\varepsilon^2] = \\sigma^2\" alt=\"E [\\varepsilon] = 0, \\ E [\\varepsilon^2] = \\sigma^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/34b\/130\/f49\/34b130f49d7bcc6e259d62f7578cbb0a.svg\" width=\"172\" height=\"25\"\/>.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 MSE \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\hat f(x)\" alt=\"\\hat f(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4bc\/c97\/c58\/4bcc97c586585c33986d3d8bc1568df9.svg\" width=\"40\" height=\"26\"\/>\u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"MSE = E[(y - \\hat f(x))^2] = E[y^2] - 2E[y \\hat f(x)] + E[\\hat f(x)^2]\" alt=\"MSE = E[(y - \\hat f(x))^2] = E[y^2] - 2E[y \\hat f(x)] + E[\\hat f(x)^2]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ddc\/9c5\/427\/ddc9c54278d45579cd75ac1f37279ec2.svg\" width=\"472\" height=\"26\"\/><\/p>\n<p>\u0433\u0434\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u0440\u0430\u0437\u0431\u0440\u043e\u0441 \u0434\u043b\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\hat f(x)\" alt=\"\\hat f(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5d7\/17b\/71d\/5d717b71db26a70ed33d0eb6740732c3.svg\" width=\"40\" height=\"26\"\/>\u0440\u0430\u0432\u043d\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"Bias[\\hat f(x)] = f(x) - E[\\hat f(x)] \\\\ Var[\\hat f(x)] = E[\\hat f(x)^2] - E[\\hat f(x)]^2\" alt=\"Bias[\\hat f(x)] = f(x) - E[\\hat f(x)] \\\\ Var[\\hat f(x)] = E[\\hat f(x)^2] - E[\\hat f(x)]^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/06b\/cd4\/d68\/06bcd4d68b8b53a2947552b056527a3e.svg\" width=\"697\" height=\"58\"\/><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} E[y^2] &amp; = E[f(x)^2] + E[\\varepsilon^2] + 2E[f(x) \\varepsilon] \\\\ &amp;= E[f(x)^2] + \\sigma^2 + 2f(x) \\underbrace{E[\\varepsilon]}_{=0} \\\\ &amp;= f(x)^2 + \\sigma^2 \\end{align*}\" alt=\"\\begin{align*} E[y^2] &amp; = E[f(x)^2] + E[\\varepsilon^2] + 2E[f(x) \\varepsilon] \\\\ &amp;= E[f(x)^2] + \\sigma^2 + 2f(x) \\underbrace{E[\\varepsilon]}_{=0} \\\\ &amp;= f(x)^2 + \\sigma^2 \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/086\/881\/693\/08688169398a69850e515f02808de42a.svg\" width=\"318\" height=\"109\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} E[y \\hat f(x)] &amp;= E[(f(x) + \\varepsilon) \\hat f(x)]\\\\ &amp;= E[(f(x) \\hat f(x)] + E[(\\varepsilon \\hat f(x)] \\\\ &amp;= f(x) E[\\hat f(x)] + \\underbrace{E[\\varepsilon]}_{=0} E[\\hat f(x)] \\\\ &amp;= f(x) E[\\hat f(x)] \\end{align*}\" alt=\"\\begin{align*} E[y \\hat f(x)] &amp;= E[(f(x) + \\varepsilon) \\hat f(x)]\\\\ &amp;= E[(f(x) \\hat f(x)] + E[(\\varepsilon \\hat f(x)] \\\\ &amp;= f(x) E[\\hat f(x)] + \\underbrace{E[\\varepsilon]}_{=0} E[\\hat f(x)] \\\\ &amp;= f(x) E[\\hat f(x)] \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3fe\/4c7\/94d\/3fe4c794d7b5099563919a4e044ebae9.svg\" width=\"333\" height=\"142\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"E[\\hat f(x)^2] = Var[\\hat f(x)] + E[\\hat f(x)]^2\" alt=\"E[\\hat f(x)^2] = Var[\\hat f(x)] + E[\\hat f(x)]^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dec\/dfa\/6f9\/decdfa6f97e0a4b8395013f58a6cb3a7.svg\" width=\"283\" height=\"26\"\/><\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 MSE \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0430\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} MSE &amp;= f(x)^2 + \\sigma^2 - 2 f(x) E[\\hat f(x)] + Var[\\hat f(x)] + E[\\hat f(x)]^2 \\\\ &amp;= (\\underbrace{f(x) - E[\\hat f(x)]}_{=Bias})^2 + Var[\\hat f(x)] + \\sigma^2 \\\\ &amp;= Bias[\\hat f(x)]^2 + Var[\\hat f(x)] + \\sigma^2 \\end{align*}\" alt=\"\\begin{align*} MSE &amp;= f(x)^2 + \\sigma^2 - 2 f(x) E[\\hat f(x)] + Var[\\hat f(x)] + E[\\hat f(x)]^2 \\\\ &amp;= (\\underbrace{f(x) - E[\\hat f(x)]}_{=Bias})^2 + Var[\\hat f(x)] + \\sigma^2 \\\\ &amp;= Bias[\\hat f(x)]^2 + Var[\\hat f(x)] + \\sigma^2 \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ccd\/213\/11e\/ccd21311e7810f59db5626b50c085dac.svg\" width=\"510\" height=\"112\"\/><\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0438 \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f (\u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0448\u0438\u0431\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c), \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430 (\u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445) \u0438 \u043d\u0435\u0443\u0441\u0442\u0440\u0430\u043d\u0438\u043c\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438\u0437-\u0437\u0430 \u0448\u0443\u043c\u0430 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u043d\u0430\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0443\u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a \u043d\u0443\u043b\u044e. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043f\u043e\u0438\u0441\u043a\u0443 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c \u0438 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u043e\u043c. \u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0438\u0445 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c30\/e77\/7ae\/c30e777aed4de3738105482bdbfe937a.png\" width=\"747\" height=\"653\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c30\/e77\/7ae\/c30e777aed4de3738105482bdbfe937a.png\"\/><\/figure>\n<h4>Bias-Variance trade-off<\/h4>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>1) \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0438 \u043c\u0435\u043d\u0435\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 (\u043d\u0438\u0437\u043a\u0438\u0439 \u0440\u0430\u0437\u0431\u0440\u043e\u0441), \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0432\u044b\u0441\u043e\u043a\u043e\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435);<\/p>\n<\/li>\n<li>\n<p>2) \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043c\u043e\u0433\u043b\u0430 \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u043d\u043a\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 (\u043d\u0438\u0437\u043a\u043e\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435), \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442\u0441\u044f \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a \u0448\u0443\u043c\u0443 \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0442\u043e\u0447\u043a\u0430\u043c \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u0440\u0430\u0437\u0431\u0440\u043e\u0441).<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0435 \u044f\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u043f\u043e\u0438\u0441\u043a \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c \u0438 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u043e\u043c, \u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0<strong>bias-variance trade-off<\/strong>, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u0438\u0434 U-\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0439 \u043a\u0440\u0438\u0432\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/277\/bfe\/571\/277bfe57141c170906dcc295367fe0c8.png\" width=\"615\" height=\"503\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/277\/bfe\/571\/277bfe57141c170906dcc295367fe0c8.png\"\/><\/figure>\n<p>\u042d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u0431\u0430\u043b\u0430\u043d\u0441 \u043c\u0435\u0436\u0434\u0443\u00a0<strong>\u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c<\/strong>\u00a0(\u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0438\u0437\u043a\u0430\u044f \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445) \u0438\u00a0<strong>\u043d\u0435\u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c<\/strong>\u00a0(\u043d\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0432 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043d\u0438\u0437\u043a\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043d\u0430 \u043d\u0438\u0445, \u0442\u0430\u043a \u0438 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445). \u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f43\/ea7\/93b\/f43ea793bb86449206eb895886a3dac1.png\" width=\"1166\" height=\"510\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f43\/ea7\/93b\/f43ea793bb86449206eb895886a3dac1.png\"\/><\/figure>\n<h4>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 bias-variance<\/h4>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>1) \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0435\u0440\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0442\u0430\u043a\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u0432\u0438\u0434\u0430 0\/1, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u0440\u0430\u0437\u0431\u0440\u043e\u0441 \u0443\u0436\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0434\u0434\u0438\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0432 \u0447\u0438\u0441\u0442\u043e\u043c \u0432\u0438\u0434\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0438\u0435 \u0444\u043e\u0440\u043c\u044b \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438. \u0422\u0430\u043a \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c 0\/1 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u043a\u0430\u043a 1, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u043a\u043e\u0439 y, \u0438 0 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u0420\u0430\u0437\u0431\u0440\u043e\u0441, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0443 \u043c\u043e\u0434\u044b. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, bias-variance decomposition \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0441\u0451 \u0435\u0449\u0451 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043a \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u0442\u0435\u0440\u044c \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0445\u043e\u0442\u044f \u0438 \u043d\u0435 \u0432 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u0435. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0445 Domingos (2000) \u0438 Valentini &amp; Dietterich (2004).<\/p>\n<\/li>\n<li>\n<p>2) Bias-Variance trade-off \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 (DNN) \u0447\u0430\u0441\u0442\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0432\u043e\u0439\u043d\u043e\u0435 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435: \u043f\u043e \u043c\u0435\u0440\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u043d\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 U-\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0439 \u043a\u0440\u0438\u0432\u043e\u0439, \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0435 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u043e \u0438 \u0434\u043b\u044f \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0439 \u043d\u0430\u0434 \u0440\u0435\u0448\u0430\u044e\u0449\u0438\u043c\u0438 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0440\u043e\u0441\u0442\u0435 \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0438 \u0447\u0438\u0441\u043b\u0430 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432. \u041f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u043a \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0434\u0432\u0443\u043c\u044f \u0444\u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>Bias-variance decomposition \u0432 \u0441\u0432\u043e\u0451\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0435\u0442\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 DNN, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043b\u043e\u043a\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0443 \u043e\u0448\u0438\u0431\u043e\u043a. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e \u043d\u043e\u0432\u043e\u0435 \u044f\u0432\u043b\u0435\u043d\u0438\u0435, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u043a\u0430\u043a\u00a0<strong>\u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u0441\u043f\u0443\u0441\u043a \u043f\u043e \u044d\u043f\u043e\u0445\u0430\u043c<\/strong>\u00a0(Nakkiran et al., 2019), \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0435\u0435 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043f\u043e\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u0440\u0430\u0431\u043e\u0442\u0435 Heckel &amp; Yilmaz (2020) \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043f\u043e \u044d\u043f\u043e\u0445\u0430\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 DNN \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u044d\u043f\u043e\u0445\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043e \u043f\u0443\u0442\u0451\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0448\u0430\u0433\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u044f \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 optimization variance (OV). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0432\u0441\u0451 \u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043f\u0440\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438, \u043c\u044b \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><a class=\"anchor\" name=\"clustering_metrics\" id=\"clustering_metrics\"><\/a><\/p>\n<h3>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f. \u041d\u0430 \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d:<\/p>\n<ul>\n<li>\n<p>\u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u043a \u0441 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438, \u0434\u043b\u044f \u043d\u0430\u0441 \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0430\u043c \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0438\u0445 \u043f\u0440\u044f\u043c\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430:<\/p>\n<ul>\n<li>\n<p>1)\u00a0<strong>\u0412\u043d\u0435\u0448\u043d\u0438\u0435<\/strong>\u00a0\u2014 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u043a), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u041a \u043d\u0438\u043c \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f: Adjusted Rand Index (ARI), Mutual Information, Homogeneity, Completeness, V-measure, Fowlkes-Mallows score.<\/p>\n<\/li>\n<li>\n<p>2)\u00a0<strong>\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435<\/strong>\u00a0\u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430. \u0421\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435: Silhouette Coefficient, Calinski-Harabasz Index, Davies-Bouldin Index. \u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043a\u0430\u0445 (\u0447\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e).<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u0440\u0438\u043a \u043d\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 make blobs.<\/p>\n<p><strong>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/strong>  <\/p>\n<pre><code class=\"python\">import numpy as np from sklearn.datasets import make_blobs from sklearn.cluster import AffinityPropagation from sklearn.metrics import (rand_score, adjusted_rand_score, mutual_info_score,                              normalized_mutual_info_score, adjusted_mutual_info_score,                              homogeneity_score, completeness_score, v_measure_score,                              homogeneity_completeness_v_measure, fowlkes_mallows_score,                              silhouette_score, calinski_harabasz_score, davies_bouldin_score)<\/code><\/pre>\n<p><strong>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/strong>  <\/p>\n<pre><code class=\"python\">X, y = make_blobs(n_samples=75, n_features=2, centers=5, random_state=0) print(y)   [0 3 4 3 2 4 0 2 0 4 2 4 2 2 0 0 0 3 2 0 2 2 2 3 4 1 1 2 3 0 4 4 3 3 3 2 2  0 1 1 3 1 0 2 4 1 4 4 0 4 1 0 3 0 4 1 2 1 4 3 1 1 3 0 3 4 1 2 1 4 0 3 1 1  3]<\/code><\/pre>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 Affinity Propagation<\/strong>  <\/p>\n<pre><code class=\"python\">ap = AffinityPropagation() y_pred = ap.fit_predict(X) print(y_pred)   [2 0 1 2 3 1 2 3 2 1 3 1 3 4 2 2 2 0 3 2 3 3 2 0 1 4 4 3 0 3 1 1 0 0 0 3 3  2 4 4 0 4 2 3 1 4 1 1 4 1 4 2 0 2 1 4 3 4 1 0 4 4 0 2 0 1 4 3 3 1 2 0 4 4  0]<\/code><\/pre>\n<p><strong>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/strong>  <\/p>\n<pre><code class=\"python\">plt.scatter(X[:, 0], X[:, 1], c=y_pred, cmap='rainbow', s=10) plt.title('AffinityPropagation') plt.xlabel(\"Feature 1\") plt.ylabel(\"Feature 2\") plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b4d\/5a2\/51a\/b4d5a251aae4de9a9d3d185a3c5fca08.png\" width=\"565\" height=\"455\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b4d\/5a2\/51a\/b4d5a251aae4de9a9d3d185a3c5fca08.png\"\/><\/figure>\n<h4>Rand Index &amp; Adjusted Rand Index (ARI)<\/h4>\n<p>\u042f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c\u0438 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a.\u00a0<strong>Rand Index<\/strong>\u00a0\u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043e\u0442\u043d\u0435\u0441\u0451\u043d\u043d\u044b\u0445 \u043a \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0438 \u0440\u0430\u0437\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0430\u0440 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044f \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{RI} = \\frac{a + b}{C_2^{n_{samples}}}\" alt=\"\\text{RI} = \\frac{a + b}{C_2^{n_{samples}}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8e\/1a1\/a44\/c8e1a1a441b696a3143c814f6e75dc3c.svg\" width=\"115\" height=\"51\"\/><\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [0, 1], \u0433\u0434\u0435 1 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, Rand Index \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a \u043d\u0443\u043b\u044e (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0447\u0442\u043e \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432). \u042d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d \u043f\u043e\u0447\u0435\u043c\u0443 Rand Index \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0434\u0430\u0451\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443. <\/p>\n<pre><code class=\"python\">ri = rand_score(y, y_pred) print(f'rand index: {ri}')   rand index: 0.9405405405405406<\/code><\/pre>\n<p>\u041d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u043c\u043e\u0436\u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"E[\\text{RI}]\" alt=\"E[\\text{RI}]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/417\/e4f\/496\/417e4f496a93f162656de89a2dd407b5.svg\" width=\"47\" height=\"22\"\/>\u00a0\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u0432\u044b\u0448\u0435. \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u043a\u0430\u043a\u00a0<strong>Adjusted Rand Index (ARI)<\/strong>:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{ARI} = \\frac{\\text{RI} - E[\\text{RI}]}{\\max(\\text{RI}) - E[\\text{RI}]}\" alt=\"\\text{ARI} = \\frac{\\text{RI} - E[\\text{RI}]}{\\max(\\text{RI}) - E[\\text{RI}]}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/369\/06f\/6c8\/36906f6c8f56d369d6b7414b0ca53022.svg\" width=\"211\" height=\"50\"\/><\/p>\n<p>\u041e\u043d\u0430 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430, \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u043c\u0435\u0442\u043e\u043a \u0438 \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [-1, 1]. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u0435\u0442\u043a\u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. <\/p>\n<pre><code class=\"python\">ari = adjusted_rand_score(y, y_pred) print(f'adjusted rand index: {ari}')   adjusted rand index: 0.8063318846556483<\/code><\/pre>\n<h4>Mutual Information &amp; Adjusted Mutual Information (AMI)<\/h4>\n<p>\u0412\u0437\u0430\u0438\u043c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f\u00a0<strong>Mutual Information<\/strong>\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0440\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u044b \u043c\u0435\u0442\u043e\u043a\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"U, V\" alt=\"U, V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fc4\/170\/09f\/fc417009f0bd7251d226703469fa7a88.svg\" width=\"38\" height=\"20\"\/>\u00a0\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0438\u0445 \u043c\u0430\u0440\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0434\u0440\u0443\u0433\u043e\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0440\u0430 \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043c\u0435\u0440\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0441\u0442\u0438 \u2014 \u044d\u0442\u043e \u043d\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435, \u043a\u0430\u043a \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H(U) = - \\sum_{i=1}^{|U|}P(i)\\ln(P(i)) \\\\ H(V) = - \\sum_{j=1}^{|V|}P'(j)\\ln(P'(j))\" alt=\"H(U) = - \\sum_{i=1}^{|U|}P(i)\\ln(P(i)) \\\\ H(V) = - \\sum_{j=1}^{|V|}P'(j)\\ln(P'(j))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c37\/06d\/333\/c3706d333cbc4422ad3fc0c686bc666e.svg\" width=\"697\" height=\"133\"\/><\/p>\n<p>\u0433\u0434\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P(i) = |U_i| \/ N\" alt=\"P(i) = |U_i| \/ N\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/013\/205\/389\/01320538917dbdcb81a2f524deee1e77.svg\" width=\"119\" height=\"22\"\/>\u2014 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"U\" alt=\"U\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2a4\/087\/178\/2a4087178e77ec10e6b53f058b62249d.svg\" width=\"15\" height=\"17\"\/>\u0432 \u043a\u043b\u0430\u0441\u0441 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"U_i\" alt=\"U_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/77d\/091\/a08\/77d091a08bca910a19313290404ddd88.svg\" width=\"20\" height=\"20\"\/>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"V\" alt=\"V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ab\/fd6\/831\/0abfd68316f578d36a38b52c6d4abb99.svg\" width=\"15\" height=\"17\"\/> \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0432\u0437\u0430\u0438\u043c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043c\u0435\u0436\u0434\u0443 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"U\" alt=\"U\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/663\/2dd\/a28\/6632dda28b985b6d23fda4028f37d91d.svg\" width=\"15\" height=\"17\"\/> \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"V\" alt=\"V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/90f\/d57\/19c\/90fd5719c945c35233a3a344e009149e.svg\" width=\"15\" height=\"17\"\/> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{MI}(U, V) = \\sum_{i=1}^{|U|}\\sum_{j=1}^{|V|}P(i, j)\\ln\\left(\\frac{P(i,j)}{P(i)P'(j)}\\right)\" alt=\"\\text{MI}(U, V) = \\sum_{i=1}^{|U|}\\sum_{j=1}^{|V|}P(i, j)\\ln\\left(\\frac{P(i,j)}{P(i)P'(j)}\\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a86\/e6d\/10a\/a86e6d10ad329143dd38654f5aa70a41.svg\" width=\"353\" height=\"65\"\/><\/p>\n<p>\u0433\u0434\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P(i, j) = |U_i \\cap V_j| \/ N\" alt=\"P(i, j) = |U_i \\cap V_j| \/ N\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f44\/efe\/a35\/f44efea35c42a3160684cb21fc19084e.svg\" width=\"176\" height=\"23\"\/> \u2014 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"python\">mi = mutual_info_score(y, y_pred) print(f'mutual index: {mi}')   mutual index: 1.3165387166969102<\/code><\/pre>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u0442\u043e \u0435\u0441\u0442\u044c\u00a0<strong>Normalized Mutual Information (NMI)<\/strong>:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{NMI}(U, V) = \\frac{\\text{MI}(U, V)}{\\text{mean}(H(U), H(V))}\" alt=\"\\text{NMI}(U, V) = \\frac{\\text{MI}(U, V)}{\\text{mean}(H(U), H(V))}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a04\/717\/715\/a047177156aa44624c9f95b4fb75161e.svg\" width=\"287\" height=\"50\"\/><\/p>\n<pre><code class=\"python\">nmi = normalized_mutual_info_score(y, y_pred) print(f'normalized mutual index: {nmi}')   normalized mutual index: 0.8182376204426293<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043e\u0431\u0435 \u044d\u0442\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439: MI \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043b\u043e\u043d\u043d\u0430 \u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430 \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0451\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043c\u0435\u0442\u043a\u0430\u043c\u0438, \u0430 NMI \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 [0, 1].<\/p>\n<p>\u0414\u043b\u044f \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f\u00a0<strong>Adjusted Mutual Information (AMI)<\/strong>, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [0, 1], \u0433\u0434\u0435 0 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u043a, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u043b\u0438\u0437\u043a\u043e\u0435 \u043a 1 \u043d\u0430 \u0438\u0445 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{AMI} = \\frac{\\text{MI} - E[\\text{MI}]}{\\text{mean}(H(U), H(V)) - E[\\text{MI}]}\" alt=\"\\text{AMI} = \\frac{\\text{MI} - E[\\text{MI}]}{\\text{mean}(H(U), H(V)) - E[\\text{MI}]}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/08b\/865\/ff9\/08b865ff99fe048795e1e11c1e007d4e.svg\" width=\"308\" height=\"50\"\/><\/p>\n<p>\u0433\u0434\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"E[\\text{MI}(U,V)]=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\sum_{n_{ij}=(a_i+b_j-N)^+ }^{\\min(a_i, b_j)} \\frac{n_{ij}}{N}\\ln \\left( \\frac{ N.n_{ij}}{a_i b_j}\\right) \\cdot \\\\ \\cdot \\frac{a_i!b_j!(N-a_i)!(N-b_j)!}{N!n_{ij}!(a_i-n_{ij})!(b_j-n_{ij})! (N-a_i-b_j+n_{ij})!}\" alt=\"E[\\text{MI}(U,V)]=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\sum_{n_{ij}=(a_i+b_j-N)^+ }^{\\min(a_i, b_j)} \\frac{n_{ij}}{N}\\ln \\left( \\frac{ N.n_{ij}}{a_i b_j}\\right) \\cdot \\\\ \\cdot \\frac{a_i!b_j!(N-a_i)!(N-b_j)!}{N!n_{ij}!(a_i-n_{ij})!(b_j-n_{ij})! (N-a_i-b_j+n_{ij})!}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b1b\/186\/b21\/b1b186b21ffb0eb06403fecc2c595280.svg\" width=\"697\" height=\"127\"\/><\/p>\n<pre><code class=\"python\">ami = adjusted_mutual_info_score(y, y_pred) print(f'adjusted mutual index: {ami}')   adjusted mutual index: 0.8036319585502079<\/code><\/pre>\n<h4>Homogeneity, Completeness &amp; V-measure<\/h4>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439, \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439 \u043a\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u2014 \u043c\u0435\u0440\u0430 \u0442\u043e\u0433\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"h = 1 - \\frac{H(C|K)}{H(C)} \\\\ H(C) = - \\sum_{c=1}^{|C|} \\frac{n_c}{n} \\cdot \\log\\left(\\frac{n_c}{n}\\right) \\\\ H(C|K) = - \\sum_{c=1}^{|C|} \\sum_{k=1}^{|K|} \\frac{n_{c,k}}{n} \\cdot \\ln\\left(\\frac{n_{c,k}}{n_k}\\right)\" alt=\"h = 1 - \\frac{H(C|K)}{H(C)} \\\\ H(C) = - \\sum_{c=1}^{|C|} \\frac{n_c}{n} \\cdot \\log\\left(\\frac{n_c}{n}\\right) \\\\ H(C|K) = - \\sum_{c=1}^{|C|} \\sum_{k=1}^{|K|} \\frac{n_{c,k}}{n} \\cdot \\ln\\left(\\frac{n_{c,k}}{n_k}\\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/84e\/7da\/c07\/84e7dac077144b2d83938d82403c5df5.svg\" width=\"697\" height=\"186\"\/><\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u043b\u043d\u043e\u0442\u0430 \u2014 \u043c\u0435\u0440\u0430 \u0442\u043e\u0433\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"c = 1 - \\frac{H(K|C)}{H(K)}\" alt=\"c = 1 - \\frac{H(K|C)}{H(K)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/973\/cea\/7ba\/973cea7babb99d3690b2ef7e75d0e968.svg\" width=\"144\" height=\"50\"\/><\/p>\n<p>\u0433\u0434\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"C\" alt=\"C\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/726\/4bc\/025\/7264bc0254e77e87f587d988341a449d.svg\" width=\"15\" height=\"17\"\/>\u00a0\u2014 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0430\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/148\/b26\/e57\/148b26e574e9daa1d1fc10665072890b.svg\" width=\"17\" height=\"17\"\/>\u00a0\u2014 \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435.  <\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 ARI \u0438\u043b\u0438 AMI, \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043c\u0430\u043b\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0442\u044b\u0441\u044f\u0447\u0443, \u0430 \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043c\u0435\u043d\u044c\u0448\u0435 10. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0436\u0435 \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ARI.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u0443 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0431\u0430\u043b\u0430\u043d\u0441, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f\u00a0<strong>V-\u043c\u0435\u0440\u0430<\/strong>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0441\u043e\u0431\u043e\u0439 \u0433\u0430\u0440\u043c\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0438 \u044f\u0432\u043b\u044f\u044e\u0449\u0430\u044f\u0441\u044f \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0441\u043c\u044b\u0441\u043b\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043e\u043c NMI:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"v = 2 \\cdot \\frac{h \\cdot c}{h + c}\" alt=\"v = 2 \\cdot \\frac{h \\cdot c}{h + c}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b70\/7b6\/50e\/b707b650e140db9743544186fbd0476d.svg\" width=\"109\" height=\"44\"\/><\/p>\n<pre><code class=\"python\">homogeneity = homogeneity_score(y, y_pred) completeness = completeness_score(y, y_pred) v_measure = v_measure_score(y, y_pred)  print(f'homogeneity: {homogeneity}') print(f'completeness: {completeness}') print(f'v measure: {v_measure}')   homogeneity: 0.8180114973840702 completeness: 0.8184638685502272 v measure: 0.8182376204426292<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 3 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043b\u0435\u0436\u0430\u0442 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [0, 1], \u0433\u0434\u0435 1 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u0432 scikit-learn \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0442\u0440\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0441\u0440\u0430\u0437\u0443.  <\/p>\n<pre><code class=\"python\">hcv = homogeneity_completeness_v_measure(y, y_pred) print('homogeneity, completeness, v measure:', hcv, sep='\\n')   homogeneity, completeness, v measure: (0.8180114973840702, 0.8184638685502272, 0.8182376204426292)<\/code><\/pre>\n<h4>Fowlkes-Mallows Index (FMI)<\/h4>\n<p>Confusion matrix \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u00a0<strong>Fowlkes-Mallows Index (FMI)<\/strong>, \u0435\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043c\u0435\u0436\u0434\u0443 precision \u0438 recall:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{FMI} = \\frac{\\text{TP}}{\\sqrt{(\\text{TP} + \\text{FP}) (\\text{TP} + \\text{FN})}}\" alt=\"\\text{FMI} = \\frac{\\text{TP}}{\\sqrt{(\\text{TP} + \\text{FP}) (\\text{TP} + \\text{FN})}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/196\/1de\/bf9\/1961debf994fabeeb511566990f9b7b8.svg\" width=\"273\" height=\"53\"\/><\/p>\n<p>\u042d\u0442\u0430 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0442\u0430\u043a\u0436\u0435 \u043b\u0435\u0436\u0438\u0442 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [0, 1] \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043e\u0431 \u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443.  <\/p>\n<pre><code class=\"python\">fmi = fowlkes_mallows_score(y, y_pred) print(f'Fowlkes-Mallows index: {fmi}')   Fowlkes-Mallows index: 0.8430070419125244<\/code><\/pre>\n<h4>Silhouette Coefficient<\/h4>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0445\u043e\u0436\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0414\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u0446\u0430 \u0441\u0438\u043b\u0443\u044d\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"s = \\frac{b - a}{max(a, b)}\" alt=\"s = \\frac{b - a}{max(a, b)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1e7\/ee5\/5a4\/1e7ee55a4c5f5da8d022e8d680c2a012.svg\" width=\"122\" height=\"48\"\/><\/p>\n<p>\u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a\" alt=\"a\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f7f\/790\/a0b\/f7f790a0ba4afad1f809124081e4edf8.svg\" width=\"10\" height=\"12\"\/>\u00a0\u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0438 \u0432\u0441\u0435\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0432 \u0442\u043e\u043c \u0436\u0435 \u043a\u043b\u0430\u0441\u0441\u0435;<\/p>\n<\/li>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"b\" alt=\"b\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/34a\/030\/718\/34a03071839253b09f5d2740ac39295e.svg\" width=\"8\" height=\"17\"\/>\u00a0\u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0438 \u0432\u0441\u0435\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0441\u0438\u043b\u0443\u044d\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0438\u043b\u0443\u044d\u0442\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u043b\u0435\u0436\u0438\u0442 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [-1, 1], \u0433\u0434\u0435 -1 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, 1 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0432\u043e\u0438\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c, \u0430 0 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u0445.<\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0434\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u043b\u0443\u044d\u0442\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0438\u043b\u0443\u044d\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043b\u043e\u043d\u043d\u043e \u043a \u0437\u0430\u0432\u044b\u0448\u0435\u043d\u043d\u044b\u043c \u043e\u0446\u0435\u043d\u043a\u0430\u043c \u0434\u043b\u044f \u0432\u044b\u043f\u0443\u043a\u043b\u044b\u0445 \u0444\u043e\u0440\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0437\u0430\u043d\u0438\u0436\u0435\u043d\u043e \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u043e\u0440\u043c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"python\">silhouette = silhouette_score(X, y_pred) print(f'silhouette: {silhouette}')   silhouette: 0.5796452132316384<\/code><\/pre>\n<h4>Calinski-Harabasz Index (CHI)<\/h4>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043a\u0430\u043a \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0439 (VRC), \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0443\u043c\u043c \u043c\u0435\u0436\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0439 \u0438 \u0432\u043d\u0443\u0442\u0440\u0438\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0439:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"s = \\frac{\\mathrm{tr}(B_k)}{\\mathrm{tr}(W_k)} \\times \\frac{n_E - k}{k - 1}\" alt=\"s = \\frac{\\mathrm{tr}(B_k)}{\\mathrm{tr}(W_k)} \\times \\frac{n_E - k}{k - 1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8df\/6fd\/373\/8df6fd373830b18404e09c1d73a0765a.svg\" width=\"187\" height=\"50\"\/><\/p>\n<p>\u0433\u0434\u0435 \u043c\u0435\u0436\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u0430\u044f\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"B_k\" alt=\"B_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9de\/64b\/0b7\/9de64b0b7f66ffd96a4bf3cf3a65208a.svg\" width=\"24\" height=\"20\"\/>\u00a0\u0438 \u0432\u043d\u0443\u0442\u0440\u0438\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u0430\u044f\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"W_k\" alt=\"W_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/07a\/852\/093\/07a85209394e16bd3c8daef8dc490093.svg\" width=\"27\" height=\"20\"\/>\u00a0\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"B_k = \\sum_{q=1}^k n_q (c_q - c_E) (c_q - c_E)^T \\\\ W_k = \\sum_{q=1}^k \\sum_{x \\in C_q} (x - c_q) (x - c_q)^T\" alt=\"B_k = \\sum_{q=1}^k n_q (c_q - c_E) (c_q - c_E)^T \\\\ W_k = \\sum_{q=1}^k \\sum_{x \\in C_q} (x - c_q) (x - c_q)^T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb0\/2a7\/853\/eb02a78532f5535a4eca5a46a5585f65.svg\" width=\"697\" height=\"131\"\/><\/p>\n<p>\u0430 \u0442\u0430\u043a\u0436\u0435 \u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"C_q\" alt=\"C_q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fd4\/e15\/3b4\/fd4e153b4e03e49fc7420712cbbcac7a.svg\" width=\"22\" height=\"22\"\/>\u00a0\u2014 \u043d\u0430\u0431\u043e\u0440 \u0442\u043e\u0447\u0435\u043a \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/efa\/b69\/1e5\/efab691e582f7dfd9e7251bf9aa7e530.svg\" width=\"9\" height=\"15\"\/>;<\/p>\n<\/li>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"c_q\" alt=\"c_q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/51a\/86e\/67c\/51a86e67ca7028da31283927d6bc3185.svg\" width=\"17\" height=\"17\"\/>\u00a0\u2014 \u0446\u0435\u043d\u0442\u0440 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1b5\/a72\/61e\/1b5a7261ee3740ccdc3c2de82e7e8836.svg\" width=\"9\" height=\"15\"\/>;<\/p>\n<\/li>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"c_E\" alt=\"c_E\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb0\/277\/59a\/eb027759a358c7a9032dd79922d39cfa.svg\" width=\"21\" height=\"14\"\/>\u00a0\u2014 \u0446\u0435\u043d\u0442\u0440 \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\u00a0E\" alt=\"\u00a0E\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/15d\/5f0\/090\/15d5f0090d587ed2f6a758ffcee61eca.svg\" width=\"15\" height=\"17\"\/>;<\/p>\n<\/li>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n_q\" alt=\"n_q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/859\/bad\/c80\/859badc8006b5f7e92dda8e5df5169c8.svg\" width=\"20\" height=\"17\"\/>\u00a0\u2014 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/633\/084\/e56\/633084e5634e0ff3ccb854d81e9d590d.svg\" width=\"9\" height=\"15\"\/>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0435\u043c \u0432\u044b\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u041a\u0430\u043b\u0438\u043d\u0441\u043a\u0438-\u0425\u0430\u0440\u0430\u0431\u0430\u0448\u0430, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0447\u0451\u0442\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b. \u0425\u043e\u0442\u044f \u0434\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0438 \u043b\u0443\u0447\u0448\u0435 \u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f, \u043d\u043e, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a, \u043a\u0430\u043a \u0438 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0441\u0438\u043b\u0443\u044d\u0442\u0430.<\/p>\n<pre><code class=\"python\">chi = calinski_harabasz_score(X, y_pred) print(f'Calinski-Harabasz index: {chi}')   Calinski-Harabasz index: 305.667448634445<\/code><\/pre>\n<h4>Davies-Bouldin Index (DBI)<\/h4>\n<p>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u0435\u0440\u0430, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0449\u0430\u044f \u043c\u0435\u0436\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u0430\u043c\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"DB = \\frac{1}{k} \\sum_{i=1}^k \\max_{i \\neq j} R_{ij}\" alt=\"DB = \\frac{1}{k} \\sum_{i=1}^k \\max_{i \\neq j} R_{ij}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/56a\/f3a\/263\/56af3a263986ccf1c1e4f0eef1ee527b.svg\" width=\"174\" height=\"60\"\/><\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"R_{ij} = \\frac{s_i + s_j}{d_{ij}}\" alt=\"R_{ij} = \\frac{s_i + s_j}{d_{ij}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/932\/381\/922\/932381922539e079770d3217964d1ddd.svg\" width=\"115\" height=\"47\"\/><\/p>\n<p>\u0433\u0434\u0435\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/72c\/1f5\/706\/72c1f5706d72d1b56f5510e95a9e63f7.svg\" width=\"9\" height=\"12\"\/>\u00a0\u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0435\u0433\u043e \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u043e\u043c, \u0430\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_{ij}\" alt=\"d_{ij}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8c7\/404\/8e1\/8c74048e175e46d8306abbc2e945f47b.svg\" width=\"22\" height=\"22\"\/>\u00a0\u2014 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0430\u043c\u0438\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e3\/d4d\/032\/9e3d4d032e61aefde8fbf8296ef4ab92.svg\" width=\"7\" height=\"16\"\/>\u00a0\u0438\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"j\" alt=\"j\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/46e\/de9\/857\/46ede985775f1e28d49ae29c69e1c9d6.svg\" width=\"8\" height=\"19\"\/>.<\/p>\n<p>\u0412 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438 \u0432\u044b\u0448\u0435, \u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u043e\u0435 \u043a \u043d\u0443\u043b\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<strong>DBI<\/strong>\u00a0\u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u043b\u0443\u0447\u0448\u0435\u043c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0425\u043e\u0442\u044f \u0434\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0442\u0435\u043c \u0436\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c, \u0447\u0442\u043e \u0438 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0441\u0438\u043b\u0443\u044d\u0442\u0430, \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0438\u0437-\u0437\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">dbi = davies_bouldin_score(X, y_pred) print(f'Davies-Bouldin index: {dbi}')   Davies-Bouldin index: 0.546114132526905<\/code><\/pre>\n<hr\/>\n<p><a class=\"anchor\" name=\"additional_sources\" id=\"additional_sources\"><\/a><\/p>\n<h3>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/h3>\n<p>\u0421\u0442\u0430\u0442\u044c\u0438:<\/p>\n<ul>\n<li>\n<p>\u00abAn introduction to ROC analysis\u00bb, Tom Fawcett;<\/p>\n<\/li>\n<li>\n<p>\u00abThe Relationship Between Precision-Recall and ROC Curves\u00bb, Jesse Davis, Mark Goadrich;<\/p>\n<\/li>\n<li>\n<p>\u00abPrecision-Recall-Gain Curves: PR Analysis Done Right\u00bb, Peter A. Flach, Meelis Kull;<\/p>\n<\/li>\n<li>\n<p>\u00abInvestigation of performance metrics in regression analysis and machine learning-based prediction models\u00bb, V. Plevris, G. Solorzano, N. Bakas, M. Ben Seghier;<\/p>\n<\/li>\n<li>\n<p>\u00abA Unified Bias-Variance Decomposition and its Applications\u00bb, Pedro Domingos;<\/p>\n<\/li>\n<li>\n<p>\u00abBias-Variance Analysis of Support Vector Machines for the Development of SVM-Based Ensemble Methods\u00bb, Giorgio Valentini, Thomas G. Dietterich;<\/p>\n<\/li>\n<li>\n<p>\u00abOptimization Variance: Exploring Generalization Properties of DNNs\u00bb, Xiao Zhang, Dongrui Wu, Haoyi Xiong, Bo Dai;<\/p>\n<\/li>\n<li>\n<p>\u00abDeep Double Descent: Where Bigger Models and More Data Hurt\u00bb, Preetum Nakkiran, Gal Kaplun, Yamini Bansal, Tristan Yang, Boaz Barak, Ilya Sutskever;<\/p>\n<\/li>\n<li>\n<p>\u00abEarly Stopping in Deep Networks: Double Descent and How to Eliminate it\u00bb, Reinhard Heckel, Fatih Furkan Yilmaz;<\/p>\n<\/li>\n<li>\n<p>\u00abPointwise Metrics for Clustering Evaluation\u00bb, Stephan van Staden.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/scikit-learn.org\/stable\/modules\/model_evaluation.html\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/a>;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/scikit-learn.org\/stable\/modules\/clustering.html#clustering-evaluation\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/813221\/\" rel=\"noopener noreferrer nofollow\"><strong>\u041c\u0435\u0442\u043e\u0434\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 ML \u0438 DL ?<\/strong><\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/821547\/\"> https:\/\/habr.com\/ru\/articles\/821547\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div class=\"floating-image\">\n<figure class=\"float full-width\"><\/figure>\n<p>\u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0435\u0451 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u043c \u0432\u044b\u0432\u043e\u0434\u0430\u043c \u0438, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u043a \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044e \u043d\u0435 \u0441\u0430\u043c\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0435\u0442\u0440\u0438\u043a, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043a\u0430\u043a bias-variance decomposition. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u0435\u0442\u0440\u0438\u043a \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0443\u0447\u043d\u044b\u0435 \u0440\u0430\u0441\u0447\u0451\u0442\u044b \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043d\u0443\u043b\u044f \u043d\u0430 Python, \u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/div>\n<blockquote>\n<p><strong>? <em>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c:<\/em><\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/804605\/\" rel=\"noopener noreferrer nofollow\"><em>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ML-\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0441 \u043d\u0443\u043b\u044f \u043d\u0430 Python<\/em><\/a><\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p><em>\u041d\u043e\u0443\u0442\u0431\u0443\u043a \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043d\u0430<\/em> <strong><em>GitHub<\/em><\/strong> (<a href=\"https:\/\/github.com\/egaoharu-kensei\/ML-algorithms-from-scratch.-Course-for-beginners\/blob\/main\/Notebooks%20%5Brus%5D\/08%29%20%D0%9C%D0%B5%D1%82%D1%80%D0%B8%D0%BA%D0%B8%20%D0%BA%D0%B0%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%B0%20%D0%B8%20%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7%20%D0%BE%D1%88%D0%B8%D0%B1%D0%BE%D0%BA%20%D0%B2%20ML.ipynb\" rel=\"noopener noreferrer nofollow\"><em>rus<\/em><\/a><em>, <\/em><a href=\"https:\/\/github.com\/egaoharu-kensei\/ML-algorithms-from-scratch.-Course-for-beginners\/blob\/main\/Notebooks%20%5Beng%5D\/08%29%20Quality%20metrics%20and%20error%20analysis%20in%20ML.ipynb\" rel=\"noopener noreferrer nofollow\"><em>eng<\/em><\/a>) \u0438 <strong><em>Kaggle<\/em><\/strong> (<a href=\"https:\/\/www.kaggle.com\/code\/egazakharenko\/quality-metrics-and-error-analysis-in-ml-guide\" rel=\"noopener noreferrer nofollow\"><em>eng<\/em><\/a>)<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<h3>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h3>\n<ul>\n<li>\n<p><a href=\"#classification_metrics\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#regression_metrics\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#bias-variance\" rel=\"noopener noreferrer nofollow\">\u0410\u043d\u0430\u043b\u0438\u0437 \u043e\u0448\u0438\u0431\u043e\u043a (bias-variance decomposition)<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#clustering_metrics\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#additional_sources\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/a><\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><a class=\"anchor\" name=\"classification_metrics\" id=\"classification_metrics\"><\/a><\/p>\n<h3>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0441\u0442\u043e\u0438\u0442 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a (confusion matrix) \u0438 \u0435\u0451 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (TP) \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (TN) \u043a\u043b\u0430\u0441\u0441\u044b, \u0430 \u043d\u0430 \u043f\u043e\u0431\u043e\u0447\u043d\u043e\u0439 \u2014 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0451 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e (FP) \u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e (FN) \u0440\u043e\u0434\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0443\u0447\u0438\u043c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044e \u043d\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 <a href=\"https:\/\/www.kaggle.com\/datasets\/uciml\/breast-cancer-wisconsin-data\" rel=\"noopener noreferrer nofollow\">Breast Cancer Wisconsin<\/a> \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0435\u0451 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u0434\u0430\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0441\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0432 scikit-learn \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0448\u0435, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0443\u0442\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e: <\/p>\n<p><strong>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/strong>  <\/p>\n<pre><code class=\"python\">import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import confusion_matrix from sklearn.preprocessing import LabelEncoder from sklearn.metrics import (accuracy_score, precision_score, recall_score, f1_score,                              fbeta_score, roc_curve, roc_auc_score, precision_recall_curve,                              auc, average_precision_score, classification_report)<\/code><\/pre>\n<p><strong>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/strong><\/p>\n<pre><code class=\"python\">df_path = \"\/content\/drive\/MyDrive\/breast_cancer.csv\" breast_cancer = pd.read_csv(df_path) breast_cancer.drop(columns=['id','Unnamed: 32'], inplace=True) print(breast_cancer)  X = breast_cancer.drop(columns='diagnosis', axis=1) y = breast_cancer['diagnosis'] y = LabelEncoder().fit_transform(y)  # 1 - Malignant, 0 - Benign X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)       diagnosis  radius_mean  texture_mean  perimeter_mean  area_mean  \\ 0           M        17.99         10.38          122.80     1001.0    1           M        20.57         17.77          132.90     1326.0    2           M        19.69         21.25          130.00     1203.0    3           M        11.42         20.38           77.58      386.1    4           M        20.29         14.34          135.10     1297.0    ..        ...          ...           ...             ...        ...    564         M        21.56         22.39          142.00     1479.0    565         M        20.13         28.25          131.20     1261.0    566         M        16.60         28.08          108.30      858.1    567         M        20.60         29.33          140.10     1265.0    568         B         7.76         24.54           47.92      181.0          smoothness_mean  compactness_mean  concavity_mean  concave points_mean  \\ 0            0.11840           0.27760         0.30010              0.14710    1            0.08474           0.07864         0.08690              0.07017    2            0.10960           0.15990         0.19740              0.12790    3            0.14250           0.28390         0.24140              0.10520    4            0.10030           0.13280         0.19800              0.10430    ..               ...               ...             ...                  ...    564          0.11100           0.11590         0.24390              0.13890    565          0.09780           0.10340         0.14400              0.09791    566          0.08455           0.10230         0.09251              0.05302    567          0.11780           0.27700         0.35140              0.15200    568          0.05263           0.04362         0.00000              0.00000          symmetry_mean  ...  radius_worst  texture_worst  perimeter_worst  \\ 0           0.2419  ...        25.380          17.33           184.60    1           0.1812  ...        24.990          23.41           158.80    2           0.2069  ...        23.570          25.53           152.50    3           0.2597  ...        14.910          26.50            98.87    4           0.1809  ...        22.540          16.67           152.20    ..             ...  ...           ...            ...              ...    564         0.1726  ...        25.450          26.40           166.10    565         0.1752  ...        23.690          38.25           155.00    566         0.1590  ...        18.980          34.12           126.70    567         0.2397  ...        25.740          39.42           184.60    568         0.1587  ...         9.456          30.37            59.16          area_worst  smoothness_worst  compactness_worst  concavity_worst  \\ 0        2019.0           0.16220            0.66560           0.7119    1        1956.0           0.12380            0.18660           0.2416    2        1709.0           0.14440            0.42450           0.4504    3         567.7           0.20980            0.86630           0.6869    4        1575.0           0.13740            0.20500           0.4000    ..          ...               ...                ...              ...    564      2027.0           0.14100            0.21130           0.4107    565      1731.0           0.11660            0.19220           0.3215    566      1124.0           0.11390            0.30940           0.3403    567      1821.0           0.16500            0.86810           0.9387    568       268.6           0.08996            0.06444           0.0000          concave points_worst  symmetry_worst  fractal_dimension_worst   0                  0.2654          0.4601                  0.11890   1                  0.1860          0.2750                  0.08902   2                  0.2430          0.3613                  0.08758   3                  0.2575          0.6638                  0.17300   4                  0.1625          0.2364                  0.07678   ..                    ...             ...                      ...   564                0.2216          0.2060                  0.07115   565                0.1628          0.2572                  0.06637   566                0.1418          0.2218                  0.07820   567                0.2650          0.4087                  0.12400   568                0.0000          0.2871                  0.07039    [569 rows x 31 columns]<\/code><\/pre>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/strong> <\/p>\n<pre><code class=\"python\">model = LogisticRegression(max_iter=10000) model.fit(X_train, y_train) y_pred = model.predict(X_test) print(y_pred)   [1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0  1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 0 0  1 0 0 0 0 0 1 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 1 0  1 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1]<\/code><\/pre>\n<p><strong>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f confusion matrix<\/strong><\/p>\n<pre><code class=\"python\">conf_matrix = confusion_matrix(y_test, y_pred)  sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Reds') plt.title('Confusion Matrix') plt.xlabel('Predicted Label') plt.ylabel('True Label') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u0413\u043b\u044f\u0434\u044f \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>(True Positive) \u2014 52 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u043d\u044b\u0435 \u0438 \u043e\u043d\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u0435\u0440\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>(True Negative) \u2014 84 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0437\u0434\u043e\u0440\u043e\u0432\u044b\u0435 \u0438 \u043e\u043d\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u0435\u0440\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>(False Positive) \u2014 6 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u043d\u044b\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u0438\u043c\u0435\u044e\u0442 \u0437\u043b\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u043f\u0443\u0445\u043e\u043b\u044c), \u043d\u043e \u043e\u043d\u0438 \u0437\u0434\u043e\u0440\u043e\u0432\u044b\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043f\u0443\u0445\u043e\u043b\u044c \u0434\u043e\u0431\u0440\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f);<\/p>\n<\/li>\n<li>\n<p>(False Negative) \u2014 1 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043a\u0430\u043a \u0437\u0434\u043e\u0440\u043e\u0432\u044b\u0439, \u043d\u043e \u043e\u043d \u0431\u043e\u043b\u0435\u043d (\u0442\u043e \u0435\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442 \u0437\u043b\u043e\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u043f\u0443\u0445\u043e\u043b\u044c).<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u0441\u0430\u043c\u0438\u043c \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c.<\/p>\n<h4>Accuracy<\/h4>\n<p>\u0421\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f\u00a0<strong>Accuracy<\/strong>\u00a0\u0438\u043b\u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u043e\u043b\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432:<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Accuracy \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u043e\u043b\u044e \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439\u00a0<strong>Error rate<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438:  <\/p>\n<pre><code class=\"python\">accuracy = accuracy_score(y_test, y_pred) error_rate = 1 - accuracy print(f'Accuracy: {accuracy}') print(f'Error rate: {error_rate}')   Accuracy: 0.951048951048951 Error rate: 0.04895104895104896<\/code><\/pre>\n<p>\u041d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0441\u0432\u043e\u044e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c, Accuracy \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u0432: \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0430\u0434 \u0434\u0440\u0443\u0433\u0438\u043c, \u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0430 \u0432 \u0435\u0433\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u0443, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0430\u0436\u0430\u0442\u044c \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0434\u0430\u0451\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0438\u043f\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u043b\u043e\u0436\u043d\u043e\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0446\u0435\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u043e\u0440\u043e\u0433\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438.<\/p>\n<h4>Precision<\/h4>\n<p>\u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u0442 \u0434\u043e\u043b\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u043a\u0430\u043a \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"python\">precision = precision_score(y_test, y_pred) print(precision)   0.896551724137931<\/code><\/pre>\n<h4>Recall (TPR)<\/h4>\n<p>\u0415\u0449\u0451 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u043a\u0430\u043a True Positive Rate, \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u043e\u043b\u044e<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-379641","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379641","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=379641"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379641\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}