{"id":300504,"date":"2020-03-21T15:00:18","date_gmt":"2020-03-21T15:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=300504"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=300504","title":{"rendered":"\u041a\u043e\u043d\u0441\u043f\u0435\u043a\u0442 \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493396\/\">\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u043a\u0440\u0430\u0442\u043a\u043e\u043c\u0443 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/491326\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0440\u0430\u0437<\/a> \u043c\u044b \u043e\u0441\u0432\u0435\u0442\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u043e\u0434 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0438\u0445 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 Python. \u041a\u043e\u043d\u0441\u043f\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u0432 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u044f \u0437\u043d\u0430\u0435\u0442 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0438\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>&#8212;<a href=\"http:\/\/www.cleverstudents.ru\/articles\/mnk.html\" rel=\"nofollow\">\u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f, \u043e\u0446\u0435\u043d\u0435\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432<\/a>. \u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u043a\u0442\u043e\u0440\u0430 \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0432 \u0432\u0438\u0434\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c (\u043e\u0448\u0438\u0431\u043a\u0438).<\/p>\n<\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/18d\/b68\/41a\/18db6841ae774e1316cf542f7de488c0.svg\" alt=\"$ \\sum_{i=1}^n (y_i-(ax_i+b))^2 \u2192 min$\" data-tex=\"display\"><\/math><\/p>\n<p>   <\/p>\n<p> \u0415\u0441\u043b\u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u043e \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:   <\/p>\n<\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/095\/de0\/0aa\/095de00aaa2511fea2bb2d58dcf8efc1.svg\" alt=\"$a = \\frac{n\\sum_{i=0}^n x_i y_i - \\sum_{i=0}^n x_i \\sum_{i=0}^n y_i}{n\\sum_{i=0}^n x_i^2 - (\\sum_{i=0}^n x_i)^2}$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c68\/d70\/7c0\/c68d707c05f5299a7f7e2df58e2ec819.svg\" alt=\"$b = \\frac{\\sum_{i=0}^n y_i - a\\sum_{i=0}^n x_i }{n}$\" data-tex=\"display\"><\/math><\/p>\n<p>    \u0413\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435:    <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qq\/-a\/ro\/qq-aroe67waa9klowdgyro5zf0i.png\"><\/p>\n<p>   \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0413\u0430\u0443\u0441\u0441\u0430-\u041c\u0430\u0440\u043a\u043e\u0432\u0430:<\/p>\n<ul>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f5f\/fe5\/4ee\/f5ffe54ee41b1fbca721fde86b4dbf1c.svg\" alt=\"$E(\u03b5_i)=0$\" data-tex=\"inline\"><\/math> \u2014 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0440\u0430\u0432\u043d\u043e 0<\/li>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b07\/158\/1ab\/b071581ab60b09b7307383337a9db922.svg\" alt=\"$\u03c3^2(\u03b5_i)=const$\" data-tex=\"inline\"><\/math> \u2014 \u0433\u043e\u043c\u043e\u0441\u043a\u0435\u0434\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c<\/li>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/09e\/966\/5ff\/09e9665ff99f2cba6aa387c61200a3af.svg\" alt=\"$cov(\u03b5_i,\u03b5_j)=0,i\u2260j$\" data-tex=\"inline\"><\/math> \u2014 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u0443\u043b\u044c\u0442\u0438\u043a\u043e\u043b\u043b\u0438\u043d\u0435\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/li>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/42f\/173\/c29\/42f173c2992cf2826d484e0dac62fb74.svg\" alt=\"$x_i$\" data-tex=\"inline\"><\/math> \u2014 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430<\/li>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/420\/8df\/3ae\/4208df3aec5d0c67717ab965237b3abc.svg\" alt=\"$\u03b5 \\sim N(0,\u03c3^2)$\" data-tex=\"inline\"><\/math> \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430<\/li>\n<\/ul>\n<p>   \u0422\u043e \u043f\u043e \u0442\u0435\u043e\u0440\u0435\u043c\u0435 \u0413\u0430\u0443\u0441\u0441\u0430-\u041c\u0430\u0440\u043a\u043e\u0432\u0430 \u043e\u0446\u0435\u043d\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\u041b\u0438\u043d\u0435\u0439\u043d\u043e\u0441\u0442\u044c \u2014 \u043f\u0440\u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 Y \u043e\u0446\u0435\u043d\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e.<\/li>\n<li>\u041d\u0435\u0441\u043c\u0435\u0449\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u2014 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043c\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0441\u044f \u043a \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/li>\n<li>\u0421\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u2014 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043c\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u0441\u0442\u0440\u0435\u043c\u044f\u0442\u0441\u044f \u043a \u0438\u0445 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/li>\n<li>\u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u2014 \u043e\u0446\u0435\u043d\u043a\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0435\u0439.<\/li>\n<li>\u041d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u2014 \u043e\u0446\u0435\u043d\u043a\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b.<\/li>\n<\/ul>\n<p>    <\/p>\n<pre><code class=\"python\"> #imports import statsmodels.api as sm  #model fit Y = [1,3,4,5,2,3,4] X = range(1,8) X = sm.add_constant(X) model = sm.OLS(Y,X) results = model.fit()  #result print(results.summary()) results.predict(X)<\/code><\/pre>\n<p>&#8212;<a href=\"https:\/\/studme.org\/72649\/ekonomika\/obobschennyy_metod_naimenshih_kvadratov\" rel=\"nofollow\">\u041e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u043a GLS<\/a>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0413\u0430\u0443\u0441\u0441\u0430-\u041c\u0430\u0440\u043a\u043e\u0432\u0430 \u043e \u0433\u043e\u043c\u043e\u0441\u043a\u0435\u0434\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 (\u043f\u043e\u0441\u0442\u043e\u044f\u043d\u0441\u0442\u0432\u0435 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438) \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u0438 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439. \u0426\u0435\u043b\u044c GLS \u2014 \u0443\u0447\u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043f\u0443\u0442\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438. \u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<p><math>$$display$$a^* = (X^T\u03a9^{-1}X)^{-1}X^T\u03a9^{-1}Y$$display$$<\/math><\/p>\n<p> \u0433\u0434\u0435 \u03a9 \u2014 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432. \u041e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u03a9 = 1 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u041c\u041d\u041a<\/p>\n<pre><code class=\"python\"> #imports import statsmodels.api as sm from scipy.linalg import toeplitz  #model fit data = sm.datasets.longley.load(as_pandas=False) data.exog = sm.add_constant(data.exog) ols_resid = sm.OLS(data.endog, data.exog).fit().resid res_fit = sm.OLS(ols_resid[1:], ols_resid[:-1]).fit() rho = res_fit.params order = toeplitz(np.arange(16)) sigma = rho**order gls_model = sm.GLS(data.endog, data.exog, sigma=sigma) gls_results = gls_model.fit()  #result print(gls_results.summary()) gls_results.predict<\/code><\/pre>\n<p>    <\/p>\n<p>&#8212;<a href=\"https:\/\/studme.org\/91760\/ekonomika\/vzveshennyy_metod_naimenshih_kvadratov\" rel=\"nofollow\">\u0412\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u043a wls<\/a>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043e\u0446\u0435\u043d\u043e\u043a (\u0435\u0441\u0442\u044c \u0433\u0435\u0442\u0435\u0440\u043e\u0441\u043a\u0435\u0434\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c) \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u043c\u044b, \u0432\u0437\u0432\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0445 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e, \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u041c\u041d\u041a.   <\/p>\n<p>   <\/p>\n<pre><code class=\"python\"> #imports import statsmodels.api as sm  #model fit Y = [1,3,4,5,2,3,4] X = range(1,8) X = sm.add_constant(X) wls_model = sm.WLS(Y,X, weights=list(range(1,8))) results = wls_model.fit()  #result print(results.summary()) results.predict<\/code><\/pre>\n<p>    <\/p>\n<p>&#8212;<a href=\"https:\/\/studme.org\/169412\/matematika_himiya_fizik\/dvuhshagovyy_metod_naimenshih_kvadratov\" rel=\"nofollow\">\u0414\u0432\u0443\u0445\u0448\u0430\u0433\u043e\u0432\u044b\u0439 \u043c\u043d\u043a tsls<\/a>. \u0414\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u0434\u043b\u044f wls, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0435\u0435 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c wls. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u044d\u043d\u0434\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u0438. <\/p>\n<p>    <\/p>\n<pre><code class=\"python\"> #imports from linearmodels import IV2SLS, IVLIML, IVGMM, IVGMMCUE from linearmodels.datasets import meps from statsmodels.api import OLS, add_constant  #model fit data = meps.load() data = data.dropna() controls = ['totchr', 'female', 'age', 'linc','blhisp'] instruments = ['ssiratio', 'lowincome', 'multlc', 'firmsz'] data['const'] = 1 controls = ['const'] + controls ivolsmod = IV2SLS(data.ldrugexp, data[['hi_empunion'] + controls], None, None) res_ols = ivolsmod.fit()  #result print(res_ols) print(res_ols.predict)<\/code><\/pre>\n<p>   <\/p>\n<p>&#8212;<a href=\"https:\/\/ru.wikipedia.org\/wiki\/ARIMA\" rel=\"nofollow\">ARIMA<\/a>. \u041c\u043e\u0434\u0435\u043b\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432. Auto-regression (\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 Y \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u043f\u0435\u0440\u0438\u043e\u0434\u0435) integrated (\u0431\u0435\u0440\u0443\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u043d\u0435\u0441\u0442\u0430\u0446\u0438\u043e\u043d\u0430\u0440\u043d\u043e\u0441\u0442\u0438 \u2014 \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u0440\u043d\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0440\u0435\u043d\u0434 \u0438\u043b\u0438 \u0446\u0438\u043a\u043b\u0438\u0447\u043d\u043e\u0441\u0442\u044c) moving average (\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u043f\u0435\u0440\u0438\u043e\u0434\u0435).<\/p>\n<pre><code class=\"python\"> #imports from pandas import read_csv from pandas import datetime from pandas import DataFrame from statsmodels.tsa.arima_model import ARIMA from matplotlib import pyplot  #model fit def parser(x): \treturn datetime.strptime('190'+x, '%Y-%m')  series = read_csv('shampoo-sales.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser) model = ARIMA(series, order=(5,1,0)) model_fit = model.fit(disp=0)  #result print(model_fit.summary()) model_fit.forecast() <\/code><\/pre>\n<p>   <\/p>\n<p>&#8212;<a href=\"https:\/\/www.machinelearningmastery.ru\/develop-arch-and-garch-models-for-time-series-forecasting-in-python\/\" rel=\"nofollow\">GARCH <\/a>. General autoregression conditional heteroscedastic \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u0430\u0445 \u0435\u0441\u0442\u044c \u0433\u0435\u0442\u0435\u0440\u043e\u0441\u043a\u0435\u0434\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>    <\/p>\n<pre><code class=\"python\"> #imports import pyflux as pf import pandas as pd from pandas_datareader import DataReader from datetime import datetime  #model fit jpm = DataReader('JPM',  'yahoo', datetime(2006,1,1), datetime(2016,3,10)) returns = pd.DataFrame(np.diff(np.log(jpm['Adj Close'].values))) returns.index = jpm.index.values[1:jpm.index.values.shape[0]] returns.columns = ['JPM Returns']  #result model = pf.GARCH(returns,p=1,q=1) x = model.fit() x.summary()<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u043f\u0443\u0449\u0435\u043d \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0438 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0430. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<p><\/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=\"https:\/\/habr.com\/ru\/post\/493396\/\"> https:\/\/habr.com\/ru\/post\/493396\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493396\/\">\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u043a\u0440\u0430\u0442\u043a\u043e\u043c\u0443 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/491326\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0440\u0430\u0437<\/a> \u043c\u044b \u043e\u0441\u0432\u0435\u0442\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u043e\u0434 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0438\u0445 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 Python. \u041a\u043e\u043d\u0441\u043f\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u0432 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u044f \u0437\u043d\u0430\u0435\u0442 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0438\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. <\/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-300504","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300504","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=300504"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300504\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}