{"id":257819,"date":"2015-05-24T12:45:02","date_gmt":"2015-05-24T08:45:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=257819"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=257819","title":{"rendered":"\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0432 Python"},"content":{"rendered":"<p>     \t\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 (\u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439) \u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043d\u0430 Python. \u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0430 \u043a \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u043c \u043a\u0443\u0440\u0441\u0430 Machine learning by Andrew Ng \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043a\u0443\u0440\u0441 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e, \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0438\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0442\u0435\u043b\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0441 <s>\u043f\u0440\u0435\u0444\u0435\u0440\u0430\u043d\u0441\u043e\u043c \u0438 \u0431\u0430\u0440\u044b\u0448\u043d\u044f\u043c<\/s> \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043d\u043e \u0447\u0442\u043e \u0442\u043e \u0432\u0430\u0441 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b\u043e, \u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u0446\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u0442\u0435\u043e\u0440\u0438\u0435\u0439 (\u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0443\u0449\u0435\u043d\u0430). <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041a\u043e\u0434 \u043e\u0442\u043a\u043e\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u043d\u043e \u0432\u0440\u044f\u0434 \u043b\u0438 \u0443 \u043a\u043e\u0433\u043e \u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0434\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c.<\/p>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0435\u0441\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e scipy.optimize.fmin_cg, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e \u043a\u0430\u043a\u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u0445 \u0440\u0435\u0447\u044c \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b?<\/b><\/p>\n<div class=\"spoiler_text\">\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u043f\u043e\u043f\u0430\u0440\u043d\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u0432\u0443\u0445 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0441 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0434\u0432\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.  <\/p>\n<pre><code class=\"python\">import numpy as np import time  A = np.random.rand(1000000, 1) # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 1 \u043c\u043b\u043d. \u0441\u0442\u0440\u043e\u043a \u0438 1 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 float B = np.random.rand(1000000, 1) # ---- C1 = np.empty((1000000, 1)) # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 1 \u043c\u043b\u043d. \u0441\u0442\u0440\u043e\u043a \u0438 1 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 C2 = np.empty((1000000, 1)) # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 1 \u043c\u043b\u043d. \u0441\u0442\u0440\u043e\u043a \u0438 1 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438  start = time.time() for i in range(0, len(A)):     C1[i] = A[i] * B[i] # \u0421\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 A, B \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 C print(time.time() - start)  start = time.time() C2 = A + B #\u0421\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e print(time.time() - start)  if (C1 == C2).all(): # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432     print('Equal!') <\/code><\/pre>\n<p>  \u041d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 \u0446\u0438\u043a\u043b \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430 4 \u0441\u0435\u043a. 40 \u043c\u0438\u043b. \u0441\u0435\u043a. \u0412\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430 0.02 \u0441\u0435\u043a.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445. \u041d\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0443\u0436\u0435 \u043e \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.  <\/div>\n<\/div>\n<p>  \u041c\u044b \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u044f\u0445 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435,   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u0442\u0438<\/b><\/p>\n<div class=\"spoiler_text\"><a href=\"http:\/\/habrahabr.ru\/post\/143129\/\">\u041d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u0447\u0430\u0439\u043d\u0438\u043a\u043e\u0432<\/a> <br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/144881\/\">\u041d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u0447\u0430\u0439\u043d\u0438\u043a\u043e\u0432 2<\/a>   <\/div>\n<\/div>\n<p>  <u>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/u><br \/>  Python 3.4 (\u043d\u0430 2.7 \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u0432\u043a\u0430\u043c\u0438)<br \/>  Numpy<br \/>  SciPy (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e)<\/p>\n<p>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0441\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b \u043c\u043e\u0434\u0443\u043b\u044c network.py<\/p>\n<h4><b>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0442\u0438<\/b><\/h4>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438. \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0438\u0446\u0438\u043b\u0438\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u0435\u0441\u043e\u0432 Theta \u03b8 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0442 -1 \u0434\u043e 1.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 network, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u043d\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e layers, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0435\u0432 \u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0441\u0435\u0442\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 list. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 [10, 5, 5, 1] \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0441\u0435\u0442\u044c \u0441 \u0434\u0435\u0441\u044f\u0442\u044c\u044e \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u0430\u043c\u0438, \u0434\u0432\u0443\u043c\u044f \u0441\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u044f\u043c\u0438 \u043f\u043e 5 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c \u0441\u043b\u043e\u0435\u043c \u0441 \u043e\u0434\u043d\u0438\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u043c<\/p>\n<pre><code class=\"python\">def create(self, layers):     theta=[0]     for i in range(1, len(layers)): # for each layer from the first (skip zero layer!)         theta.append(np.mat(np.random.uniform(-1, 1, (layers[i], layers[i-1]+1)))) # create nxM+1 matrix (+bias!) with random floats in range [-1; 1]     nn={'theta':theta,'structure':layers}     return nn <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 layers \u0432\u0440\u044f\u0434 \u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0430\u0436\u0435 \u0432 \u0441\u0430\u043c\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0446\u0438\u043a\u043b for.<\/p>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c list theta \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438 \u0441 \u0432\u0435\u0441\u0430\u043c\u0438.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c theta[0] = 0 ?<\/b><\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a77\/0d2\/f7a\/a770d2f7a78c6f7b97a78a32a2ab6a45.png\" alt=\"image\"\/><br \/>  \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0438\u0437 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 Machine Learning, \u0441 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u043c\u0438<\/p>\n<p>  \u0412 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u03b81 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u0441\u043e\u0432 \u043e\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (input) \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f. \u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u043b\u043e\u0435\u0432 \u0434\u043e Input layer, \u0442\u043e \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u0435\u0441\u043e\u0432 \u0442\u043e\u0436\u0435 \u043d\u0435\u0442.  <\/div>\n<\/div>\n<p>   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0427\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f theta[1], theta[2], \u2026, theta[n] ?<\/b><\/p>\n<div class=\"spoiler_text\">\u0412\u0441\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c theta[1] \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430. Theta[1] \u044d\u0442\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0440\u0430\u0432\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043a\u0440\u044b\u0442\u043e\u043c \u0441\u043b\u043e\u0435, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0440\u0430\u0432\u043d\u043e \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0434\u043b\u044f \u0431\u0438\u0430\u0441\u0430 (\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f) + \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043b\u043e\u0435.<\/p>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u043c\u0430\u0442\u0440\u0438\u0446\u044b theta[1] \u0442\u043e \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 (\u0447\u0438\u0442\u0430\u0439 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446) \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u0443 \u0431\u0438\u0430\u0441\u0430, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b (\u0441\u0442\u043e\u043b\u0431\u0446\u044b) \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u0430\u043c \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u044f.  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Bias (\u0431\u0438\u0430\u0441) \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d?<\/b><\/p>\n<div class=\"spoiler_text\">Bias \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u00ab\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u00bb \u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u043e\u043d \u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 (\u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0430\u0448, \u041a\u044d\u043f). \u041b\u0443\u0447\u0448\u0435 \u0447\u0435\u043c <a href=\"http:\/\/stackoverflow.com\/questions\/2480650\/role-of-bias-in-neural-networks\">\u0437\u0434\u0435\u0441\u044c<\/a> \u044f \u0432\u0440\u044f\u0434 \u043b\u0438 \u0441\u043a\u0430\u0436\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434.<\/p>\n<p>  \u0411\u0438\u0430\u0441 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <b>\u0441\u043c\u0435\u0449\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0432\u043b\u0435\u0432\u043e \u0438\u043b\u0438 \u0432\u043f\u0440\u0430\u0432\u043e<\/b>, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<br \/>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0431\u0435\u0437 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0438 1 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043d\u0435\u0439\u0440\u043e\u043d<br \/>   <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/517\/4e8\/ef55174e813e40a3ccc3b2beaf961757.gif\" alt=\"image\"\/><\/p>\n<p>  \u0412\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u0435\u0441\u0430 W0 \u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b X \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0438\u0433\u043c\u043e\u0438\u0434) \u043a \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044e.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0432\u0435\u0441\u0430 W0<br \/>   <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ede\/140\/790\/ede140790c120e5d6f269c2f32dbfe90.png\" alt=\"image\"\/><\/p>\n<p>  \u041c\u0435\u043d\u044f\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0435\u0441\u0430 W0 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430\u043a\u043b\u043e\u043d \u043a\u0440\u0438\u0432\u043e\u0439, \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0435\u0451 \u043a\u0440\u0443\u0442\u0438\u0437\u043d\u044b, \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e, \u043d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0447\u0442\u043e \u0431\u044b \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0441\u0438\u0433\u043d\u0430\u043b \u0431\u044b\u043b \u0440\u0430\u0432\u0435\u043d 0 \u043a\u043e\u0433\u0434\u0430 X \u0440\u0430\u0432\u0435\u043d 2? \u041f\u0440\u043e\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u043a\u043b\u043e\u043d \u043a\u0440\u0438\u0432\u043e\u0439 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u2013 <b>\u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442 \u0441\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u044e \u043a\u0440\u0438\u0432\u0443\u044e \u043d\u0430\u043f\u0440\u0430\u0432\u043e<\/b>.<br \/>  \u042d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0411\u0438\u0430\u0441. \u0415\u0441\u043b\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0411\u0438\u0430\u0441 \u043a \u043d\u0430\u0448\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a:<br \/>   <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a0a\/6c1\/b51\/a0a6c1b514e3dbdc4556a60aeb64eb91.gif\" alt=\"image\"\/><\/p>\n<p>  \u2026 \u0442\u043e\u0433\u0434\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0430\u0448\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f sig(w0*x + w1*1.0). \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432\u0435\u0441\u0430 W1:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/994\/8fd\/509\/9948fd5091b75121790c6608444b4889.png\" alt=\"image\"\/><\/p>\n<p>  \u0412\u0435\u0441 W1 \u0440\u0430\u0432\u043d\u044b\u0439 -5 \u0441\u0434\u0432\u0438\u043d\u0435\u0442 \u043a\u0440\u0438\u0432\u0443\u044e \u043d\u0430\u043f\u0440\u0430\u0432\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d 0 \u043f\u0440\u0438 X \u0440\u0430\u0432\u043d\u043e\u043c 2  <\/div>\n<\/div>\n<p>  <\/p>\n<h4><b>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/b><\/h4>\n<p>  \u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0435\u0441\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435.<\/p>\n<pre><code class=\"python\">def runAll(self, nn, X):     z=[0]     m = len(X)     a = [ copy.deepcopy(X) ] # a[0] is equal to the first input values     logFunc = self.logisticFunctionVectorize()     for i in range(1, len(nn['structure'])): # for each layer except the input         a[i-1] = np.c_[ np.ones(m), a[i-1]]; # add bias column to the previous matrix of activation functions         z.append(a[i-1]*nn['theta'][i].T) # for all neurons in current layer multiply corresponds neurons         # in previous layers by the appropriate weights and sum the productions         a.append(logFunc(z[i])) # apply activation function for each value     nn['z'] = z     nn['a'] = a     return a[len(nn['structure'])-1] <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/b><\/p>\n<div class=\"spoiler_text\">\u0424\u043e\u0440\u043c\u0430\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u044b <b>X<\/b>: \u0441\u0442\u0440\u043e\u043a\u0438 \u2013 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (input values), \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u2013 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>  <b>Z<\/b> \u2013 \u043b\u0438\u0441\u0442 \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438 \u0441\u0443\u043c\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u044f \u0438 \u0432\u0435\u0441\u043e\u0432 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0445 \u0438\u0445 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0441\u043b\u043e\u0435\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u043c. \u0412\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0443 \u043d\u0438\u0445 \u043d\u0435\u0442 \u0432\u0435\u0441\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c z[0] \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 z[1]<\/p>\n<p>  <b>a<\/b> \u2013 \u043b\u0438\u0441\u0442 \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<br \/>  a[0] \u2013 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0431\u0438\u0430\u0441 (\u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e m * 1) \u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 X, \u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0451 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 X*(1+\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 X). \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e a[1] \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043a\u0440\u044b\u0442\u043e\u043c \u0441\u043b\u043e\u0435, \u0435\u0451 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 X*(1+\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043a\u0440\u044b\u0442\u043e\u043c \u0441\u043b\u043e\u0435)  <\/div>\n<\/div>\n<p>  <\/p>\n<pre><code class=\"python\">def logisticFunction(self, x):     a = 1\/(1+np.exp(-x))     if a == 1: a = 0.99999 #make smallest step to the direction of zero     elif a == 0: a = 0.00001 # It is possible to use np.nextafter(0, 1) and      #make smallest step to the direction of one, but sometimes this step is too small and other algorithms fail :)     return a      def logisticFunctionVectorize(self):     return np.vectorize(self.logisticFunction) <\/code><\/pre>\n<p>  \u041a\u0440\u0430\u0442\u043a\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b np.vectorize \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u044b 10\u04451 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e 10\u04451<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0427\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 logisticFunction?<\/b><\/p>\n<div class=\"spoiler_text\">\u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0432\u0430\u0436\u043d\u044b\u0439 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u0430\u043c\u0435\u043d\u044c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435\u043c (\u0442\u0443\u0442 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u0431\u0435\u0436\u0430\u0442\u044c \u0432 \u043f\u0435\u0440\u0435\u0434). \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0447\u0442\u043e \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0435\u0442\u044c, \u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0435\u0432, \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432, \u0432\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u0435\u0441\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a, \u0447\u0442\u043e \u0441\u0443\u043c\u043c\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0439 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043b\u043e\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 -40. \u041b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442 -40 \u0440\u0430\u0434\u043e\u0441\u0442\u043d\u043e \u0432\u0435\u0440\u043d\u0435\u0442 \u0432\u0430\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u0443. <\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0430\u0448\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u044d\u0442\u0443 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0430 \u043e\u0442 1 \u2014 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 [ log(1-output) ] \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c \u043e\u0442 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d, \u043d\u043e \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0435 \u0432\u044b\u0441\u043a\u043e\u0447\u0438\u0442, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0448\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f.  <\/div>\n<\/div>\n<p>  \u0418\u0437 \u0432\u0430\u0436\u043d\u043e\u0433\u043e \u0445\u043e\u0447\u0443 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0431\u0438\u0430\u0441\u0430 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u0441\u0443\u043c\u043c\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0439. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e \u0431\u0438\u0430\u0441 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0432\u0435\u043d \u0435\u0434\u0438\u043d\u0438\u0446\u0435, \u0430 \u043d\u0435 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442 \u0435\u0434\u0438\u043d\u0438\u0446\u044b (\u0447\u0442\u043e \u0435\u0441\u0442\u044c 0,73)<\/p>\n<pre><code class=\"python\">a[i-1] = np.c_[ np.ones(m), a[i-1]]; <\/code><\/pre>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u0438\u0430\u0441 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u043e\u044f\u0445, \u043a\u0440\u043e\u043c\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f, \u0432 \u043d\u0451\u043c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u044b = \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432*\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043b\u043e\u0435).<\/p>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u0431\u043b\u0438\u0437\u043a\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u043f\u0438\u0442\u043e\u043d\u043e\u043c \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <i>runAll <\/i>\u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u043a\u043e\u043f\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0430\u043c\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c <i>nn<\/i>) \u0430 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043d\u0438\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <i>nn[\u2018z\u2019] = z<\/i> \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u0435\u0442\u044c nn \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e nn \u043e\u0431\u0440\u0430\u0442\u043d\u043e.<\/p>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (<i>runAll<\/i>) \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u0430\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u0441\u0435\u0442\u0438 (\u0435\u0451 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432*1) \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u044b <i>z<\/i> \u0438 <i>a<\/i> \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438.<\/p>\n<h4><b>\u041e\u0448\u0438\u0431\u043a\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/b><\/h4>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435<br \/>   <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/392\/44c\/a8a\/39244ca8a6c6aca4582f66758e7e20cb.png\" alt=\"image\"\/><br \/>  \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0432\u0437\u044f\u0442\u0430 \u0438\u0437 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 Machine Learning<br \/>  <i>m<\/i> \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, <i>K<\/i> \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, <i>h0(xi)<\/i> \u2013 \u0432\u0435\u043a\u0442\u043e\u0440 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, <i>\u03b8<\/i> \u2014 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u0435\u0441\u043e\u0432, \u0433\u0434\u0435 \u03b8^1 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432\u0435\u0441\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f, <i>lambda <\/i>\u2013 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438. <\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432\u0430\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0439 \u0438 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439, \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e :), \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u043d\u0430 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 2 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. <\/p>\n<p>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0441\u0443\u0442\u0438 \u044d\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0440\u0430\u0441\u0442\u044f\u043d\u0435\u0442\u0441\u044f, \u0438 \u044f \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430 \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0433\u043e, \u043d\u043e \u043f\u0438\u0448\u0438\u0442\u0435, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044e.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412 \u0447\u0435\u043c \u0441\u0443\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438?<\/b><\/p>\n<div class=\"spoiler_text\">\u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044e, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 (\u0442\u0430\u043a \u043a\u0430\u043a \u0432\u043e \u0432\u0441\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0443\u043c\u043c\u0430 \u0434\u0432\u0443\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0432\u0435\u0441\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c\u0438.  <\/div>\n<\/div>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442 \u043d\u0430\u043c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 float, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0448\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u043b. <\/p>\n<pre><code class=\"python\">def costTotal(self, theta, nn, X, y, lamb):     m = len(X)     #following string is for fmin_cg computaton     if type(theta) == np.ndarray: nn['theta'] = self.roll(theta, nn['structure'])     y = np.matrix(copy.deepcopy(y))     hAll = self.runAll(nn, X) #feed forward to obtain output of neural network     cost = self.cost(hAll, y)     return cost\/m+(lamb\/(2*m))*self.regul(nn['theta']) #apply regularization  <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b <i>X<\/i> \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<br \/>  \u041f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0443\u043b\u044b, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u0435\u0442\u0438<\/p>\n<pre><code class=\"python\">def cost(self, h, y):     logH=np.log(h)     log1H=np.log(1-h)     cost=-1*y.T*logH-(1-y.T)*log1H #transpose y for matrix multiplication     return cost.sum(axis=0).sum(axis=1) # sum matrix of costs for each output neuron and input vector <\/code><\/pre>\n<p>  \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044e<\/p>\n<pre><code class=\"python\">def regul(self, theta):     reg=0     thetaLocal=copy.deepcopy(theta)     for i in range(1,len(thetaLocal)):         thetaLocal[i]=np.delete(thetaLocal[i],0,1) # delete bias connection         thetaLocal[i]=np.power(thetaLocal[i], 2) # square the values because they can be negative         reg+=thetaLocal[i].sum(axis=0).sum(axis=1) # sum at first rows, than columns     return reg <\/code><\/pre>\n<p>  \u0414\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u043f\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438 theta \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432\u0435\u0441\u044c\u043c\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0435\u0432, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043d\u0435\u0441\u0435\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0443\u0440\u043e\u043d.<\/p>\n<p>  \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u044f\u0437\u044c \u0441 \u0431\u0438\u0430\u0441\u043e\u043c \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e \u043e\u0441\u0438 \u0425. <\/p>\n<h4><b>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430<\/b><\/h4>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c, \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u043b \u0438 \u043e\u0448\u0438\u0431\u043a\u0443, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u0438 \u0432\u0435\u0441\u043e\u0432.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0430\u043c \u043d\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u0446\u0438\u043a\u043b\u0430 \u043f\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c \u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0441\u0447\u0435\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430, \u043c\u044b \u0432\u044b\u043d\u043e\u0441\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u0435\u0440\u0435\u0434 \u0446\u0438\u043a\u043b\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0448\u0430\u0433\u0430\u0445 \u043c\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <i>runAll <\/i>\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0447\u0442\u043e \u0431\u044b \u043e\u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u043b\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0430 \u043d\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 (\u0441\u0442\u0440\u043e\u043a\u0438) \u043f\u043e\u0448\u0442\u0443\u0447\u043d\u043e, \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0437\u0430\u0442\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u0438\u043c \u0432 \u0446\u0438\u043a\u043b\u0435. \u041f\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043c\u0435\u0440\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u0438\u0447\u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 25%<\/p>\n<p>  \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u043e \u0441\u043b\u043e\u044f\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0435\u0451 \u043d\u0430 \u0441\u043b\u043e\u0439 \u043d\u0430\u0437\u0430\u0434, \u0447\u0442\u043e \u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0438 \u0442.\u0434.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u043c \u0441\u0435\u0442\u044f\u043c \u0434\u043b\u044f \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0442\u0440\u0435\u0445\u0441\u043b\u043e\u0439\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 (\u0441 \u043e\u0434\u043d\u0438\u043c \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0441\u043b\u043e\u0435\u043c), \u0434\u0435\u043b\u044c\u0442\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 3, \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0438\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043b\u0438\u0441\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 3 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <\/p>\n<pre><code class=\"python\">def backpropagation(self, theta, nn, X, y, lamb):     layersNumb=len(nn['structure'])     thetaDelta = [0]*(layersNumb)     m=len(X)     #calculate matrix of outpit values for all input vectors X     hLoc = copy.deepcopy(self.runAll(nn, X))     yLoc=np.matrix(y)     thetaLoc = copy.deepcopy(nn['theta'])     derFunct=np.vectorize(lambda x: (1\/(1+np.exp(-x)))*(1-(1\/(1+np.exp(-x)))) )          zLoc = copy.deepcopy(nn['z'])     aLoc = copy.deepcopy(nn['a'])     for n in range(0, len(X)):         delta = [0]*(layersNumb+1)  #fill list with zeros         delta[len(delta)-1]=(hLoc[n].T-yLoc[n].T) #calculate delta of error of output layer         for i in range(layersNumb-1, 0, -1):             if i&gt;1: # we can not calculate delta[0] because we don't have theta[0] (and even we don't need it)                 z = zLoc[i-1][n]                 z = np.c_[ [[1]], z ] #add one for correct matrix multiplication                 delta[i]=np.multiply(thetaLoc[i].T*delta[i+1],derFunct(z).T)                 delta[i]=delta[i][1:]             thetaDelta[i] = thetaDelta[i] + delta[i+1]*aLoc[i-1][n]      for i in range(1, len(thetaDelta)):         thetaDelta[i]=thetaDelta[i]\/m         thetaDelta[i][:,1:]=thetaDelta[i][:,1:]+thetaLoc[i][:,1:]*(lamb\/m) #regularization         if type(theta) == np.ndarray: return np.asarray(self.unroll(thetaDelta)).reshape(-1) # to work also with fmin_cg     return thetaDelta <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u0438\u0441\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438, \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u0430\u0442\u0440\u0438\u0446 <i>theta<\/i><\/p>\n<p>  \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u044f\u043c\u0431\u0434\u0430, \u044d\u0442\u043e \u043d\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435 \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f \u043e\u0442 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u0430), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u0435\u0449\u0435 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0443\u044e   <\/p>\n<pre><code class=\"python\">lambda x: (1\/(1+np.exp(-x)))*(1-(1\/(1+np.exp(-x)))) <\/code><\/pre>\n<p>  <\/p>\n<h4><b>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/b><\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0438 \u0434\u0430\u0436\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u043e\u0431\u0443\u0447\u0438\u0442\u044c \u0447\u0435\u043c\u0443 \u043d\u0438\u0431\u0443\u0434\u044c \ud83d\ude42<br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0443\u0447\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 [0;5) \u044d\u0442\u043e \u043d\u0443\u043b\u044c, [5;9] \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u0430 <\/p>\n<pre><code class=\"python\">nn=nt.create([1, 1000, 1])  lamb=0.3 cost=1 alf = 0.2 xTrain = [[0], [1], [1.9], [2], [3], [3.31], [4], [4.7], [5], [5.1], [6], [7], [8], [9]] yTrain = [[0], [0], [0], [0], [0], [0], [0], [0], [1], [1], [1], [1], [1], [1]]  xTest= [[0.4], [1.51], [2.6], [3.23], [4.87], [5.78], [6.334], [7.667], [8.22], [9.1]] yTest = [[0], [0], [0], [0], [0], [1], [1], [1], [1], [1]]  theta = nt.unroll(nn['theta']) print(nt.runAll(nn, xTest)) theta =  optimize.fmin_cg(nt.costTotal, fprime=nt.backpropagation,                 x0=theta, args=(nn, xTrain, yTrain, lamb), maxiter=200) print(nt.runAll(nn, xTest)) <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0412\u044b\u0432\u043e\u0434 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0434\u043e \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438, \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u0438 \u043f\u043e\u0441\u043b\u0435 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438. \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0431\u043b\u0438\u0436\u0435 \u043a \u043d\u0443\u043b\u044e, \u0432\u0442\u043e\u0440\u044b\u0435 \u043f\u044f\u0442\u044c \u0431\u043b\u0438\u0436\u0435 \u043a \u0435\u0434\u0438\u043d\u0438\u0446\u0435.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/490\/9cc\/587\/4909cc587e0fe9533647841fae97056f.png\" alt=\"image\"\/><\/p>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <i>fmin_cg<\/i> \u0442\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043c\u0435\u043d\u044f\u0442\u044c <i>theta<\/i>(\u0432\u0435\u0441\u0430 \u0441\u0435\u0442\u0438) \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.<br \/>  \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c \u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0443\u044e \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044e \u043e\u0442 \u043d\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0439. \u041d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f 4 \u0447\u0438\u0441\u043b\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f, \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u0430, \u0435\u0441\u043b\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0442\u0441\u044f, \u044d\u0442\u043e \u043d\u0443\u043b\u044c.<\/p>\n<pre><code class=\"python\">nn=nt.create([4, 1000, 1])  lamb=0.3 cost=1 alf = 0.2 xTrain = [[1, 2.3, 4.5, 5.3], [1.1, 1.3, 2.4, 2.4], [1.9, 1.7, 1.5, 1.3], [2.3, 2.9, 3.3, 4.9], [3, 5.2, 6.1, 8.2], [3.31, 2.9, 2.4, 1.5], [4.9, 5.7, 6.1, 6.3],  [4.85, 5.0, 7.2, 8.1], [5.9, 5.3, 4.2, 3.3], [7.7, 5.4, 4.3, 3.9], [6.7, 5.3, 3.2, 1.4], [7.1, 8.6, 9.1, 9.9], [8.5, 7.4, 6.3, 4.1], [9.8, 5.3, 3.1, 2.9]] yTrain = [[1], [1], [0], [1], [1], [0], [1],  [1], [0], [0], [0], [1], [0], [0]]  xTest= [[0.4, 1.9, 2.5, 3.1], [1.51, 2.0, 2.4, 3.8], [2.6, 5.1, 6.2, 7.2], [3.23, 4.1, 4.3, 4.9], [7.1, 7.6, 8.2, 9.3],  [5.78, 5.1, 4.5, 3.55], [6.33, 4.8, 3.4, 2.5], [7.67, 6.45, 5.8, 4.31], [8.22, 6.32, 5.87, 3.59], [9.1, 8.5, 7.7, 6.1]] yTest = [[1], [1], [1], [1], [1],  [0], [0], [0], [0], [0]]                  while cost&gt;0:     cost=nt.costTotal(False, nn, xTrain, yTrain, lamb)     costTest=nt.costTotal(False, nn, xTest, yTest, lamb)     delta=nt.backpropagation(False, nn, xTrain, yTrain, lamb)     nn['theta']=[nn['theta'][i]-alf*delta[i] for i in range(0,len(nn['theta']))]     print('Train cost ', cost[0,0], 'Test cost ', costTest[0,0])     print(nt.runAll(nn, xTest)) <\/code><\/pre>\n<p>  \u0421\u043f\u0443\u0441\u0442\u044f 400 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 (\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 1 \u043c\u0438\u043d.) \u043f\u043e \u043a\u0430\u043a\u0438\u043c \u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c \u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u0430\u043c\u0430\u044f \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 (\u0432\u044b\u0445\u043e\u0434 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 0.13), \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/359\/b59\/975\/359b599753118b58ee1e158cebd8e118.png\" alt=\"image\"\/><\/p>\n<p>  \u0412 \u0446\u0438\u043a\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c <i>theta<\/i> \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043a\u0430\u043a \u0431\u044b \u0441\u043a\u043e\u043b\u044c\u0437\u0438\u043c \u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0430 \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442, \u0442\u043e \u043c\u044b \u0448\u043b\u0438 \u0431\u044b \u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0443). \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <i>alf<\/i> \u0447\u0430\u0441\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u00ab\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f\u00bb \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u043e \u043a\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c <i>theta<\/i> \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <i>\u0430\u043b\u044c\u0444\u0430<\/i> \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u043e\u0448\u0438\u0431\u043a\u0430 \u0441\u0435\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0436\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u043f\u0440\u044b\u0433\u0430\u0442\u044c \u0432\u0432\u0435\u0440\u0445 \u0438 \u0432\u043d\u0438\u0437 \u0442\u0430\u043a \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0448\u0430\u0433\u0438\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c.<\/p>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432\u0441\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0438\u043f\u0430 dict, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0451 \u043b\u0435\u0433\u043a\u043e \u0441\u0435\u0440\u0440\u0438\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u0444\u0430\u043b\u0435 \u0438 \u0442\u0430\u043a \u0436\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u0442\u0435\u043c\u0443 \u043a\u0430\u043a \u0435\u0449\u0435 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 (\u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 Python) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043d\u0430 GPU <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u043c\u043e\u0434\u0443\u043b\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import copy import numpy as np import random as rd  class network:     # layers -list [5 10 10 5] - 5 input, 2 hidden layers (10 neurons each), 5 output     def create(self, layers):         theta=[0]         for i in range(1, len(layers)): # for each layer from the first (skip zero layer!)             theta.append(np.mat(np.random.uniform(-1, 1, (layers[i], layers[i-1]+1)))) # create nxM+1 matrix (+bias!) with random floats in range [-1; 1]         nn={'theta':theta,'structure':layers}         return nn          def runAll(self, nn, X):         z=[0]         m = len(X)         a = [ copy.deepcopy(X) ] # a[0] is equal to the first input values         logFunc = self.logisticFunction()         for i in range(1, len(nn['structure'])): # for each layer except the input             a[i-1] = np.c_[ np.ones(m), a[i-1]]; # add bias column to the previous matrix of activation functions             z.append(a[i-1]*nn['theta'][i].T) # for all neurons in current layer multiply corresponds neurons             # in previous layers by the appropriate weights and sum the productions             a.append(logFunc(z[i])) # apply activation function for each value         nn['z'] = z         nn['a'] = a         return a[len(nn['structure'])-1]              def run(self, nn, input):         z=[0]         a=[]         a.append(copy.deepcopy(input))         a[0]=np.matrix(a[0]).T # nx1 vector         logFunc = self.logisticFunction()         for i in range(1, len(nn['structure'])):             a[i-1]=np.vstack(([1], a[i-1]))             z.append(nn['theta'][i]*a[i-1])             a.append(logFunc(z[i]))         nn['z'] = z         nn['a'] = a         return a[len(nn['structure'])-1]              def logisticFunction(self):         return np.vectorize(lambda x: 1\/(1+np.exp(-x)))              def costTotal(self, theta, nn, X, y, lamb):         m = len(X)         #following string is for fmin_cg computaton         if type(theta) == np.ndarray: nn['theta'] = self.roll(theta, nn['structure'])         y = np.matrix(copy.deepcopy(y))         hAll = self.runAll(nn, X) #feed forward to obtain output of neural network         cost = self.cost(hAll, y)         return cost\/m+(lamb\/(2*m))*self.regul(nn['theta']) #apply regularization           def cost(self, h, y):         logH=np.log(h)         log1H=np.log(1-h)         cost=-1*y.T*logH-(1-y.T)*log1H #transpose y for matrix multiplication         return cost.sum(axis=0).sum(axis=1) # sum matrix of costs for each output neuron and input vector              def regul(self, theta):         reg=0         thetaLocal=copy.deepcopy(theta)         for i in range(1,len(thetaLocal)):             thetaLocal[i]=np.delete(thetaLocal[i],0,1) # delete bias connection             thetaLocal[i]=np.power(thetaLocal[i], 2) # square the values because they can be negative             reg+=thetaLocal[i].sum(axis=0).sum(axis=1) # sum at first rows, than columns         return reg              def backpropagation(self, theta, nn, X, y, lamb):         layersNumb=len(nn['structure'])         thetaDelta = [0]*(layersNumb)         m=len(X)         #calculate matrix of outpit values for all input vectors X         hLoc = copy.deepcopy(self.runAll(nn, X))         yLoc=np.matrix(y)         thetaLoc = copy.deepcopy(nn['theta'])         derFunct=np.vectorize(lambda x: (1\/(1+np.exp(-x)))*(1-(1\/(1+np.exp(-x)))) )                  zLoc = copy.deepcopy(nn['z'])         aLoc = copy.deepcopy(nn['a'])         for n in range(0, len(X)):             delta = [0]*(layersNumb+1)  #fill list with zeros             delta[len(delta)-1]=(hLoc[n].T-yLoc[n].T) #calculate delta of error of output layer             for i in range(layersNumb-1, 0, -1):                 if i&gt;1: # we can not calculate delta[0] because we don't have theta[0] (and even we don't need it)                     z = zLoc[i-1][n]                     z = np.c_[ [[1]], z ] #add one for correct matrix multiplication                     delta[i]=np.multiply(thetaLoc[i].T*delta[i+1],derFunct(z).T)                     delta[i]=delta[i][1:]                 thetaDelta[i] = thetaDelta[i] + delta[i+1]*aLoc[i-1][n]          for i in range(1, len(thetaDelta)):             thetaDelta[i]=thetaDelta[i]\/m             thetaDelta[i][:,1:]=thetaDelta[i][:,1:]+thetaLoc[i][:,1:]*(lamb\/m) #regularization                 if type(theta) == np.ndarray: return np.asarray(self.unroll(thetaDelta)).reshape(-1) # to work also with fmin_cg         return thetaDelta          # create 1d array form lists like theta     def unroll(self, arr):         for i in range(0,len(arr)):             arr[i]=np.matrix(arr[i])             if i==0:                 res=(arr[i]).ravel().T             else:                 res=np.vstack((res,(arr[i]).ravel().T))         res.shape=(1, len(res))         return res     # roll back 1d array to list with matrices according to given structure     def roll(self, arr, structure):         rolled=[arr[0]]         shift=1         for i in range(1,len(structure)):             temparr=copy.deepcopy(arr[shift:shift+structure[i]*(structure[i-1]+1)])             temparr.shape=(structure[i],structure[i-1]+1)             rolled.append(np.matrix(temparr))             shift+=structure[i]*(structure[i-1]+1)         return rolled <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/258611\/\"> http:\/\/habrahabr.ru\/post\/258611\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 (\u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439) \u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043d\u0430 Python. \u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0430 \u043a \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u043c \u043a\u0443\u0440\u0441\u0430 Machine learning by Andrew Ng \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043a\u0443\u0440\u0441 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e, \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0438\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0442\u0435\u043b\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0441 <s>\u043f\u0440\u0435\u0444\u0435\u0440\u0430\u043d\u0441\u043e\u043c \u0438 \u0431\u0430\u0440\u044b\u0448\u043d\u044f\u043c<\/s> \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043d\u043e \u0447\u0442\u043e \u0442\u043e \u0432\u0430\u0441 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b\u043e, \u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u0446\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u0442\u0435\u043e\u0440\u0438\u0435\u0439 (\u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0443\u0449\u0435\u043d\u0430).   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-257819","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257819","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=257819"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257819\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}