{"id":448745,"date":"2025-02-19T03:02:47","date_gmt":"2025-02-19T03:02:47","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=448745"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=448745","title":{"rendered":"<span>\u0412\u044b\u044f\u0432\u043b\u044f\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Isolation Forest<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437\u00a0\u0441\u0430\u043c\u044b\u0445 \u043c\u043e\u0449\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>Isolation Forest<\/strong>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0443\u0442\u044c, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043b\u0435\u0441. \u0412\u044b \u0438\u0434\u0451\u0442\u0435 \u043f\u043e\u00a0\u043d\u0435\u043c\u0443, \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0427\u0435\u043c\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u044b \u043d\u0430\u0442\u044b\u043a\u0430\u0435\u0442\u0435\u0441\u044c \u043d\u0430\u00a0\u0440\u0435\u0434\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f. Isolation Forest \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u0443\u00a0\u0436\u0435 \u0438\u0434\u0435\u044e, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0443\u00a0\u043d\u0430\u0441 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430\u00a0\u0432\u043c\u0435\u0441\u0442\u043e \u043b\u0435\u0441\u0430\u00a0\u2014 \u0440\u0435\u0448\u0430\u044e\u0449\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f (\u043c\u0435\u0442\u0430\u0444\u043e\u0440\u0430 \u0432\u0435\u043a\u0430).<\/p>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f<\/h4>\n<p>\u041e\u0431\u044b\u0447\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>SVM \u0438\u043b\u0438\u00a0\u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438<\/strong>, \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f <strong>\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u0432\u044b\u0431\u0440\u043e\u0441\u044b. Isolation Forest \u0438\u0434\u0451\u0442 \u0441\u00a0\u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043d\u0446\u0430: \u043e\u043d <strong>\u043d\u0435\u00a0\u0441\u0442\u0440\u043e\u0438\u0442 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c<\/strong>, \u0430\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0431\u0440\u043e\u0441\u044b.<\/p>\n<p>\u041a\u0430\u043a\u00a0\u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0442\u0440\u043e\u0438\u043c \u0434\u0435\u0440\u0435\u0432\u043e<\/strong>, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0434\u0435\u043b\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435<\/strong>, \u043f\u043e\u043a\u0430 \u043a\u0430\u0436\u0434\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043d\u0435\u00a0\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432\u00a0\u0441\u0432\u043e\u0451\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u00a0\u043b\u0438\u0441\u0442\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/strong> \u0442\u043e\u0447\u043a\u0438 \u043f\u043e\u00a0\u0442\u043e\u043c\u0443, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e\u00a0\u0431\u044b\u0441\u0442\u0440\u043e \u043e\u043d\u0430\u00a0\u0431\u044b\u043b\u0430 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 (\u0447\u0435\u043c \u043a\u043e\u0440\u043e\u0447\u0435 \u043f\u0443\u0442\u044c, \u0442\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u0435\u0435).<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u00a0\u043f\u0430\u0440\u0443 \u0448\u0430\u0433\u043e\u0432\u00a0\u2014 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u043e\u043d \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437\u00a0\u043e\u0431\u0449\u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u044b.<\/p>\n<h3>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u2014 \u043a\u043e\u0434<\/h3>\n<p>\u0411\u0435\u0440\u0451\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0438 \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043b\u043e\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.ensemble import IsolationForest  # \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0435\u0439\u043a\u043e\u0432\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 np.random.seed(42) n_samples = 1000  # \"\u041d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435\" \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 amounts = np.random.normal(loc=50, scale=10, size=n_samples) durations = np.random.normal(loc=5, scale=2, size=n_samples) num_items = np.random.normal(loc=3, scale=1, size=n_samples)  # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 (\u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u0443\u043c\u043c\u044b) anomaly_size = 50 amounts[:anomaly_size] = np.random.normal(loc=300, scale=50, size=anomaly_size) durations[:anomaly_size] = np.random.normal(loc=20, scale=5, size=anomaly_size) num_items[:anomaly_size] = np.random.normal(loc=10, scale=3, size=anomaly_size)  df = pd.DataFrame({'amount': amounts, 'duration': durations, 'num_items': num_items})<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0434\u0435 50\u00a0\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u044f\u0432\u043d\u043e \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b (\u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0441\u0443\u043c\u043c\u044b \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c). \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0445.<\/p>\n<pre><code class=\"python\"># \u041e\u0431\u0443\u0447\u0430\u0435\u043c Isolation Forest model = IsolationForest(contamination=0.05, random_state=42)  # 5% \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 df['is_anomaly'] = model.fit_predict(df[['amount', 'duration', 'num_items']])  # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c -1 (\u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f) \u0438 1 (\u043d\u043e\u0440\u043c\u0430) \u0432 0\/1 df['is_anomaly'] = df['is_anomaly'].map({1: 0, -1: 1})  # \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c plt.figure(figsize=(10,6)) plt.scatter(df['amount'], df['duration'], c=df['is_anomaly'], cmap='coolwarm', alpha=0.7) plt.xlabel('Transaction Amount') plt.ylabel('Transaction Duration') plt.title('Isolation Forest Anomaly Detection') plt.colorbar(label=\"Anomaly Score\") plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/353\/8c7\/ed8\/3538c7ed86bf3e13647c911c2a6d4fca.png\" alt=\"\u0413\u0440\u0430\u0444\u0438\u043a\" title=\"\u0413\u0440\u0430\u0444\u0438\u043a\" width=\"800\" height=\"547\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/353\/8c7\/ed8\/3538c7ed86bf3e13647c911c2a6d4fca.png\"\/><\/p>\n<div><figcaption>\u0413\u0440\u0430\u0444\u0438\u043a<\/figcaption><\/div>\n<\/figure>\n<p>\u0413\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043f\u043e\u00a0\u0434\u0432\u0443\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c: <strong>\u0441\u0443\u043c\u043c\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 <\/strong><code>amount<\/code> \u0438 <strong>\u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c <\/strong><code>duration<\/code>.<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0438\u043d\u0438\u0435 \u0442\u043e\u0447\u043a\u0438<\/strong>\u00a0\u2014 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0443\u043c\u043c\u044b \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c).<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438<\/strong>\u00a0\u2014 \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u0443\u043c\u043c\u044b \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f).<\/p>\n<\/li>\n<li>\n<p><strong>\u0426\u0432\u0435\u0442\u043e\u0432\u0430\u044f \u0448\u043a\u0430\u043b\u0430<\/strong>\u00a0\u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0430 \u043a\u0430\u043a <code>\"Anomaly Classification\"<\/code>, \u043e\u0442\u0440\u0430\u0436\u0430\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u0443\u044e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e: <code>0<\/code> (\u043d\u043e\u0440\u043c\u0430) \u0438 <code>1<\/code> (\u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f).<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c <code>Isolation Forest<\/code> \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0430 50\u00a0\u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439. \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e\u00a0\u043e\u043d\u0438 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u00a0\u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c\u0438 \u0441\u0443\u043c\u043c\u0430\u043c\u0438 (200\u2013400) \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0432\u044b\u0448\u0435 15\u00a0\u0441\u0435\u043a\u0443\u043d\u0434. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0441\u044b.<\/p>\n<h3>\u041a\u0430\u043a \u0432\u044b\u0436\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0438\u0437 Isolation Forest<\/h3>\n<p>\u041a\u0430\u043a\u00a0\u0438 \u043b\u044e\u0431\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, Isolation Forest \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 <strong>\u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/strong>. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"158\" width=\"158\">\n<p>\u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<\/p>\n<\/th>\n<th>\n<p>\u0427\u0442\u043e\u00a0\u0434\u0435\u043b\u0430\u0435\u0442<\/p>\n<\/th>\n<th>\n<p>\u041a\u0430\u043a\u00a0\u0432\u043b\u0438\u044f\u0435\u0442<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>n_estimators<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432\u00a0\u043b\u0435\u0441\u0443<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0411\u043e\u043b\u044c\u0448\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u2192 \u043b\u0443\u0447\u0448\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u043e\u00a0\u0434\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>max_samples<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 256, \u043c\u043e\u0436\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0434\u043b\u044f\u00a0\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>contamination<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u043b\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u043b\u0438\u044f\u0435\u0442 \u043d\u0430\u00a0\u043f\u043e\u0440\u043e\u0433 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>max_features<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0434\u0435\u0440\u0435\u0432\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u043b\u043e, \u043b\u0443\u0447\u0448\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=200, max_samples=500, contamination=0.02, max_features=2, random_state=42) model.fit(df) df['is_anomaly'] = model.predict(df) df['is_anomaly'] = df['is_anomaly'].map({1: 0, -1: 1})<\/code><\/pre>\n<h3>\u041b\u0438\u043c\u0438\u0442\u044b Isolation Forest<\/h3>\n<p>\u041d\u0435\u00a0\u0441\u0442\u043e\u0438\u0442 \u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0\u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u00a0\u2014 \u0441\u0435\u0440\u0435\u0431\u0440\u044f\u043d\u0430\u044f \u043f\u0443\u043b\u044f. \u041e\u043d \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u044b\u0445 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439, \u043d\u043e\u00a0\u0432\u043e\u0442 \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c\u0438 \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u0441\u044f\u0447\u0438\u0442\u044c.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<ol>\n<li>\n<p><strong>\u041f\u043b\u043e\u0445\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u00a0\u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0442\u044b\u0441\u044f\u0447\u0438 \u0444\u0438\u0447\u0435\u0439, \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0431\u0443\u0434\u0443\u0442 \u0440\u0443\u0431\u0438\u0442\u044c \u043d\u0430\u0443\u0433\u0430\u0434.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0435\u00a0\u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b, \u043b\u0443\u0447\u0448\u0435 \u0432\u0437\u044f\u0442\u044c LSTM \u0438\u043b\u0438\u00a0Prophet.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 contamination<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u043e\u043d \u0437\u0430\u0434\u0430\u043d \u043d\u0435\u0432\u0435\u0440\u043d\u043e, \u043c\u043e\u0436\u043d\u043e\u00a0\u043b\u0438\u0431\u043e \u043d\u0435\u00a0\u043d\u0430\u0439\u0442\u0438 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438,\u00a0\u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0438\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 Isolation Forest \u043d\u0435\u00a0\u0437\u0430\u0448\u0451\u043b, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><strong>LOF (Local Outlier Factor)<\/strong>\u00a0\u2014 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0435\u0434\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>Autoencoders<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0432\u00a0\u043f\u0440\u043e\u0434\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>One\u2011Class SVM<\/strong>\u00a0\u2014 \u0438\u043d\u043e\u0433\u0434\u0430 \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e\u00a0\u0436\u0440\u0451\u0442 \u043c\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u0430\u043a \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e Isolation Forest?<\/h3>\n<p>\u0421\u0443\u043f\u0435\u0440, \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u043d\u043e \u043a\u0430\u043a\u00a0\u043f\u043e\u043d\u044f\u0442\u044c, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u00a0\u043b\u0438 \u043e\u043d\u0430 \u0445\u043e\u0440\u043e\u0448\u043e? \u0412\u00a0\u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442\u00a0\u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0442\u0443\u0442 \u043d\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043a\u0430\u043a\u00a0accuracy \u0438\u043b\u0438\u00a0F1-score, \u043d\u0435\u00a0\u043f\u043e\u043c\u043e\u0433\u0443\u0442.<\/p>\n<p>\u041d\u043e\u00a0\u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438:<\/p>\n<h4>\u0420\u0443\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430<\/h4>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e\u00a0\u043c\u043e\u0449\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043f\u043e\u00a0\u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f\u043c<\/p>\n<\/li>\n<li>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u043f-100\u00a0\u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">df.sort_values(by='is_anomaly', ascending=False).head(100)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u00a0\u0442\u043e\u043f\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u0443\u043c\u043c\u044b, \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u044b)\u00a0\u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h4>\u0410\u043d\u0430\u043b\u0438\u0437 &#171;decision_function()&#187;<\/h4>\n<p>Isolation Forest \u0434\u0430\u0451\u0442 \u043e\u0446\u0435\u043d\u043a\u0443 \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043d\u0435\u00a0\u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 0\/1, \u0430\u00a0\u0447\u0438\u0441\u043b\u043e \u043e\u0442 -0.5\u00a0\u0434\u043e 0.5. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u00ab\u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043e\u043d\u044b\u00bb:<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np from sklearn.ensemble import IsolationForest from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.pipeline import Pipeline from joblib import dump  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0437\u0430\u043a\u0430\u0437\u0430\u0445 df = pd.read_csv(\"orders.csv\")  # \u041e\u0442\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 num_features = ['amount', 'duration', 'num_items'] cat_features = ['payment_method', 'country']  # \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438 df[num_features] = df[num_features].fillna(df[num_features].median()) df[cat_features] = df[cat_features].fillna('Unknown')  # \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 df = pd.get_dummies(df, columns=cat_features, drop_first=True)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435<strong>\u0442,<\/strong> \u0447\u0442\u043e \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 \u0447\u0451\u0442\u043a\u043e \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u044b\u00a0\u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<h4>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443\u00a0\u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u0442\u0432\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, chargebacks). \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0445 \u043b\u043e\u0432\u0438\u0442:<\/p>\n<pre><code class=\"python\">fraud_orders = df[df['chargeback'] == 1] fraud_detected = df[(df['chargeback'] == 1) &amp; (df['is_anomaly'] == 1)]  print(f\"\u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e {len(fraud_detected)} \u0438\u0437 {len(fraud_orders)} \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432.\") <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 (&gt;70%), \u0437\u043d\u0430\u0447\u0438\u0442, Isolation Forest \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h3>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>Isolation Forest \u0445\u043e\u0440\u043e\u0448, \u043d\u043e\u00a0\u043e\u043d \u043d\u0435\u00a0\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f\u00a0\u043b\u0438\u043d\u0435\u0439\u043d\u043e. \u0415\u0441\u043b\u0438 \u0443\u00a0\u043d\u0430\u0441 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>fit()<\/code> \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 1: max_samples<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0433\u043e, \u043b\u0443\u0447\u0448\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c <code>max_samples<\/code>. \u0412 <code>sklearn<\/code> \u043f\u043e\u00a0\u0434\u0435\u0444\u043e\u043b\u0442\u0443: <code>max_samples = min(256, n_samples)<\/code><\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e:<\/p>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=100, max_samples=5000, contamination=0.01, n_jobs=-1, random_state=42)<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432<strong>\u0430\u0442<\/strong>\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0441\u0442\u0440\u043e\u043a, \u043d\u0435\u00a0\u0442\u0435\u0440\u044f\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 2: n_jobs=-1<\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u044f\u0434\u0440\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430:<\/p>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=200, max_samples=5000, contamination=0.01, n_jobs=-1)<\/code><\/pre>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 3: GPU-\u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435<\/h4>\n<p>Isolation Forest \u043d\u0435\u0442 \u0432 <code>cuML<\/code>, \u043d\u043e\u00a0\u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438. \u041e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0430 <strong>GPU<\/strong> \u0438\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<h4>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/h4>\n<p>Isolation Forest\u00a0\u2014 \u043c\u043e\u0449\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043d\u043e\u00a0\u043e\u0434\u043d\u043e \u0434\u0435\u043b\u043e \u043d\u0430\u0442\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u00a0\u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0435\u00a0\u2014 \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u00a0\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u0438\u0437\u043d\u0435\u0441. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f, \u043a\u0430\u043a\u00a0\u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u0430\u0441\u0442\u0438 \u043c\u0430\u0433\u0430\u0437\u0438\u043d \u044d\u043b\u0438\u0442\u043d\u044b\u0445 \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u043e\u0442\u00a0\u043c\u043e\u0448\u0435\u043d\u043d\u0438\u043a\u043e\u0432.<\/p>\n<h3>\u041a\u0435\u0439\u0441: \u043c\u0430\u0433\u0430\u0437\u0438\u043d \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e\u00a0\u0443\u00a0\u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u043d\u043b\u0430\u0439\u043d\u2011\u043c\u0430\u0433\u0430\u0437\u0438\u043d \u043f\u043e\u0440\u043e\u0434\u0438\u0441\u0442\u044b\u0445 \u043a\u043e\u0442\u0438\u043a\u043e\u0432. \u0426\u0435\u043d\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043e\u0442 500$, \u043d\u043e\u00a0\u0437\u0430\u00a0\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0437\u0430\u00a0\u0431\u0440\u0438\u0442\u0430\u043d\u0446\u0435\u0432 \u0438\u043b\u0438\u00a0\u043c\u0435\u0439\u043d\u2011\u043a\u0443\u043d\u043e\u0432) \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442 \u0438 \u043f\u043e 5000$.<\/p>\n<p>\u0412\u0441\u0451\u00a0\u0431\u044b\u043b\u043e\u00a0\u0431\u044b \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e&#8230;<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b: \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043a\u0443\u043f\u0430\u0435\u0442 15\u00a0\u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0441\u0440\u0430\u0437\u0443, \u043f\u043b\u0430\u0442\u0438\u0442 \u0441\u00a0\u043a\u0440\u0435\u0434\u0438\u0442\u043a\u0438 \u0438\u0437\u00a0\u0418\u043d\u0434\u043e\u043d\u0435\u0437\u0438\u0438, \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430\u00a0\u2014 \u043d\u0430\u00a0\u043f\u043e\u0447\u0442\u0443 \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u00a0\u041d\u043e\u0432\u043e\u0441\u0438\u0431\u0438\u0440\u0441\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u0442\u0451\u0436\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0436\u0430\u043b\u0443\u044e\u0442\u0441\u044f: \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u044b\u0439 \u0440\u0438\u0441\u043a chargeback&#8217;\u043e\u0432\u00a0\u2014 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0437\u0430\u044f\u0432\u043b\u044f\u044e\u0442, \u0447\u0442\u043e\u00a0\u043d\u0435\u00a0\u0434\u0435\u043b\u0430\u043b\u0438 \u0437\u0430\u043a\u0430\u0437\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b: \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435\u00a0\u0436\u0435 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u0438 \u043c\u0435\u043d\u044f\u044e\u0442 \u0438\u043c\u0435\u043d\u0430, \u043d\u043e\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442\u00a0\u0436\u0435 IP.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u0440\u043e\u0447\u0435, \u0437\u0430\u043f\u0430\u0445\u043b\u043e \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u043a\u0430\u043c\u0438, \u0438 \u043d\u0430\u0448\u0435\u043c\u0443 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0443 \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0441\u0440\u043e\u0447\u043d\u043e \u043d\u0443\u0436\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0442\u044c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b, \u0434\u043e\u00a0\u0442\u043e\u0433\u043e \u043a\u0430\u043a\u00a0\u043a\u043e\u0442\u0438\u043a \u0443\u0435\u0445\u0430\u043b \u0432\u00a0\u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u00a0\u0437\u0430\u043a\u0430\u0437\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c Isolation Forest \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u044f\u0432\u043b\u044f\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0438\u0445.<\/p>\n<\/li>\n<\/ol>\n<h4>\u0414\u0430\u043d\u043d\u044b\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c<\/h4>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"88\" width=\"88\">\n<p>order_id<\/p>\n<\/th>\n<th data-colwidth=\"123\" width=\"123\">\n<p>customer_id<\/p>\n<\/th>\n<th data-colwidth=\"84\" width=\"84\">\n<p>amount<\/p>\n<\/th>\n<th data-colwidth=\"99\" width=\"99\">\n<p>num_cats<\/p>\n<\/th>\n<th data-colwidth=\"83\" width=\"83\">\n<p>country<\/p>\n<\/th>\n<th>\n<p>payment_method<\/p>\n<\/th>\n<th>\n<p>ip_address<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">123<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">900<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">RU<\/p>\n<\/td>\n<td>\n<p align=\"left\">Credit Card<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.1.2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">2<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">456<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">5000<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">US<\/p>\n<\/td>\n<td>\n<p align=\"left\">Bitcoin<\/p>\n<\/td>\n<td>\n<p align=\"left\">172.34.56.78<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">3<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">789<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">10\u00a0000<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">15<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">ID<\/p>\n<\/td>\n<td>\n<p align=\"left\">PayPal<\/p>\n<\/td>\n<td>\n<p align=\"left\">36.72.11.55<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">4<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">234<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">300<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">RU<\/p>\n<\/td>\n<td>\n<p align=\"left\">Credit Card<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.1.5<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>\u0427\u0442\u043e\u00a0\u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e:<\/strong><\/p>\n<ul>\n<li>\n<p><code>num_cats &gt; 10<\/code> (\u043d\u0443 \u043a\u0442\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 10\u00a0\u043a\u043e\u0442\u0438\u043a\u043e\u0432?)<\/p>\n<\/li>\n<li>\n<p><code>amount &gt; 5000<\/code> (\u0440\u0435\u0434\u043a\u0438\u0435 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u043d\u0430\u00a0\u0442\u0430\u043a\u0438\u0435 \u0441\u0443\u043c\u043c\u044b)<\/p>\n<\/li>\n<li>\n<p><code>country = ID<\/code> (\u0443 \u043d\u0430\u0441 \u0440\u0435\u0434\u043a\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u044e\u0442 \u0438\u0437\u00a0\u0418\u043d\u0434\u043e\u043d\u0435\u0437\u0438\u0438)<\/p>\n<\/li>\n<li>\n<p><code>payment_method = Bitcoin<\/code> (\u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e\u0441\u0442\u044c \u2260 \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u043d\u043e\u00a0\u043f\u043e\u0432\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c)<\/p>\n<\/li>\n<li>\n<p><code>ip_address<\/code> \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0443\u00a0\u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np from sklearn.ensemble import IsolationForest from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.pipeline import Pipeline from joblib import dump  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 df = pd.read_csv(\"cat_orders.csv\")  # \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 num_features = ['amount', 'num_cats'] cat_features = ['country', 'payment_method']  # \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 (One-Hot Encoding) df = pd.get_dummies(df, columns=cat_features, drop_first=True)  # \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 scaler = StandardScaler() df[num_features] = scaler.fit_transform(df[num_features])<\/code><\/pre>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=200, contamination=0.02, random_state=42) model.fit(df[num_features])  df['anomaly_score'] = model.decision_function(df[num_features]) df['is_anomaly'] = model.predict(df[num_features]) df['is_anomaly'] = df['is_anomaly'].map({1: 0, -1: 1})<\/code><\/pre>\n<h4>\u041a\u0430\u043a\u0438\u0435 \u0437\u0430\u043a\u0430\u0437\u044b \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438?<\/h4>\n<pre><code class=\"python\">suspicious_orders = df[df['is_anomaly'] == 1] print(suspicious_orders)<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434\u0438\u0442 \u0447\u0442\u043e\u2011\u0442\u043e \u0442\u0438\u043f\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>order_id<\/p>\n<\/th>\n<th>\n<p>amount<\/p>\n<\/th>\n<th>\n<p>num_cats<\/p>\n<\/th>\n<th>\n<p>is_anomaly<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">10\u00a0000<\/p>\n<\/td>\n<td>\n<p align=\"left\">15<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">8<\/p>\n<\/td>\n<td>\n<p align=\"left\">7500<\/p>\n<\/td>\n<td>\n<p align=\"left\">12<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0418 \u0442\u0443\u0442 \u0443\u0436\u0435 \u0440\u0435\u0448\u0430\u0435\u043c: \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043a\u043b\u043e\u043d\u044f\u0442\u044c \u0438\u043b\u0438\u00a0\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430\u00a0\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0443.<\/p>\n<h4>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>Isolation Forest \u0445\u043e\u0440\u043e\u0448, \u043d\u043e\u00a0\u0443\u00a0\u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0442\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u00a0\u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\u00a0\u2014 \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u043e\u0432\u0438\u0442\u044c \u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 <code>amount<\/code> \u0438 <code>num_cats<\/code>\u00a0\u2014 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u043a \u043f\u043e\u043a\u0443\u043f\u0430\u0435\u0442 \u043f\u043e 1\u00a0\u043a\u043e\u0442\u0438\u043a\u0443, \u043d\u043e\u00a0\u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e \u0441 50\u00a0\u0430\u043a\u043a\u0430\u0443\u043d\u0442\u043e\u0432?<\/p>\n<p><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong> \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>customer_id<\/code> \u0432\u00a0\u043c\u043e\u0434\u0435\u043b\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0434\u0438\u0440\u0443\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u043e\u043a\u0443\u043f\u043e\u043a).<\/p>\n<pre><code class=\"python\">df['customer_freq'] = df.groupby('customer_id')['order_id'].transform('count')<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a\u00a0\u0447\u0430\u0441\u0442\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043a\u0430\u0437\u044b.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0434\u043e\u0440\u043e\u0433\u0438\u0435, \u043d\u043e\u00a0\u043b\u0435\u0433\u0438\u0442\u0438\u043c\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b \u0442\u043e\u0436\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432\u00a0\u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043a\u0443\u043f\u0438\u043b \u0434\u0432\u0443\u0445 \u0441\u0443\u043f\u0435\u0440\u0434\u043e\u0440\u043e\u0433\u0438\u0445 \u043a\u043e\u0442\u043e\u0432, \u043d\u043e\u00a0\u044d\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u043a\u0443\u043f\u043a\u0430.<\/p>\n<p><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong> \u0432\u0432\u0435\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u00a0\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443\u00a0\u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 chargeback&#8217;\u0438, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"python\"># \u041e\u0431\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043a\u0430\u0437\u0430\u0445 normal_orders = df[df['chargeback'] == 0] model.fit(normal_orders[num_features])  # \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 df['is_anomaly'] = model.predict(df[num_features])<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0430\u00a0\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f\u0445, \u0430\u00a0\u043d\u0435\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u00a0\u0432\u0441\u0435\u0445 \u0437\u0430\u043a\u0430\u0437\u0430\u0445 \u043f\u043e\u0434\u0440\u044f\u0434.<\/p>\n<h4>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d?<\/h4>\n<p>\u041e\u043a\u0435\u0439, \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0447\u0442\u043e? \u041d\u0430\u0434\u043e <strong>\u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u0442\u043e \u0432\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433 \u0437\u0430\u043a\u0430\u0437\u043e\u0432<\/strong>:<\/p>\n<ol>\n<li>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u043e\u0444\u043e\u0440\u043c\u043b\u044f\u0435\u0442 \u0437\u0430\u043a\u0430\u0437.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0447\u0435\u0440\u0435\u0437 Isolation Forest.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 <code>is_anomaly == 1<\/code>, \u0437\u0430\u043a\u0430\u0437 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u00a0\u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u0434\u043c\u0438\u043d\u0430\u043c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 API \u043d\u0430\u00a0Flask:<\/p>\n<pre><code class=\"python\">from flask import Flask, request, jsonify from joblib import load  app = Flask(__name__)  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c model = load(\"isolation_forest_model.joblib\")  @app.route(\"\/predict\", methods=[\"POST\"]) def predict():     data = request.json     df = pd.DataFrame([data])  # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c JSON \u0432 DataFrame     df = scaler.transform(df)  # \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435          prediction = model.predict(df)     is_anomaly = 1 if prediction[0] == -1 else 0          return jsonify({\"is_anomaly\": is_anomaly})  if __name__ == \"__main__\":     app.run(port=5000, debug=True)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u0430\u0433\u0430\u0437\u0438\u043d \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 \u0437\u0430\u00a0\u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043e\u0442\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b.<\/p>\n<p>\u0410\u00a0\u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043b\u043e\u0432\u043e \u0432\u0430\u043c! \u041a\u0430\u043a\u00a0\u0432\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0435 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 \u0432\u00a0\u0441\u0432\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445? \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Isolation Forest \u0438\u043b\u0438\u00a0\u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0447\u0442\u043e\u2011\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c!<\/p>\n<hr\/>\n<p>\u0412\u0441\u0435\u043c, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u0435\u043c\u0430 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u044c \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u0443\u044e \u043e\u043d\u043b\u0430\u0439\u043d-\u043b\u0435\u043a\u0446\u0438\u044e \u0432 Otus \u043d\u0430 \u0442\u0435\u043c\u0443 \u00ab\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0Docker\u00a0\u2014 \u0432\u044b\u0432\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d\u00bb.<\/p>\n<p>\u041d\u0430 \u0432\u0435\u0431\u0438\u043d\u0430\u0440\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 Docker: \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b, \u043e\u0441\u0432\u043e\u0438\u043c Dockerfile \u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 ML-\u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u0440\u0430\u0437 \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0451\u043c \u0441\u0435\u0440\u0432\u0438\u0441. \u0422\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0441 docker-compose. \u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/otus.pw\/RD2X\/\">\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u0443\u0440\u0441\u0430 &#171;Machine Learning. Advanced&#187;.<\/a><\/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\/881086\/\"> https:\/\/habr.com\/ru\/articles\/881086\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437\u00a0\u0441\u0430\u043c\u044b\u0445 \u043c\u043e\u0449\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>Isolation Forest<\/strong>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0443\u0442\u044c, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043b\u0435\u0441. \u0412\u044b \u0438\u0434\u0451\u0442\u0435 \u043f\u043e\u00a0\u043d\u0435\u043c\u0443, \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0427\u0435\u043c\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u044b \u043d\u0430\u0442\u044b\u043a\u0430\u0435\u0442\u0435\u0441\u044c \u043d\u0430\u00a0\u0440\u0435\u0434\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f. Isolation Forest \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u0443\u00a0\u0436\u0435 \u0438\u0434\u0435\u044e, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0443\u00a0\u043d\u0430\u0441 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430\u00a0\u0432\u043c\u0435\u0441\u0442\u043e \u043b\u0435\u0441\u0430\u00a0\u2014 \u0440\u0435\u0448\u0430\u044e\u0449\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f (\u043c\u0435\u0442\u0430\u0444\u043e\u0440\u0430 \u0432\u0435\u043a\u0430).<\/p>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f<\/h4>\n<p>\u041e\u0431\u044b\u0447\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>SVM \u0438\u043b\u0438\u00a0\u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438<\/strong>, \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f <strong>\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u0432\u044b\u0431\u0440\u043e\u0441\u044b. Isolation Forest \u0438\u0434\u0451\u0442 \u0441\u00a0\u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043d\u0446\u0430: \u043e\u043d <strong>\u043d\u0435\u00a0\u0441\u0442\u0440\u043e\u0438\u0442 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c<\/strong>, \u0430\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0431\u0440\u043e\u0441\u044b.<\/p>\n<p>\u041a\u0430\u043a\u00a0\u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0442\u0440\u043e\u0438\u043c \u0434\u0435\u0440\u0435\u0432\u043e<\/strong>, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0434\u0435\u043b\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435<\/strong>, \u043f\u043e\u043a\u0430 \u043a\u0430\u0436\u0434\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043d\u0435\u00a0\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432\u00a0\u0441\u0432\u043e\u0451\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u00a0\u043b\u0438\u0441\u0442\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/strong> \u0442\u043e\u0447\u043a\u0438 \u043f\u043e\u00a0\u0442\u043e\u043c\u0443, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e\u00a0\u0431\u044b\u0441\u0442\u0440\u043e \u043e\u043d\u0430\u00a0\u0431\u044b\u043b\u0430 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 (\u0447\u0435\u043c \u043a\u043e\u0440\u043e\u0447\u0435 \u043f\u0443\u0442\u044c, \u0442\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u0435\u0435).<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u00a0\u043f\u0430\u0440\u0443 \u0448\u0430\u0433\u043e\u0432\u00a0\u2014 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u043e\u043d \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437\u00a0\u043e\u0431\u0449\u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u044b.<\/p>\n<h3>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u2014 \u043a\u043e\u0434<\/h3>\n<p>\u0411\u0435\u0440\u0451\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0438 \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043b\u043e\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.ensemble import IsolationForest  # \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0435\u0439\u043a\u043e\u0432\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 np.random.seed(42) n_samples = 1000  # \"\u041d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435\" \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 amounts = np.random.normal(loc=50, scale=10, size=n_samples) durations = np.random.normal(loc=5, scale=2, size=n_samples) num_items = np.random.normal(loc=3, scale=1, size=n_samples)  # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 (\u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u0443\u043c\u043c\u044b) anomaly_size = 50 amounts[:anomaly_size] = np.random.normal(loc=300, scale=50, size=anomaly_size) durations[:anomaly_size] = np.random.normal(loc=20, scale=5, size=anomaly_size) num_items[:anomaly_size] = np.random.normal(loc=10, scale=3, size=anomaly_size)  df = pd.DataFrame({'amount': amounts, 'duration': durations, 'num_items': num_items})<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0434\u0435 50\u00a0\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u044f\u0432\u043d\u043e \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b (\u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0441\u0443\u043c\u043c\u044b \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c). \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0445.<\/p>\n<pre><code class=\"python\"># \u041e\u0431\u0443\u0447\u0430\u0435\u043c Isolation Forest model = IsolationForest(contamination=0.05, random_state=42)  # 5% \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 df['is_anomaly'] = model.fit_predict(df[['amount', 'duration', 'num_items']])  # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c -1 (\u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f) \u0438 1 (\u043d\u043e\u0440\u043c\u0430) \u0432 0\/1 df['is_anomaly'] = df['is_anomaly'].map({1: 0, -1: 1})  # \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c plt.figure(figsize=(10,6)) plt.scatter(df['amount'], df['duration'], c=df['is_anomaly'], cmap='coolwarm', alpha=0.7) plt.xlabel('Transaction Amount') plt.ylabel('Transaction Duration') plt.title('Isolation Forest Anomaly Detection') plt.colorbar(label=\"Anomaly Score\") plt.show()<\/code><\/pre>\n<figure class=\"full-width\">\n<div><figcaption>\u0413\u0440\u0430\u0444\u0438\u043a<\/figcaption><\/div>\n<\/figure>\n<p>\u0413\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043f\u043e\u00a0\u0434\u0432\u0443\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c: <strong>\u0441\u0443\u043c\u043c\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 <\/strong><code>amount<\/code> \u0438 <strong>\u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c <\/strong><code>duration<\/code>.<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0438\u043d\u0438\u0435 \u0442\u043e\u0447\u043a\u0438<\/strong>\u00a0\u2014 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0443\u043c\u043c\u044b \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c).<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438<\/strong>\u00a0\u2014 \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u0443\u043c\u043c\u044b \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f).<\/p>\n<\/li>\n<li>\n<p><strong>\u0426\u0432\u0435\u0442\u043e\u0432\u0430\u044f \u0448\u043a\u0430\u043b\u0430<\/strong>\u00a0\u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0430 \u043a\u0430\u043a <code>\"Anomaly Classification\"<\/code>, \u043e\u0442\u0440\u0430\u0436\u0430\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u0443\u044e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e: <code>0<\/code> (\u043d\u043e\u0440\u043c\u0430) \u0438 <code>1<\/code> (\u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f).<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c <code>Isolation Forest<\/code> \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0430 50\u00a0\u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439. \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e\u00a0\u043e\u043d\u0438 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u00a0\u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c\u0438 \u0441\u0443\u043c\u043c\u0430\u043c\u0438 (200\u2013400) \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0432\u044b\u0448\u0435 15\u00a0\u0441\u0435\u043a\u0443\u043d\u0434. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0441\u044b.<\/p>\n<h3>\u041a\u0430\u043a \u0432\u044b\u0436\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0438\u0437 Isolation Forest<\/h3>\n<p>\u041a\u0430\u043a\u00a0\u0438 \u043b\u044e\u0431\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, Isolation Forest \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 <strong>\u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/strong>. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"158\" width=\"158\">\n<p>\u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<\/p>\n<\/th>\n<th>\n<p>\u0427\u0442\u043e\u00a0\u0434\u0435\u043b\u0430\u0435\u0442<\/p>\n<\/th>\n<th>\n<p>\u041a\u0430\u043a\u00a0\u0432\u043b\u0438\u044f\u0435\u0442<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>n_estimators<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432\u00a0\u043b\u0435\u0441\u0443<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0411\u043e\u043b\u044c\u0448\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u2192 \u043b\u0443\u0447\u0448\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u043e\u00a0\u0434\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>max_samples<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 256, \u043c\u043e\u0436\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0434\u043b\u044f\u00a0\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>contamination<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u043b\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u043b\u0438\u044f\u0435\u0442 \u043d\u0430\u00a0\u043f\u043e\u0440\u043e\u0433 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>max_features<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0434\u0435\u0440\u0435\u0432\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u043b\u043e, \u043b\u0443\u0447\u0448\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=200, max_samples=500, contamination=0.02, max_features=2, random_state=42) model.fit(df) df['is_anomaly'] = model.predict(df) df['is_anomaly'] = df['is_anomaly'].map({1: 0, -1: 1})<\/code><\/pre>\n<h3>\u041b\u0438\u043c\u0438\u0442\u044b Isolation Forest<\/h3>\n<p>\u041d\u0435\u00a0\u0441\u0442\u043e\u0438\u0442 \u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0\u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u00a0\u2014 \u0441\u0435\u0440\u0435\u0431\u0440\u044f\u043d\u0430\u044f \u043f\u0443\u043b\u044f. \u041e\u043d \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u044b\u0445 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439, \u043d\u043e\u00a0\u0432\u043e\u0442 \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c\u0438 \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u0441\u044f\u0447\u0438\u0442\u044c.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<ol>\n<li>\n<p><strong>\u041f\u043b\u043e\u0445\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u00a0\u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0442\u044b\u0441\u044f\u0447\u0438 \u0444\u0438\u0447\u0435\u0439, \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0431\u0443\u0434\u0443\u0442 \u0440\u0443\u0431\u0438\u0442\u044c \u043d\u0430\u0443\u0433\u0430\u0434.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0435\u00a0\u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b, \u043b\u0443\u0447\u0448\u0435 \u0432\u0437\u044f\u0442\u044c LSTM \u0438\u043b\u0438\u00a0Prophet.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 contamination<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u043e\u043d \u0437\u0430\u0434\u0430\u043d \u043d\u0435\u0432\u0435\u0440\u043d\u043e, \u043c\u043e\u0436\u043d\u043e\u00a0\u043b\u0438\u0431\u043e \u043d\u0435\u00a0\u043d\u0430\u0439\u0442\u0438 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438,\u00a0\u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0438\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 Isolation Forest \u043d\u0435\u00a0\u0437\u0430\u0448\u0451\u043b, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><strong>LOF (Local Outlier Factor)<\/strong>\u00a0\u2014 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0435\u0434\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>Autoencoders<\/strong>\u00a0\u2014 \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0432\u00a0\u043f\u0440\u043e\u0434\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>One\u2011Class SVM<\/strong>\u00a0\u2014 \u0438\u043d\u043e\u0433\u0434\u0430 \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e\u00a0\u0436\u0440\u0451\u0442 \u043c\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u0430\u043a \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e Isolation Forest?<\/h3>\n<p>\u0421\u0443\u043f\u0435\u0440, \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u043d\u043e \u043a\u0430\u043a\u00a0\u043f\u043e\u043d\u044f\u0442\u044c, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u00a0\u043b\u0438 \u043e\u043d\u0430 \u0445\u043e\u0440\u043e\u0448\u043e? \u0412\u00a0\u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442\u00a0\u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0442\u0443\u0442 \u043d\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043a\u0430\u043a\u00a0accuracy \u0438\u043b\u0438\u00a0F1-score, \u043d\u0435\u00a0\u043f\u043e\u043c\u043e\u0433\u0443\u0442.<\/p>\n<p>\u041d\u043e\u00a0\u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438:<\/p>\n<h4>\u0420\u0443\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430<\/h4>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e\u00a0\u043c\u043e\u0449\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043f\u043e\u00a0\u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f\u043c<\/p>\n<\/li>\n<li>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u043f-100\u00a0\u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">df.sort_values(by='is_anomaly', ascending=False).head(100)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u00a0\u0442\u043e\u043f\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u0443\u043c\u043c\u044b, \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u044b)\u00a0\u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h4>\u0410\u043d\u0430\u043b\u0438\u0437 &#171;decision_function()&#187;<\/h4>\n<p>Isolation Forest \u0434\u0430\u0451\u0442 \u043e\u0446\u0435\u043d\u043a\u0443 \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043d\u0435\u00a0\u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 0\/1, \u0430\u00a0\u0447\u0438\u0441\u043b\u043e \u043e\u0442 -0.5\u00a0\u0434\u043e 0.5. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u00ab\u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043e\u043d\u044b\u00bb:<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np from sklearn.ensemble import IsolationForest from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.pipeline import Pipeline from joblib import dump  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0437\u0430\u043a\u0430\u0437\u0430\u0445 df = pd.read_csv(\"orders.csv\")  # \u041e\u0442\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 num_features = ['amount', 'duration', 'num_items'] cat_features = ['payment_method', 'country']  # \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438 df[num_features] = df[num_features].fillna(df[num_features].median()) df[cat_features] = df[cat_features].fillna('Unknown')  # \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 df = pd.get_dummies(df, columns=cat_features, drop_first=True)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435<strong>\u0442,<\/strong> \u0447\u0442\u043e \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438 \u0447\u0451\u0442\u043a\u043e \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u044b\u00a0\u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<h4>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443\u00a0\u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u0442\u0432\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, chargebacks). \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0445 \u043b\u043e\u0432\u0438\u0442:<\/p>\n<pre><code class=\"python\">fraud_orders = df[df['chargeback'] == 1] fraud_detected = df[(df['chargeback'] == 1) &amp; (df['is_anomaly'] == 1)]  print(f\"\u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e {len(fraud_detected)} \u0438\u0437 {len(fraud_orders)} \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432.\") <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 (&gt;70%), \u0437\u043d\u0430\u0447\u0438\u0442, Isolation Forest \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h3>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>Isolation Forest \u0445\u043e\u0440\u043e\u0448, \u043d\u043e\u00a0\u043e\u043d \u043d\u0435\u00a0\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f\u00a0\u043b\u0438\u043d\u0435\u0439\u043d\u043e. \u0415\u0441\u043b\u0438 \u0443\u00a0\u043d\u0430\u0441 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>fit()<\/code> \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 1: max_samples<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0433\u043e, \u043b\u0443\u0447\u0448\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c <code>max_samples<\/code>. \u0412 <code>sklearn<\/code> \u043f\u043e\u00a0\u0434\u0435\u0444\u043e\u043b\u0442\u0443: <code>max_samples = min(256, n_samples)<\/code><\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e:<\/p>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=100, max_samples=5000, contamination=0.01, n_jobs=-1, random_state=42)<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432<strong>\u0430\u0442<\/strong>\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0441\u0442\u0440\u043e\u043a, \u043d\u0435\u00a0\u0442\u0435\u0440\u044f\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 2: n_jobs=-1<\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u044f\u0434\u0440\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430:<\/p>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=200, max_samples=5000, contamination=0.01, n_jobs=-1)<\/code><\/pre>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 3: GPU-\u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435<\/h4>\n<p>Isolation Forest \u043d\u0435\u0442 \u0432 <code>cuML<\/code>, \u043d\u043e\u00a0\u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438. \u041e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0430 <strong>GPU<\/strong> \u0438\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<h4>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/h4>\n<p>Isolation Forest\u00a0\u2014 \u043c\u043e\u0449\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043d\u043e\u00a0\u043e\u0434\u043d\u043e \u0434\u0435\u043b\u043e \u043d\u0430\u0442\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u00a0\u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0435\u00a0\u2014 \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u00a0\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u0438\u0437\u043d\u0435\u0441. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f, \u043a\u0430\u043a\u00a0\u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u0430\u0441\u0442\u0438 \u043c\u0430\u0433\u0430\u0437\u0438\u043d \u044d\u043b\u0438\u0442\u043d\u044b\u0445 \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u043e\u0442\u00a0\u043c\u043e\u0448\u0435\u043d\u043d\u0438\u043a\u043e\u0432.<\/p>\n<h3>\u041a\u0435\u0439\u0441: \u043c\u0430\u0433\u0430\u0437\u0438\u043d \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e\u00a0\u0443\u00a0\u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u043d\u043b\u0430\u0439\u043d\u2011\u043c\u0430\u0433\u0430\u0437\u0438\u043d \u043f\u043e\u0440\u043e\u0434\u0438\u0441\u0442\u044b\u0445 \u043a\u043e\u0442\u0438\u043a\u043e\u0432. \u0426\u0435\u043d\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043e\u0442 500$, \u043d\u043e\u00a0\u0437\u0430\u00a0\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0437\u0430\u00a0\u0431\u0440\u0438\u0442\u0430\u043d\u0446\u0435\u0432 \u0438\u043b\u0438\u00a0\u043c\u0435\u0439\u043d\u2011\u043a\u0443\u043d\u043e\u0432) \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442 \u0438 \u043f\u043e 5000$.<\/p>\n<p>\u0412\u0441\u0451\u00a0\u0431\u044b\u043b\u043e\u00a0\u0431\u044b \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e&#8230;<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b: \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043a\u0443\u043f\u0430\u0435\u0442 15\u00a0\u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0441\u0440\u0430\u0437\u0443, \u043f\u043b\u0430\u0442\u0438\u0442 \u0441\u00a0\u043a\u0440\u0435\u0434\u0438\u0442\u043a\u0438 \u0438\u0437\u00a0\u0418\u043d\u0434\u043e\u043d\u0435\u0437\u0438\u0438, \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430\u00a0\u2014 \u043d\u0430\u00a0\u043f\u043e\u0447\u0442\u0443 \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u00a0\u041d\u043e\u0432\u043e\u0441\u0438\u0431\u0438\u0440\u0441\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u0442\u0451\u0436\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0436\u0430\u043b\u0443\u044e\u0442\u0441\u044f: \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u044b\u0439 \u0440\u0438\u0441\u043a chargeback&#8217;\u043e\u0432\u00a0\u2014 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0437\u0430\u044f\u0432\u043b\u044f\u044e\u0442, \u0447\u0442\u043e\u00a0\u043d\u0435\u00a0\u0434\u0435\u043b\u0430\u043b\u0438 \u0437\u0430\u043a\u0430\u0437\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b: \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435\u00a0\u0436\u0435 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u0438 \u043c\u0435\u043d\u044f\u044e\u0442 \u0438\u043c\u0435\u043d\u0430, \u043d\u043e\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442\u00a0\u0436\u0435 IP.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u0440\u043e\u0447\u0435, \u0437\u0430\u043f\u0430\u0445\u043b\u043e \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u043a\u0430\u043c\u0438, \u0438 \u043d\u0430\u0448\u0435\u043c\u0443 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0443 \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0441\u0440\u043e\u0447\u043d\u043e \u043d\u0443\u0436\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0442\u044c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b, \u0434\u043e\u00a0\u0442\u043e\u0433\u043e \u043a\u0430\u043a\u00a0\u043a\u043e\u0442\u0438\u043a \u0443\u0435\u0445\u0430\u043b \u0432\u00a0\u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u00a0\u0437\u0430\u043a\u0430\u0437\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c Isolation Forest \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u044f\u0432\u043b\u044f\u0435\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0438\u0445.<\/p>\n<\/li>\n<\/ol>\n<h4>\u0414\u0430\u043d\u043d\u044b\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c<\/h4>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"88\" width=\"88\">\n<p>order_id<\/p>\n<\/th>\n<th data-colwidth=\"123\" width=\"123\">\n<p>customer_id<\/p>\n<\/th>\n<th data-colwidth=\"84\" width=\"84\">\n<p>amount<\/p>\n<\/th>\n<th data-colwidth=\"99\" width=\"99\">\n<p>num_cats<\/p>\n<\/th>\n<th data-colwidth=\"83\" width=\"83\">\n<p>country<\/p>\n<\/th>\n<th>\n<p>payment_method<\/p>\n<\/th>\n<th>\n<p>ip_address<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">123<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">900<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">RU<\/p>\n<\/td>\n<td>\n<p align=\"left\">Credit Card<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.1.2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">2<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">456<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">5000<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">US<\/p>\n<\/td>\n<td>\n<p align=\"left\">Bitcoin<\/p>\n<\/td>\n<td>\n<p align=\"left\">172.34.56.78<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">3<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">789<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">10\u00a0000<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">15<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">ID<\/p>\n<\/td>\n<td>\n<p align=\"left\">PayPal<\/p>\n<\/td>\n<td>\n<p align=\"left\">36.72.11.55<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"88\" width=\"88\">\n<p align=\"left\">4<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">234<\/p>\n<\/td>\n<td data-colwidth=\"84\" width=\"84\">\n<p align=\"left\">300<\/p>\n<\/td>\n<td data-colwidth=\"99\" width=\"99\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"83\" width=\"83\">\n<p align=\"left\">RU<\/p>\n<\/td>\n<td>\n<p align=\"left\">Credit Card<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.1.5<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>\u0427\u0442\u043e\u00a0\u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e:<\/strong><\/p>\n<ul>\n<li>\n<p><code>num_cats &gt; 10<\/code> (\u043d\u0443 \u043a\u0442\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 10\u00a0\u043a\u043e\u0442\u0438\u043a\u043e\u0432?)<\/p>\n<\/li>\n<li>\n<p><code>amount &gt; 5000<\/code> (\u0440\u0435\u0434\u043a\u0438\u0435 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u043d\u0430\u00a0\u0442\u0430\u043a\u0438\u0435 \u0441\u0443\u043c\u043c\u044b)<\/p>\n<\/li>\n<li>\n<p><code>country = ID<\/code> (\u0443 \u043d\u0430\u0441 \u0440\u0435\u0434\u043a\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u044e\u0442 \u0438\u0437\u00a0\u0418\u043d\u0434\u043e\u043d\u0435\u0437\u0438\u0438)<\/p>\n<\/li>\n<li>\n<p><code>payment_method = Bitcoin<\/code> (\u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e\u0441\u0442\u044c \u2260 \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u043d\u043e\u00a0\u043f\u043e\u0432\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c)<\/p>\n<\/li>\n<li>\n<p><code>ip_address<\/code> \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0443\u00a0\u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np from sklearn.ensemble import IsolationForest from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.pipeline import Pipeline from joblib import dump  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 df = pd.read_csv(\"cat_orders.csv\")  # \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 num_features = ['amount', 'num_cats'] cat_features = ['country', 'payment_method']  # \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 (One-Hot Encoding) df = pd.get_dummies(df, columns=cat_features, drop_first=True)  # \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 scaler = StandardScaler() df[num_features] = scaler.fit_transform(df[num_features])<\/code><\/pre>\n<pre><code class=\"python\">model = IsolationForest(n_estimators=200, contamination=0.02, random_state=42) model.fit(df[num_features])  df['anomaly_score'] = model.decision_function(df[num_features]) df['is_anomaly'] =<\/code><\/pre>\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-448745","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/448745","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=448745"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/448745\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=448745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=448745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=448745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}