{"id":388468,"date":"2024-06-29T07:57:16","date_gmt":"2024-06-29T07:57:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=388468"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=388468","title":{"rendered":"<span>Asymmetric horizontal distribution for time series<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>Introduction<\/h2>\n<p>The goal of paper is to demonstrate non-trivial approaches to give statistical estimate for forecast result. Idea comes from <strong>probability cone<\/strong> concept. A\u00a0probability cone\u00a0is an indicator that forecasts a statistical distribution from a set point in time into the future. This acticle provide alternative approaches using machine learning, regression analysis.<\/p>\n<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7ec\/1e8\/1ba\/7ec1e81ba57686f8e95dd34268bc0322.png\" alt=\"Probability cone\" title=\"Probability cone\" width=\"967\" height=\"532\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ec\/1e8\/1ba\/7ec1e81ba57686f8e95dd34268bc0322.png\"\/><figcaption>Probability cone<\/figcaption><\/figure>\n<p>There are properties of probability cone<\/p>\n<ul>\n<li>\n<p>Forecast a Standard or Laplace distribution.<\/p>\n<\/li>\n<li>\n<p>Change the how many bars the cones will lookback and sample in their calculations.<\/p>\n<\/li>\n<li>\n<p>Set how many bars to forecast the cones.<\/p>\n<\/li>\n<li>\n<p>Let the cones follow price from a set number of bars back.<\/p>\n<\/li>\n<\/ul>\n<p>As we may see cone is parametric and non-robust model that takes into accout only few values. It will be solved by our methods. For accomplishing that goal, we need to collect data, preprocess it, train model, assing confidence intervals for forecast values.<\/p>\n<h2>Collecting data<\/h2>\n<p>We collected data via <code>yfinance library<\/code> and saved it to database.<\/p>\n<p><code>start_period = \"2021-01-01\"<br \/> end_period = \"2022-01-01\"<br \/> interval = \"1h\"<\/code><\/p>\n<p><code>def collect_save_data(assets, interval, start_period, end_period):<br \/> collected_data = [collect_stock_data(security_name=asset, start_period=start_period, end_period=end_period, interval=interval) for asset in assets]<br \/> [data[0].to_sql(str(name.lower() + \"_\" + interval), engine, if_exists=\"replace\") for name, data in zip(assets, collected_data)]<\/code><\/p>\n<p><code>screen = pd.read_csv(r\"C:\\Users\\1\\Downloads\\nasdaq_screener.csv\")<br \/> worst_20 = screen.sort_values(by=['Net Change']).head(20)[\"Symbol\"].to_numpy()<br \/> best_20 = screen.sort_values(by=['Net Change']).tail(20)[\"Symbol\"].to_numpy()<\/code><\/p>\n<h2>Preprocessing<\/h2>\n<ul>\n<li>\n<p>Scaling<\/p>\n<\/li>\n<li>\n<p>Rates of return<\/p>\n<\/li>\n<li>\n<p>Diff operator<\/p>\n<\/li>\n<li>\n<p>Wavelet transformations <\/p>\n<\/li>\n<li>\n<p>Singular spectrum analysis <\/p>\n<\/li>\n<\/ul>\n<p><strong>Standard scaler<\/strong> standardize features by removing the mean and scaling to unit variance.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\frac{x - \\mu}{\\sigma}\" alt=\"\\frac{x - \\mu}{\\sigma}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8fb\/768\/3fd\/8fb7683fdf9515fbc8d4fb294fa626a3.svg\" width=\"53\" height=\"41\"\/><\/p>\n<p><strong>Robust scaler<\/strong>. This Scaler removes the median and scales the data according to the quantile range.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\frac{x - x_{median}}{Q_{75}(x) - Q_{25}(x)}\" alt=\"\\frac{x - x_{median}}{Q_{75}(x) - Q_{25}(x)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/479\/83f\/2db\/47983f2db7acfb627744110c255246cd.svg\" width=\"144\" height=\"46\"\/><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5b7\/717\/0ca\/5b77170ca6829206ceae21f6e1dc068b.png\" width=\"1223\" height=\"511\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5b7\/717\/0ca\/5b77170ca6829206ceae21f6e1dc068b.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>Diff operator<\/strong> returns difference between the values for each row.<\/p>\n<p><strong>Wavelet transformations <\/strong>uses a series of functions called wavelets, each with a different scale. The word wavelet means a small wave, and this is exactly what a wavelet is.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/61a\/7d3\/1cd\/61a7d31cd51e4614292d0f9bf67ae92b.png\" width=\"816\" height=\"379\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/61a\/7d3\/1cd\/61a7d31cd51e4614292d0f9bf67ae92b.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>Singular spectrum analysis <\/strong>is a\u00a0nonparametric\u00a0spectral estimation\u00a0method.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/023\/d24\/5ae\/023d245ae8b18b314d70781d2071315d.png\" width=\"1200\" height=\"856\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/023\/d24\/5ae\/023d245ae8b18b314d70781d2071315d.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>Modeling and creating distributions\u00a0  <\/h2>\n<h3>Linear regression<\/h3>\n<p>Linear regression is a statistical method used to model the linear relationship between a dependent variable and one or more independent variables. It is a type of supervised machine learning algorithm that is used to predict a continuous outcome variable (also known as the dependent variable) based on one or more predictor variables (also known as the independent variables). Let&#8217;s train it on  19 consequent values.  <\/p>\n<p><code>scaler = RobustScaler()<\/code><\/p>\n<p><code>X = scaler.fit_transform(assets[\"googl\"].iloc[:-20,7:26].to_numpy())<br \/> X = sm.add_constant(X)<br \/> y = scaler.fit_transform(assets[\"googl\"].iloc[:-20,26:27].to_numpy())<br \/> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=42, shuffle=True)<\/code><\/p>\n<p><code>model = sm.OLS(y_train, X_train).fit()<br \/> predictions = model.predict(X_test)<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b4e\/288\/bea\/b4e288bea3f9c529f8e4503549b51f0f.png\" alt=\"\" title=\"\" width=\"822\" height=\"264\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b4e\/288\/bea\/b4e288bea3f9c529f8e4503549b51f0f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>Then collect std errors for every param in regression.<\/p>\n<pre><code class=\"python\">model.bse  array([0.00102656, 0.03234659, 0.04763217, 0.04585968, 0.04170401,        0.04149197, 0.04077272, 0.04054332, 0.04153725, 0.04220609,        0.0417554 , 0.04046333, 0.04128765, 0.04102963, 0.04096044,        0.04111759, 0.04085509, 0.03993392, 0.04110262, 0.02925589])  model.params  array([-4.32672277e-04,  5.82552401e-02, -6.81325066e-02, -4.29359924e-04,        5.05127833e-03,  3.92011313e-03, -1.18822186e-02, -2.72863632e-02,         -8.02409511e-03,  1.00404139e-01, -7.00931586e-02,  6.04074269e-02,        -4.16763135e-02,  4.99412759e-02, -5.78008738e-02,  2.34065881e-02,            -1.77504834e-02,  2.07238701e-03, -4.47528509e-02,  1.04294193e+00])<\/code><\/pre>\n<p>Cone generating function  <\/p>\n<pre><code class=\"python\">def generate_cone(model, data, n):     lower_reg_w = np.array(model.params) - 1.96 * np.array(model.bse)     upper_reg_w = np.array(model.params) + 1.96 * np.array(model.bse)          lower_data = data     upper_data = data          for i in range(n):         lower_data = np.append(lower_data, (lower_reg_w * lower_data[i:]).sum())         upper_data = np.append(upper_data, (upper_reg_w * upper_data[i:]).sum())              return lower_data, upper_data<\/code><\/pre>\n<p>Formulas<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"y_{low} = \\sum_{i=1}^n((\\theta_i - 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) x_i) + (\\theta_0 - 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) bias + \\varepsilon\" alt=\"y_{low} = \\sum_{i=1}^n((\\theta_i - 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) x_i) + (\\theta_0 - 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) bias + \\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b98\/ef6\/475\/b98ef64752719657d9d1d3c45fdb0736.svg\" width=\"457\" height=\"57\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"y_{upp} = \\sum_{i=1}^n((\\theta_i + 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) x_i) + (\\theta_0 + 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) bias + \\varepsilon\" alt=\"y_{upp} = \\sum_{i=1}^n((\\theta_i + 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) x_i) + (\\theta_0 + 1.96 \\frac{\\hat{\\sigma}_{\\theta_i}}{\\sqrt{n}}) bias + \\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4ca\/b1a\/c27\/4cab1ac279fea7890a11ed1178060bae.svg\" width=\"458\" height=\"57\"\/><\/p>\n<p>Results<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e67\/2be\/b31\/e672beb31d4d33d6fbc090138e76b6e8.png\" width=\"966\" height=\"514\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e67\/2be\/b31\/e672beb31d4d33d6fbc090138e76b6e8.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>Deep learinng approach<\/h3>\n<h3> Fully connected NN<\/h3>\n<p>A fully connected neural network (also known as a dense neural network) is a type of artificial neural network in which each neuron in one layer is connected to every neuron in the next layer. In other words, the neurons in one layer receive input from all the neurons in the previous layer and send output to all the neurons in the next layer.<\/p>\n<p>A fully connected neural network consists of an input layer, one or more hidden layers, and an output layer. The input layer receives the input data, the hidden layers process the data through a series of transformations, and the output layer produces the final output. Each layer is made up of a set of neurons, which are connected to the neurons in the next layer through a set of weights.<\/p>\n<pre><code class=\"python\">class ConeNN(nn.Module):     def __init__(self):         super(ConeNN, self).__init__()                  self.layers = torch.nn.Sequential()         self.layers.add_module(\"linear1\", nn.Linear(19, 40))         self.layers.add_module('relu1', torch.nn.LeakyReLU())         self.layers.add_module(\"linear2\", nn.Linear(40, 30))         self.layers.add_module('relu2', torch.nn.LeakyReLU())         self.layers.add_module(\"linear3\", nn.Linear(30, 20))         self.layers.add_module('relu3', torch.nn.LeakyReLU())         self.layers.add_module(\"linear4\", nn.Linear(20, 20))         self.layers.add_module('relu4', torch.nn.LeakyReLU())         self.layers.add_module(\"linear5\", nn.Linear(20, 1))              def forward(self, x):         return self.layers(x)<\/code><\/pre>\n<p>Cone generating<\/p>\n<pre><code class=\"python\">def generate_cone(model, data, n):     conf = 1.96 * assets[\"GOOGL\"][\"Open\"].std()          lower_data = torch.tensor(data, dtype=torch.float32)     upper_data = torch.tensor(data, dtype=torch.float32)          network.eval()     with torch.no_grad():         for i in range(n):             lower_data = torch.cat((lower_data, network(lower_data[i:]) - conf \/ len(X_train)), 0)             upper_data = torch.cat((upper_data, network(upper_data[i:]) + conf \/ len(X_train)) , 0)              return lower_data, upper_data<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6d5\/176\/52e\/6d517652e567de9409c574fb833fc3cc.png\" width=\"856\" height=\"679\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6d5\/176\/52e\/6d517652e567de9409c574fb833fc3cc.png\"\/><figcaption><\/figcaption><\/figure>\n<p>Results for RNN and LSTM weren&#8217;t that good.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f25\/848\/3b4\/f258483b40e466e360b9fcfbc0b868bb.png\" width=\"887\" height=\"777\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f25\/848\/3b4\/f258483b40e466e360b9fcfbc0b868bb.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/706184\/\"> https:\/\/habr.com\/ru\/articles\/706184\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>Introduction<\/h2>\n<p>The goal of paper is to demonstrate non-trivial approaches to give statistical estimate for forecast result. Idea comes from <strong>probability cone<\/strong> concept. A\u00a0probability cone\u00a0is an indicator that forecasts a statistical distribution from a set point in time into the future. This acticle provide alternative approaches using machine learning, regression analysis.<\/p>\n<\/p>\n<figure class=\"full-width\"><figcaption>Probability cone<\/figcaption><\/figure>\n<p>There are properties of probability cone<\/p>\n<ul>\n<li>\n<p>Forecast a Standard or Laplace distribution.<\/p>\n<\/li>\n<li>\n<p>Change the how many bars the cones will lookback and sample in their calculations.<\/p>\n<\/li>\n<li>\n<p>Set how many bars to forecast the cones.<\/p>\n<\/li>\n<li>\n<p>Let the cones follow price from a set number of bars back.<\/p>\n<\/li>\n<\/ul>\n<p>As we may see cone is parametric and non-robust model that takes into accout only few values. It will be solved by our methods. For accomplishing that goal, we need to collect data, preprocess it, train model, assing confidence intervals for forecast values.<\/p>\n<h2>Collecting data<\/h2>\n<p>We collected data via <code>yfinance library<\/code> and saved it to database.<\/p>\n<p><code>start_period = \"2021-01-01\"<br \/> end_period = \"2022-01-01\"<br \/> interval = \"1h\"<\/code><\/p>\n<p><code>def collect_save_data(assets, interval, start_period, end_period):<br \/> collected_data = [collect_stock_data(security_name=asset, start_period=start_period, end_period=end_period, interval=interval) for asset in assets]<br \/> [data[0].to_sql(str(name.lower() + \"_\" + interval), engine, if_exists=\"replace\") for name, data in zip(assets, collected_data)]<\/code><\/p>\n<p><code>screen = pd.read_csv(r\"C:\\Users\\1\\Downloads\\nasdaq_screener.csv\")<br \/> worst_20 = screen.sort_values(by=['Net Change']).head(20)[\"Symbol\"].to_numpy()<br \/> best_20 = screen.sort_values(by=['Net Change']).tail(20)[\"Symbol\"].to_numpy()<\/code><\/p>\n<h2>Preprocessing<\/h2>\n<ul>\n<li>\n<p>Scaling<\/p>\n<\/li>\n<li>\n<p>Rates of return<\/p>\n<\/li>\n<li>\n<p>Diff operator<\/p>\n<\/li>\n<li>\n<p>Wavelet transformations <\/p>\n<\/li>\n<li>\n<p>Singular spectrum analysis <\/p>\n<\/li>\n<\/ul>\n<p><strong>Standard scaler<\/strong> standardize features by removing the mean and scaling to unit variance.<\/p>\n<p><strong>Robust scaler<\/strong>. This Scaler removes the median and scales the data according to the quantile range.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>Diff operator<\/strong> returns difference between the values for each row.<\/p>\n<p><strong>Wavelet transformations <\/strong>uses a series of functions called wavelets, each with a different scale. The word wavelet means a small wave, and this is exactly what a wavelet is.  <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>Singular spectrum analysis <\/strong>is a\u00a0nonparametric\u00a0spectral estimation\u00a0method.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>Modeling and creating distributions\u00a0  <\/h2>\n<h3>Linear regression<\/h3>\n<p>Linear regression is a statistical method used to model the linear relationship between a dependent variable and one or more independent variables. It is a type of supervised machine learning algorithm that is used to predict a continuous outcome variable (also known as the dependent variable) based on one or more predictor variables (also known as the independent variables). Let&#8217;s train it on  19 consequent values.  <\/p>\n<p><code>scaler = RobustScaler()<\/code><\/p>\n<p><code>X = scaler.fit_transform(assets[\"googl\"].iloc[:-20,7:26].to_numpy())<br \/> X = sm.add_constant(X)<br \/> y = scaler.fit_transform(assets[\"googl\"].iloc[:-20,26:27].to_numpy())<br \/> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=42, shuffle=True)<\/code><\/p>\n<p><code>model = sm.OLS(y_train, X_train).fit()<br \/> predictions = model.predict(X_test)<\/code><\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>Then collect std errors for every param in regression.<\/p>\n<pre><code class=\"python\">model.bse  array([0.00102656, 0.03234659, 0.04763217, 0.04585968, 0.04170401,        0.04149197, 0.04077272, 0.04054332, 0.04153725, 0.04220609,        0.0417554 , 0.04046333, 0.04128765, 0.04102963, 0.04096044,        0.04111759, 0.04085509, 0.03993392, 0.04110262, 0.02925589])  model.params  array([-4.32672277e-04,  5.82552401e-02, -6.81325066e-02, -4.29359924e-04,        5.05127833e-03,  3.92011313e-03, -1.18822186e-02, -2.72863632e-02,         -8.02409511e-03,  1.00404139e-01, -7.00931586e-02,  6.04074269e-02,        -4.16763135e-02,  4.99412759e-02, -5.78008738e-02,  2.34065881e-02,            -1.77504834e-02,  2.07238701e-03, -4.47528509e-02,  1.04294193e+00])<\/code><\/pre>\n<p>Cone generating function  <\/p>\n<pre><code class=\"python\">def generate_cone(model, data, n):     lower_reg_w = np.array(model.params) - 1.96 * np.array(model.bse)     upper_reg_w = np.array(model.params) + 1.96 * np.array(model.bse)          lower_data = data     upper_data = data          for i in range(n):         lower_data = np.append(lower_data, (lower_reg_w * lower_data[i:]).sum())         upper_data = np.append(upper_data, (upper_reg_w * upper_data[i:]).sum())              return lower_data, upper_data<\/code><\/pre>\n<p>Formulas<\/p>\n<p>Results<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>Deep learinng approach<\/h3>\n<h3> Fully connected NN<\/h3>\n<p>A fully connected neural network (also known as a dense neural network) is a type of artificial neural network in which each neuron in one layer is connected to every neuron in the next layer. In other words, the neurons in one layer receive input from all the neurons in the previous layer and send output to all the neurons in the next layer.<\/p>\n<p>A fully connected neural network consists of an input layer, one or more hidden layers, and an output layer. The input layer receives the input data, the hidden layers process the data through a series of transformations, and the output layer produces the final output. Each layer is made up of a set of neurons, which are connected to the neurons in the next layer through a set of weights.<\/p>\n<pre><code class=\"python\">class ConeNN(nn.Module):     def __init__(self):         super(ConeNN, self).__init__()                  self.layers = torch.nn.Sequential()         self.layers.add_module(\"linear1\", nn.Linear(19, 40))         self.layers.add_module('relu1', torch.nn.LeakyReLU())         self.layers.add_module(\"linear2\", nn.Linear(40, 30))         self.layers.add_module('relu2', torch.nn.LeakyReLU())         self.layers.add_module(\"linear3\", nn.Linear(30, 20))         self.layers.add_module('relu3', torch.nn.LeakyReLU())         self.layers.add_module(\"linear4\", nn.Linear(20, 20))         self.layers.add_module('relu4', torch.nn.LeakyReLU())         self.layers.add_module(\"linear5\", nn.Linear(20, 1))              def forward(self, x):         return self.layers(x)<\/code><\/pre>\n<p>Cone generating<\/p>\n<pre><code class=\"python\">def generate_cone(model, data, n):     conf = 1.96 * assets[\"GOOGL\"][\"Open\"].std()          lower_data = torch.tensor(data, dtype=torch.float32)     upper_data = torch.tensor(data, dtype=torch.float32)          network.eval()     with torch.no_grad():         for i in range(n):             lower_data = torch.cat((lower_data, network(lower_data[i:]) - conf \/ len(X_train)), 0)             upper_data = torch.cat((upper_data, network(upper_data[i:]) + conf \/ len(X_train)) , 0)              return lower_data, upper_data<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>Results for RNN and LSTM weren&#8217;t that good.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/706184\/\"> https:\/\/habr.com\/ru\/articles\/706184\/<\/a><br \/><\/br><\/br><\/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-388468","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/388468","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=388468"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/388468\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=388468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=388468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=388468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}