{"id":2795,"date":"2025-08-22T07:36:37","date_gmt":"2025-08-22T04:36:37","guid":{"rendered":"http:\/\/csnotes.ru\/?p=2795"},"modified":"2025-08-23T17:49:10","modified_gmt":"2025-08-23T14:49:10","slug":"%d0%b4%d0%b8%d1%81%d0%bf%d0%b5%d1%82%d1%87%d0%b5%d1%80%d0%b8%d0%b7%d0%b0%d1%86%d0%b8%d1%8f-%d1%87%d0%b5%d1%80%d0%b5%d0%b7-%d1%81%d0%bb%d0%be%d0%b2%d0%b0%d1%80%d1%8c-%d1%84%d1%83%d0%bd%d0%ba%d1%86","status":"publish","type":"post","link":"https:\/\/csnotes.ru\/?p=2795","title":{"rendered":"\u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0439"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Dictionary dispatch, dispatch table &#8211; \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0422\u0435\u0445\u043d\u0438\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 if-elif-else.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 1<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u0414\u0430\u043d\u044b \u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b\n\ndef process_admin_request(user, request):\n    return f\"Admin {user} processed: {request}\"\n\ndef process_manager_request(user, request):\n    return f\"Manager {user} processed: {request}\"\n\ndef process_client_request(user, request):\n    return f\"Client {user} processed: {request}\"\n\n<strong># \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438: \u0440\u043e\u043b\u0438 \u2192 \u0444\u0443\u043d\u043a\u0446\u0438\u0438\ngroup_to_process_method = {\n    \"admin\": process_admin_request,\n    \"manager\": process_manager_request,\n    \"client\": process_client_request,\n}<\/strong>\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445\nclass User:\n    def __init__(self, name, group):\n        self.name = name\n        self.group = group\n\nuser = User(\"Alice\", \"manager\")\nrequest = \"update database\"\n\n<strong># \u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/strong>\n<strong>result = group_to_process_method&#91;user.group](user.name, request)<\/strong>\nprint(result)\n\n### \u0412\u044b\u0432\u043e\u0434\n# Manager Alice processed: update database<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 2 &#8211; \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 Data Science<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\nfrom sklearn.preprocessing import StandardScaler, MinMaxScaler, RobustScaler\n\n# \"\u0424\u0430\u0431\u0440\u0438\u043a\u0438\" \u0434\u043b\u044f \u0441\u043a\u0435\u0439\u043b\u0435\u0440\u043e\u0432\ndef standard_scaler(data):\n    return StandardScaler().fit_transform(data)\n\ndef minmax_scaler(data):\n    return MinMaxScaler().fit_transform(data)\n\ndef robust_scaler(data):\n    return RobustScaler().fit_transform(data)\n\n<strong># \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438\nscaler_methods = {\n    \"standard\": standard_scaler,\n    \"minmax\": minmax_scaler,\n    \"robust\": robust_scaler,\n}<\/strong>\n\n# \u0414\u0430\u043d\u043d\u044b\u0435\nX = np.array(&#91;&#91;1, 100], &#91;2, 300], &#91;3, 500]], dtype=float)\n\n# \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \"robust\"\nchosen_method = \"standard\"\n\n<strong># \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\nX_scaled = scaler_methods&#91;chosen_method](X)<\/strong>\n\nprint(\"\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:\\n\", X)\nprint(\"\u041f\u043e\u0441\u043b\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:\", chosen_method, \"\\n\", X_scaled)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0418\u043b\u0438 \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.svm import SVC\n\n<strong># \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439\nmodel_dispatch = {\n    \"logreg\": LogisticRegression,\n    \"tree\": DecisionTreeClassifier,\n    \"svm\": SVC,\n}<\/strong>\n\n# \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \"tree\"\nchosen_model = \"tree\"\n\n<strong># \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0447\u0435\u0440\u0435\u0437 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e\nmodel = model_dispatch&#91;chosen_model](max_depth=3)<\/strong>\n\nprint(\"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c:\", model)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dictionary dispatch, dispatch table &#8211; \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0435\u0445\u043d\u0438\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 if-elif-else. \u041f\u0440\u0438\u043c\u0435\u0440 1 \u041f\u0440\u0438\u043c\u0435\u0440 2 &#8211; \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 Data Science \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u043b\u0438 \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57,2,5,24],"tags":[129,128],"class_list":["post-2795","post","type-post","status-publish","format-standard","hentry","category-ds","category-ml","category-python","category-tech","tag-129","tag-128"],"views":85,"_links":{"self":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts\/2795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2795"}],"version-history":[{"count":4,"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts\/2795\/revisions"}],"predecessor-version":[{"id":2803,"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts\/2795\/revisions\/2803"}],"wp:attachment":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}