{"id":341653,"date":"2022-11-24T15:00:10","date_gmt":"2022-11-24T15:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341653"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341653","title":{"rendered":"<span>\u041c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0432 Streamlit: \u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441\u0430<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/44f\/8c7\/4e8\/44f8c74e8cdef14f5517600e2c2e663a.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/44f\/8c7\/4e8\/44f8c74e8cdef14f5517600e2c2e663a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u0420\u0443\u0441\u0442\u0435\u043c, IBM Senior DevOps Engineer &amp; Integration Architect.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432 Streamlit \u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Data Science. \u0412 \u044d\u0442\u043e\u0439 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u044b\u0445 \u0438\u0441\u043a\u0430\u0445. \u041c\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043c\u043e\u0449\u044c Streamlit \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u043c \u0438\u0437 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u042f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 Data Science \u043f\u0443\u0431\u043b\u0438\u043a\u0435 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0427\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u044b Streamlit<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 DS \u0432 Streamlit<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0432\u044b\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b:<\/p>\n<ul>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 Python<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Pandas\/Numpy\/Seaborn<\/p>\n<\/li>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<h4>\u041d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e Streamlit<\/h4>\n<p>Streamlit \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0430\u043d\u0435\u043b\u0438 \u043d\u0430 Python. \u0412\u0441\u0435\u0433\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0434\u044d\u0448\u0431\u043e\u0440\u0434. \u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0432\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c, Streamlit \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0430\u043d\u0435\u043b\u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430.<\/p>\n<h3>\u0428\u0430\u0433 1<\/h3>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u043f\u0430\u043d\u0435\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043b\u044e\u0431\u044b\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c Python, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF > \/tmp\/test.py import numpy as np import pandas as pd import matplotlib.pyplot as plt import timeit import warnings warnings.filterwarnings(\"ignore\") import streamlit as st import streamlit.components.v1 as components  #Import classification models and metrics from sklearn.linear_model import LogisticRegression from sklearn.neighbors import KNeighborsClassifier from sklearn.svm import SVC from sklearn.ensemble import RandomForestClassifier,ExtraTreesClassifier from sklearn.model_selection import cross_val_score  #Import performance metrics, imbalanced rectifiers from sklearn.metrics import  confusion_matrix,classification_report,matthews_corrcoef from imblearn.over_sampling import SMOTE from imblearn.under_sampling import NearMiss np.random.seed(42) #for reproducibility since SMOTE and Near Miss use randomizations  from pandas_profiling import ProfileReport from streamlit_pandas_profiling import st_profile_report EOF<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u2014 \u044d\u0442\u043e \u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043a\u043e\u0432\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043d\u0435\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c (\u0438\u043b\u0438 \u0432\u044b) \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0430\u043d\u0435\u043b\u044c. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0437\u0434\u0435\u0441\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u00ab\u041e \u043d\u0430\u0441\u00bb, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0430 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u0434\u0435\u043b\u0430\u0435\u043c \u0438 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0430\u043d\u0435\u043b\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u0432 \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0432\u043e\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u043a\u043e\u0432\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u0438 \u043f\u043e\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u0430 st.tabs. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u0430\u043c \u0440\u0435\u0448\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Streamlit (\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u0442\u0432\u0430!)<\/p>\n<pre><code>cat &lt;&lt; EOF >> \/tmp\/test.py st.title('Claims Prediction')  df=pd.read_excel('https:\/\/github.com\/Stijnvhd\/Streamlit_Course\/blob\/main\/3.%20A%20first%20ML%20example\/data.xlsx?raw=true', engine='openpyxl',) #df[\"Exposure\"] = pd.to_numeric(df[\"Exposure\"], errors='coerce')  app_mode = st.sidebar.selectbox('Mode', ['About', 'EDA', 'Analysis']) EOF<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 (\u0445\u043e\u0442\u044f \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u043d\u043e\u0433\u043e, \u043d\u0435 \u0443\u0434\u0438\u0432\u043b\u044f\u0439\u0442\u0435\u0441\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043c\u043d\u043e\u0433\u043e\u0433\u043e!).<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432:<\/p>\n<pre><code>streamlit run \/tmp\/test.py --server.port 80<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b17\/789\/94f\/b1778994ff8962420126ba818aaccf55.png\" width=\"1186\" height=\"408\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b17\/789\/94f\/b1778994ff8962420126ba818aaccf55.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b3f\/b28\/f11\/b3fb28f11b9a7956d16366ecf0796b62.png\" width=\"1224\" height=\"760\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b3f\/b28\/f11\/b3fb28f11b9a7956d16366ecf0796b62.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 2<\/h2>\n<p><strong>\u041f\u0435\u0440\u0432\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u0414\u0430\u0448\u0431\u043e\u0440\u0434\u0430<\/strong><\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435, \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043d\u0430\u0434 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c. \u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u043d\u043e\u0432\u044b\u0439 \u0430\u0441\u043f\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044c, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u0442\u0438\u043b\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0431\u043e\u043a\u043e\u0432\u0430\u044f \u043f\u0430\u043d\u0435\u043b\u044c, \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u0448 \u0414\u044d\u0448\u0431\u043e\u0440\u0434.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0434\u044d\u0448\u0431\u043e\u0440\u0434 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Ctrl + C \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py if app_mode == \"About\":     st.markdown('Claims Prediction Example')      st.markdown(         \"\"\"         &lt;style>         [data-testid=\"stSidebar\"][aria-expanded=\"true\"] > div:first-child{             width: 350px         }         [data-testid=\"stSidebar\"][aria-expanded=\"false\"] > div:first-child{             width: 350px             margin-left: -350px         }         &lt;\/style>         \"\"\",          unsafe_allow_html=True,     )      st.markdown('')      st.markdown('This dashboard allows you to follow the claims prediction example. It can help you to understand how we can focus on claims and in this way develop proper pricing for insurance products.') EOF<\/code><\/pre>\n<p>\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 About, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/efd\/228\/3cc\/efd2283cc3d2474e690ad17e349a605d.png\" width=\"1174\" height=\"721\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/efd\/228\/3cc\/efd2283cc3d2474e690ad17e349a605d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u0434\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u044b\u0431\u043e\u0440\u0430, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <code>if<\/code> \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py elif app_mode == 'EDA':      st.sidebar.subheader(' Quick  Explore')     st.markdown(\"Tick the box on the side panel to explore the dataset.\")     if st.sidebar.checkbox('Basic Info'):          if st.sidebar.checkbox(\"Show Columns\"):             st.subheader('Show Columns List')             all_columns = df.columns.to_list()             st.write(all_columns)          if st.sidebar.checkbox('Statistical Description'):             st.subheader('Statistical Data Description')             st.write(df.describe())         if st.sidebar.checkbox('Missing Values?'):             st.subheader('Missing values')             st.write(df.isnull().sum()) EOF<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434, \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Ctrl + C, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u044d\u0448\u0431\u043e\u0440\u0434 \u0432 \u0432\u0430\u0448\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435.<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432<\/p>\n<pre><code>streamlit run \/tmp\/test.py --server.port 80<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/039\/665\/6e4\/0396656e400a6bbfe829e5d2b3e32538.png\" width=\"1189\" height=\"758\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/039\/665\/6e4\/0396656e400a6bbfe829e5d2b3e32538.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/07f\/bdc\/a25\/07fbdca25f5ec941cf6f77b5c8a76888.png\" width=\"1220\" height=\"745\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/07f\/bdc\/a25\/07fbdca25f5ec941cf6f77b5c8a76888.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 3. \u0412\u0440\u0435\u043c\u044f \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0438\u0436\u0435 \u043a\u043e\u0434\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py elif app_mode == \"Analysis\":      # Print shape and description of the data     st.set_option('deprecation.showPyplotGlobalUse', False)     if st.sidebar.checkbox('Show DataFrame'):         st.write(df.head(100))         st.write('Shape of the dataframe: ',df.shape)         st.write('Data description: \\n',df.describe())     # Print valid and fraud transactions     fraud=df[df.ClaimNb==1]     valid=df[df.ClaimNb==0]     outlier_percentage=(df.ClaimNb.value_counts()[1]\/df.ClaimNb.value_counts()[0])*100     if st.sidebar.checkbox('Show claim and valid transaction details'):         st.write('Claim cases are: %.3f%%'%outlier_percentage)         st.write('Claim Cases: ',len(fraud))         st.write('Valid Cases: ',len(valid)) EOF<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430\u0431\u043e\u0440\u0430 \u0442\u0435\u0441\u0442\u043e\u0432! \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043c\u0435\u0442\u043a\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u043e\u0432.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py     #Obtaining X (features) and y (labels)     df=df.drop(['PolicyID'], axis=1)     df=df.drop(['Power'], axis=1)     df=df.drop(['Brand'], axis=1)     df=df.drop(['Gas'], axis=1)     df=df.drop(['Region'], axis=1)     df=df.dropna()     X=df.drop(['ClaimNb'], axis=1)     y=df.ClaimNb      # Split the data into training and testing sets     from sklearn.model_selection import train_test_split     size = st.sidebar.slider('Test Set Size', min_value=0.2, max_value=0.4)      X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = size, random_state = 42)      #Print shape of train and test sets     if st.sidebar.checkbox('Show the shape of training and test set features and labels'):         st.write('X_train: ',X_train.shape)         st.write('y_train: ',y_train.shape)         st.write('X_test: ',X_test.shape)         st.write('y_test: ',y_test.shape) EOF<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043d\u0430\u0448\u0435\u0439 \u043f\u0430\u043d\u0435\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (\u0434\u044d\u0448\u0431\u043e\u0440\u0434\u0435).<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py #Feature selection through feature importance     @st.cache     def feature_sort(model,X_train,y_train):         #feature selection         mod=model         # fit the model         mod.fit(X_train, y_train)         # get importance         imp = mod.feature_importances_         return imp      #Classifiers for feature importance     clf=['Extra Trees','Random Forest']     mod_feature = st.sidebar.selectbox('Which model for feature importance?', clf)      start_time = timeit.default_timer()     if mod_feature=='Extra Trees':         model=etree         importance=feature_sort(model,X_train,y_train)     elif mod_feature=='Random Forest':         model=rforest         importance=feature_sort(model,X_train,y_train)     elapsed = timeit.default_timer() - start_time     st.write('Execution Time for feature selection: %.2f minutes'%(elapsed\/60)) EOF<\/code><\/pre>\n<p>\u041e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0431\u0448\u0438\u0440\u043d\u044b\u043c \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0443\u0433\u0430\u044e\u0449\u0438\u043c, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u0435, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0438 \u043d\u0430 \u0442\u043e\u043c, \u043a\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u043d \u0445\u043e\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u044b\u0431\u043e\u0440\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py  #Plot of feature importance     if st.sidebar.checkbox('Show plot of feature importance'):         plt.bar([x for x in range(len(importance))], importance)         plt.title('Feature Importance')         plt.xlabel('Feature (Variable Number)')         plt.ylabel('Importance')         st.pyplot()      feature_imp=list(zip(features,importance))     feature_sort=sorted(feature_imp, key = lambda x: x[1])      n_top_features = st.sidebar.slider('Number of top features', min_value=5, max_value=20)      top_features=list(list(zip(*feature_sort[-n_top_features:]))[0])      if st.sidebar.checkbox('Show selected top features'):         st.write('Top %d features in order of importance are: %s'%(n_top_features,top_features[::-1]))      X_train_sfs=X_train[top_features]     X_test_sfs=X_test[top_features]      X_train_sfs_scaled=X_train_sfs     X_test_sfs_scaled=X_test_sfs     smt = SMOTE()     nr = NearMiss()     def compute_performance(model, X_train, y_train,X_test,y_test):         start_time = timeit.default_timer()         scores = cross_val_score(model, X_train, y_train, cv=3, scoring='accuracy').mean()         'Accuracy: ',scores         model.fit(X_train,y_train)         y_pred = model.predict(X_test)         cm=confusion_matrix(y_test,y_pred)         'Confusion Matrix: ',cm         cr=classification_report(y_test, y_pred)         'Classification Report: ',cr         mcc= matthews_corrcoef(y_test, y_pred)         'Matthews Correlation Coefficient: ',mcc         elapsed = timeit.default_timer() - start_time         'Execution Time for performance computation: %.2f minutes'%(elapsed\/60)     #Run different classification models with rectifiers     if st.sidebar.checkbox('Run a claims prediction model'):          alg=['Extra Trees','Random Forest','k Nearest Neighbor','Support Vector Machine','Logistic Regression']         classifier = st.sidebar.selectbox('Which algorithm?', alg)         rectifier=['SMOTE','Near Miss','No Rectifier']         imb_rect = st.sidebar.selectbox('Which imbalanced class rectifier?', rectifier)          if classifier=='Logistic Regression':             model=logreg             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)           elif classifier == 'k Nearest Neighbor':             model=knn             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)          elif classifier == 'Support Vector Machine':             model=svm             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)          elif classifier == 'Random Forest':             model=rforest             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)          elif classifier == 'Extra Trees':             model=etree             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test) EOF<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448 \u0434\u0430\u0448\u0431\u043e\u0440\u0434<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/41f\/cc4\/fe8\/41fcc4fe83667cf2ef50ed3d4cde2c61.png\" width=\"1195\" height=\"463\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/41f\/cc4\/fe8\/41fcc4fe83667cf2ef50ed3d4cde2c61.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/81a\/d2b\/515\/81ad2b5159be76f97b34bb674dffdaee.png\" width=\"1222\" height=\"747\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/81a\/d2b\/515\/81ad2b5159be76f97b34bb674dffdaee.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 4. \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0435\u0441\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0435\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0432\u044c\u044e \u043d\u0430 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0435.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF > \/tmp\/test3.py import numpy as np import pandas as pd import matplotlib.pyplot as plt import timeit import warnings warnings.filterwarnings(\"ignore\") import streamlit as st import streamlit.components.v1 as components  #Import classification models and metrics from sklearn.linear_model import LogisticRegression from sklearn.neighbors import KNeighborsClassifier from sklearn.svm import SVC from sklearn.ensemble import RandomForestClassifier,ExtraTreesClassifier from sklearn.model_selection import cross_val_score  #Import performance metrics, imbalanced rectifiers from sklearn.metrics import  confusion_matrix,classification_report,matthews_corrcoef from imblearn.over_sampling import SMOTE from imblearn.under_sampling import NearMiss np.random.seed(42) #for reproducibility since SMOTE and Near Miss use randomizations  from pandas_profiling import ProfileReport from streamlit_pandas_profiling import st_profile_report  st.title('Claims Prediction')  df=pd.read_excel('https:\/\/github.com\/Stijnvhd\/Streamlit_Course\/blob\/main\/3.%20A%20first%20ML%20example\/data.xlsx?raw=true', engine='openpyxl',)  app_mode = st.sidebar.selectbox('Mode', ['About', 'EDA', 'Analysis'])  if app_mode == \"About\":     st.markdown('Claims Prediction Example')      st.markdown(         \"\"\"         &lt;style>         [data-testid=\"stSidebar\"][aria-expanded=\"true\"] > div:first-child{             width: 350px         }         [data-testid=\"stSidebar\"][aria-expanded=\"false\"] > div:first-child{             width: 350px             margin-left: -350px         }         &lt;\/style>         \"\"\",          unsafe_allow_html=True,     )      st.markdown('')      st.markdown('This dashboard allows you to follow the Claims Prediction Example. It can help you to understand how we can focus on claims and this way develop proper pricing for our products.')  elif app_mode == 'EDA':      st.sidebar.subheader(' Quick  Explore')     st.markdown(\"Tick the box on the side panel to explore the dataset.\")     if st.sidebar.checkbox('Basic Info'):          if st.sidebar.checkbox(\"Show Columns\"):             st.subheader('Show Columns List')             all_columns = df.columns.to_list()             st.write(all_columns)          if st.sidebar.checkbox('Statistical Description'):             st.subheader('Statistical Data Description')             st.write(df.describe())         if st.sidebar.checkbox('Missing Values?'):             st.subheader('Missing values')             st.write(df.isnull().sum())  elif app_mode == \"Analysis\":      # Print shape and description of the data     st.set_option('deprecation.showPyplotGlobalUse', False)     if st.sidebar.checkbox('Show DataFrame'):         st.write(df.head(100))         st.write('Shape of the dataframe: ',df.shape)         st.write('Data decription: \\n',df.describe())     # Print valid and fraud transactions     fraud=df[df.ClaimNb==1]     valid=df[df.ClaimNb==0]     outlier_percentage=(df.ClaimNb.value_counts()[1]\/df.ClaimNb.value_counts()[0])*100     if st.sidebar.checkbox('Show claim and valid transaction details'):         st.write('Claim cases are: %.3f%%'%outlier_percentage)         st.write('Claim Cases: ',len(fraud))         st.write('Valid Cases: ',len(valid))           #Obtaining X (features) and y (labels)     df=df.drop(['PolicyID'], axis=1)     df=df.drop(['Power'], axis=1)     df=df.drop(['Brand'], axis=1)     df=df.drop(['Gas'], axis=1)     df=df.drop(['Region'], axis=1)     df=df.dropna()     X=df.drop(['ClaimNb'], axis=1)     y=df.ClaimNb      # Split the data into training and testing sets     from sklearn.model_selection import train_test_split     size = st.sidebar.slider('Test Set Size', min_value=0.2, max_value=0.4)      X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = size, random_state = 42)      #Print shape of train and test sets     if st.sidebar.checkbox('Show the shape of training and test set features and labels'):         st.write('X_train: ',X_train.shape)         st.write('y_train: ',y_train.shape)         st.write('X_test: ',X_test.shape)         st.write('y_test: ',y_test.shape)       #Import classification models and metrics     from sklearn.linear_model import LogisticRegression     from sklearn.neighbors import KNeighborsClassifier     from sklearn.svm import SVC     from sklearn.ensemble import RandomForestClassifier,ExtraTreesClassifier     from sklearn.model_selection import cross_val_score       logreg=LogisticRegression()     svm=SVC()     knn=KNeighborsClassifier()     etree=ExtraTreesClassifier(random_state=42)     rforest=RandomForestClassifier(random_state=42)       features=X_train.columns.tolist()       #Feature selection through feature importance     @st.cache     def feature_sort(model,X_train,y_train):         #feature selection         mod=model         # fit the model         mod.fit(X_train, y_train)         # get importance         imp = mod.feature_importances_         return imp      #Classifiers for feature importance     clf=['Extra Trees','Random Forest']     mod_feature = st.sidebar.selectbox('Which model for feature importance?', clf)      start_time = timeit.default_timer()     if mod_feature=='Extra Trees':         model=etree         importance=feature_sort(model,X_train,y_train)     elif mod_feature=='Random Forest':         model=rforest         importance=feature_sort(model,X_train,y_train)     elapsed = timeit.default_timer() - start_time     st.write('Execution Time for feature selection: %.2f minutes'%(elapsed\/60))      #Plot of feature importance     if st.sidebar.checkbox('Show plot of feature importance'):         plt.bar([x for x in range(len(importance))], importance)         plt.title('Feature Importance')         plt.xlabel('Feature (Variable Number)')         plt.ylabel('Importance')         st.pyplot()      feature_imp=list(zip(features,importance))     feature_sort=sorted(feature_imp, key = lambda x: x[1])      n_top_features = st.sidebar.slider('Number of top features', min_value=5, max_value=20)      top_features=list(list(zip(*feature_sort[-n_top_features:]))[0])      if st.sidebar.checkbox('Show selected top features'):         st.write('Top %d features in order of importance are: %s'%(n_top_features,top_features[::-1]))      X_train_sfs=X_train[top_features]     X_test_sfs=X_test[top_features]      X_train_sfs_scaled=X_train_sfs     X_test_sfs_scaled=X_test_sfs     smt = SMOTE()     nr = NearMiss()     def compute_performance(model, X_train, y_train,X_test,y_test):         start_time = timeit.default_timer()         scores = cross_val_score(model, X_train, y_train, cv=3, scoring='accuracy').mean()         'Accuracy: ',scores         model.fit(X_train,y_train)         y_pred = model.predict(X_test)         cm=confusion_matrix(y_test,y_pred)         'Confusion Matrix: ',cm         cr=classification_report(y_test, y_pred)         'Classification Report: ',cr         mcc= matthews_corrcoef(y_test, y_pred)         'Matthews Correlation Coefficient: ',mcc         elapsed = timeit.default_timer() - start_time         'Execution Time for performance computation: %.2f minutes'%(elapsed\/60)     #Run different classification models with rectifiers     if st.sidebar.checkbox('Run a claims prediction model'):          alg=['Extra Trees','Random Forest','k Nearest Neighbor','Support Vector Machine','Logistic Regression']         classifier = st.sidebar.selectbox('Which algorithm?', alg)         rectifier=['SMOTE','Near Miss','No Rectifier']         imb_rect = st.sidebar.selectbox('Which imbalanced class rectifier?', rectifier)          if classifier=='Logistic Regression':             model=logreg             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)           elif classifier == 'k Nearest Neighbor':             model=knn             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)          elif classifier == 'Support Vector Machine':             model=svm             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)          elif classifier == 'Random Forest':             model=rforest             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)          elif classifier == 'Extra Trees':             model=etree             if imb_rect=='No Rectifier':                 compute_performance(model, X_train_sfs_scaled, y_train,X_test_sfs_scaled,y_test)             elif imb_rect=='SMOTE':                     rect=smt                     st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                     X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                     st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                     compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test)             elif imb_rect=='Near Miss':                 rect=nr                 st.write('Shape of imbalanced y_train: ',np.bincount(y_train))                 X_train_bal, y_train_bal = rect.fit_resample(X_train_sfs_scaled, y_train)                 st.write('Shape of balanced y_train: ',np.bincount(y_train_bal))                 compute_performance(model, X_train_bal, y_train_bal,X_test_sfs_scaled,y_test) EOF  <\/code><\/pre>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434, \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Ctrl + C, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0430\u043d\u0435\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0432\u0430\u0448\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435. \u0417\u0430\u0442\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435 \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f!<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>streamlit run \/tmp\/test3.py<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ea4\/ad0\/eda\/ea4ad0eda19040db9e7dbdb67d5e66b9.png\" width=\"1190\" height=\"377\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ea4\/ad0\/eda\/ea4ad0eda19040db9e7dbdb67d5e66b9.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/17c\/015\/f9d\/17c015f9dd3b704d8fa0516134d555fa.png\" width=\"1227\" height=\"740\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/17c\/015\/f9d\/17c015f9dd3b704d8fa0516134d555fa.png\"\/><figcaption><\/figcaption><\/figure>\n<hr\/>\n<p>\u041f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c \u0441\u043b\u0443\u0447\u0430\u0435\u043c, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u043e\u043d\u043b\u0430\u0439\u043d-\u0443\u0440\u043e\u043a \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438. \u041d\u0430 \u0437\u0430\u043d\u044f\u0442\u0438\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0432 ML, \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (Bagging, Random Forest, Boosting) \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0445 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u043d\u0438\u0436\u0435.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/y4Gc\/\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/company\/otus\/blog\/701412\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/701412\/<\/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<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u0420\u0443\u0441\u0442\u0435\u043c, IBM Senior DevOps Engineer &amp; Integration Architect.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432 Streamlit \u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Data Science. \u0412 \u044d\u0442\u043e\u0439 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u044b\u0445 \u0438\u0441\u043a\u0430\u0445. \u041c\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043c\u043e\u0449\u044c Streamlit \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u043c \u0438\u0437 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u042f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 Data Science \u043f\u0443\u0431\u043b\u0438\u043a\u0435 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0427\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u044b Streamlit<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 DS \u0432 Streamlit<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0432\u044b\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b:<\/p>\n<ul>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 Python<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Pandas\/Numpy\/Seaborn<\/p>\n<\/li>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<h4>\u041d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e Streamlit<\/h4>\n<p>Streamlit \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0430\u043d\u0435\u043b\u0438 \u043d\u0430 Python. \u0412\u0441\u0435\u0433\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0434\u044d\u0448\u0431\u043e\u0440\u0434. \u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0432\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c, Streamlit \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0430\u043d\u0435\u043b\u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430.<\/p>\n<h3>\u0428\u0430\u0433 1<\/h3>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u043f\u0430\u043d\u0435\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043b\u044e\u0431\u044b\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c Python, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF > \/tmp\/test.py import numpy as np import pandas as pd import matplotlib.pyplot as plt import timeit import warnings warnings.filterwarnings(\"ignore\") import streamlit as st import streamlit.components.v1 as components  #Import classification models and metrics from sklearn.linear_model import LogisticRegression from sklearn.neighbors import KNeighborsClassifier from sklearn.svm import SVC from sklearn.ensemble import RandomForestClassifier,ExtraTreesClassifier from sklearn.model_selection import cross_val_score  #Import performance metrics, imbalanced rectifiers from sklearn.metrics import  confusion_matrix,classification_report,matthews_corrcoef from imblearn.over_sampling import SMOTE from imblearn.under_sampling import NearMiss np.random.seed(42) #for reproducibility since SMOTE and Near Miss use randomizations  from pandas_profiling import ProfileReport from streamlit_pandas_profiling import st_profile_report EOF<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u2014 \u044d\u0442\u043e \u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043a\u043e\u0432\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043d\u0435\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c (\u0438\u043b\u0438 \u0432\u044b) \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0430\u043d\u0435\u043b\u044c. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0437\u0434\u0435\u0441\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u00ab\u041e \u043d\u0430\u0441\u00bb, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0430 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u0434\u0435\u043b\u0430\u0435\u043c \u0438 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0430\u043d\u0435\u043b\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u0432 \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0432\u043e\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u043a\u043e\u0432\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u0438 \u043f\u043e\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u0430 st.tabs. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u0430\u043c \u0440\u0435\u0448\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Streamlit (\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u0442\u0432\u0430!)<\/p>\n<pre><code>cat &lt;&lt; EOF >> \/tmp\/test.py st.title('Claims Prediction')  df=pd.read_excel('https:\/\/github.com\/Stijnvhd\/Streamlit_Course\/blob\/main\/3.%20A%20first%20ML%20example\/data.xlsx?raw=true', engine='openpyxl',) #df[\"Exposure\"] = pd.to_numeric(df[\"Exposure\"], errors='coerce')  app_mode = st.sidebar.selectbox('Mode', ['About', 'EDA', 'Analysis']) EOF<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 (\u0445\u043e\u0442\u044f \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u043d\u043e\u0433\u043e, \u043d\u0435 \u0443\u0434\u0438\u0432\u043b\u044f\u0439\u0442\u0435\u0441\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043c\u043d\u043e\u0433\u043e\u0433\u043e!).<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432:<\/p>\n<pre><code>streamlit run \/tmp\/test.py --server.port 80<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 2<\/h2>\n<p><strong>\u041f\u0435\u0440\u0432\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u0414\u0430\u0448\u0431\u043e\u0440\u0434\u0430<\/strong><\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435, \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043d\u0430\u0434 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c. \u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u043d\u043e\u0432\u044b\u0439 \u0430\u0441\u043f\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044c, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u0442\u0438\u043b\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0431\u043e\u043a\u043e\u0432\u0430\u044f \u043f\u0430\u043d\u0435\u043b\u044c, \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u0448 \u0414\u044d\u0448\u0431\u043e\u0440\u0434.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0434\u044d\u0448\u0431\u043e\u0440\u0434 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Ctrl + C \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py if app_mode == \"About\":     st.markdown('Claims Prediction Example')      st.markdown(         \"\"\"         &lt;style>         [data-testid=\"stSidebar\"][aria-expanded=\"true\"] > div:first-child{             width: 350px         }         [data-testid=\"stSidebar\"][aria-expanded=\"false\"] > div:first-child{             width: 350px             margin-left: -350px         }         &lt;\/style>         \"\"\",          unsafe_allow_html=True,     )      st.markdown('')      st.markdown('This dashboard allows you to follow the claims prediction example. It can help you to understand how we can focus on claims and in this way develop proper pricing for insurance products.') EOF<\/code><\/pre>\n<p>\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 About, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u0434\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u044b\u0431\u043e\u0440\u0430, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <code>if<\/code> \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py elif app_mode == 'EDA':      st.sidebar.subheader(' Quick  Explore')     st.markdown(\"Tick the box on the side panel to explore the dataset.\")     if st.sidebar.checkbox('Basic Info'):          if st.sidebar.checkbox(\"Show Columns\"):             st.subheader('Show Columns List')             all_columns = df.columns.to_list()             st.write(all_columns)          if st.sidebar.checkbox('Statistical Description'):             st.subheader('Statistical Data Description')             st.write(df.describe())         if st.sidebar.checkbox('Missing Values?'):             st.subheader('Missing values')             st.write(df.isnull().sum()) EOF<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434, \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Ctrl + C, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u044d\u0448\u0431\u043e\u0440\u0434 \u0432 \u0432\u0430\u0448\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435.<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432<\/p>\n<pre><code>streamlit run \/tmp\/test.py --server.port 80<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0428\u0430\u0433 3. \u0412\u0440\u0435\u043c\u044f \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0438\u0436\u0435 \u043a\u043e\u0434\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py elif app_mode == \"Analysis\":      # Print shape and description of the data     st.set_option('deprecation.showPyplotGlobalUse', False)     if st.sidebar.checkbox('Show DataFrame'):         st.write(df.head(100))         st.write('Shape of the dataframe: ',df.shape)         st.write('Data description: \\n',df.describe())     # Print valid and fraud transactions     fraud=df[df.ClaimNb==1]     valid=df[df.ClaimNb==0]     outlier_percentage=(df.ClaimNb.value_counts()[1]\/df.ClaimNb.value_counts()[0])*100     if st.sidebar.checkbox('Show claim and valid transaction details'):         st.write('Claim cases are: %.3f%%'%outlier_percentage)         st.write('Claim Cases: ',len(fraud))         st.write('Valid Cases: ',len(valid)) EOF<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430\u0431\u043e\u0440\u0430 \u0442\u0435\u0441\u0442\u043e\u0432! \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043c\u0435\u0442\u043a\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u043e\u0432.<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py     #Obtaining X (features) and y (labels)     df=df.drop(['PolicyID'], axis=1)     df=df.drop(['Power'], axis=1)     df=df.drop(['Brand'], axis=1)     df=df.drop(['Gas'], axis=1)     df=df.drop(['Region'], axis=1)     df=df.dropna()     X=df.drop(['ClaimNb'], axis=1)     y=df.ClaimNb      # Split the data into training and testing sets     from sklearn.model_selection import train_test_split     size = st.sidebar.slider('Test Set Size', min_value=0.2, max_value=0.4)      X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = size, random_state = 42)      #Print shape of train and test sets     if st.sidebar.checkbox('Show the shape of training and test set features and labels'):         st.write('X_train: ',X_train.shape)         st.write('y_train: ',y_train.shape)         st.write('X_test: ',X_test.shape)         st.write('y_test: ',y_test.shape) EOF<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043d\u0430\u0448\u0435\u0439 \u043f\u0430\u043d\u0435\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (\u0434\u044d\u0448\u0431\u043e\u0440\u0434\u0435).<\/p>\n<pre><code class=\"python\">cat &lt;&lt; EOF >> \/tmp\/test.py #Feature selection through feature importance     @st.cache     def feature_sort(model,X_train,y_train):         #feature selection         mod=model         # fit the model         mod.fit(X_train, y_train)         # get importance         imp = mod.feature_importances_         return imp      #Classifiers for feature importance     clf=['Extra Trees','Random Forest']     mod_feature = st.sidebar.selectbox('Which model for feature importance?', clf)      start_time = timeit.default_timer()     if mod_feature=='Extra Trees':         model=etree         importance=feature_sort(model,X_train,y_train)     elif mod_feature=='Random Forest':         model=rforest         importance=feature_sort(model,X_train,y_train)     elapsed = timeit.default_timer() - start_time     st.write('Execution Time for feature selection: %.2f minutes'%(elapsed\/60)) EOF<\/code><\/pre>\n<p>\u041e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0431\u0448\u0438\u0440\u043d\u044b\u043c \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e,<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-341653","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341653","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=341653"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341653\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}