Answers.Body: <p>No idea if this would result in a &quot;decent&quot; model, but can you not take the disjoint union of all features?</p>
  <p>Roughly that means you concatenate the <span class="math-container">$n$</span> features for all 8 stocks into a single &quot;megastock&quot; that has <span class="math-container">$8n$</span> features and <span class="math-container">$8$</span> outputs (<span class="math-container">$1$</span> price per stock), as opposed to 8 models with <span class="math-container">$n$</span> features and <span class="math-container">$1$</span> output each.</p>
  <p>In other words, for each stock you have <span class="math-container">$n$</span> input features and 1 output (price), so taking the disjoint union would result in <span class="math-container">$8n$</span> input features and 8 outputs (price for stock <span class="math-container">$1$</span>, price for stock <span class="math-container">$2$</span>, etc.).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-12T20:15:12.097Z
Answers.LastActivityDate: 2022-12-12T20:15:12.097Z
Answers.UserDisplayName: étale-cohomology
Answers.Body: <p>Maybe you can try to encode &quot;stock&quot; column via one hot encoding <a href="https://stackoverflow.com/questions/37292872/how-can-i-one-hot-encode-in-python">https://stackoverflow.com/questions/37292872/how-can-i-one-hot-encode-in-python</a></p>
  <p>so for example, if you have &quot;AAPL&quot; and &quot;MSFT&quot; stocks, than AAPL would be encoded as [0, 1] and MSFT would be encoded  as [1, 0].</p>
  <p>And maybe it worth to do the same for &quot;Year&quot;, like 2022 -&gt; [0, 0, 1], 2021 -&gt; [0, 1, 0], 2020 -&gt; [1, 0, 0]</p>
  <p>And also, I think price should also be normalized, so instead of absolute values you can use minmax normalization, to convert price to number from 0-1 range <a href="https://stackoverflow.com/questions/48178884/min-max-normalisation-of-a-numpy-array">https://stackoverflow.com/questions/48178884/min-max-normalisation-of-a-numpy-array</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-17T14:06:28.413Z
Answers.Text: thanks for the ideas. In a prior approach, I have categorised the price (-1,0,1), however, if I would encode my 2000+ stocks, wouldn't that create a horribly huge dataframe for my model?
Answers.UserDisplayName: Sphenoidale
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-15T15:18:54.720Z
Answers.LastActivityDate: 2022-07-15T15:18:54.720Z
Answers.UserDisplayName: Mikita Shautsou
Body: <p>I have the following situation:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Stock</th>
  <th>Time_Stamps</th>
  <th>Feature_1</th>
  <th>Feature_2</th>
  <th>Feature_n</th>
  <th>Price</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Stock_1</td>
  <td>2019</td>
  <td>0.5</td>
  <td>1.0</td>
  <td>1.0</td>
  <td>100</td>
  </tr>
  <tr>
  <td>Stock_1</td>
  <td>2020</td>
  <td>0.7</td>
  <td>1.3</td>
  <td>0.9</td>
  <td>90</td>
  </tr>
  <tr>
  <td>Stock_2</td>
  <td>2019</td>
  <td>0.3</td>
  <td>0.9</td>
  <td>1.1</td>
  <td>110</td>
  </tr>
  <tr>
  <td>Stock_2</td>
  <td>2020</td>
  <td>0.2</td>
  <td>0.8</td>
  <td>1.1</td>
  <td>120</td>
  </tr>
  <tr>
  <td>Stock_n</td>
  <td>year_n</td>
  <td>value_n</td>
  <td>value_n</td>
  <td>value_n</td>
  <td>price_n</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>So this is how my data table is structured. My original df has 100+ features and 70000k observations resp. 2000+ stocks - so this is only a simplification.</p>
  <p>I want to train a LSTM on this data table and look for features correlation with the price.
  Common idea, nothing new, so pls save your time giving me &quot;this will not work&quot; bla bla.</p>
  <p>I am generally interested in how you would approach this problem. We have multiple inputs (features) for our time series forecast with 8 time stamps (8 years) per stock. However, in my understanding, I'd have to train my model for every stock seperately which is inconvenient.</p>
  <p>How would you pre-process my data, so that I can train a decent model?</p>
  
Tags: <long-short-term-memory><data-science>
Title: LSTM exploding? - multiple parallel time series with multiple variables
UserDisplayName: Sphenoidale
ThreadText: # LSTM exploding? - multiple parallel time series with multiple variables
  
  (Asked by: username_0 on 2022-07-15)
  
  I have the following situation:
  
  | Stock | Time\_Stamps | Feature\_1 | Feature\_2 | Feature\_n | Price |
  | --- | --- | --- | --- | --- | --- |
  | Stock\_1 | 2019 | 0.5 | 1.0 | 1.0 | 100 |
  | Stock\_1 | 2020 | 0.7 | 1.3 | 0.9 | 90 |
  | Stock\_2 | 2019 | 0.3 | 0.9 | 1.1 | 110 |
  | Stock\_2 | 2020 | 0.2 | 0.8 | 1.1 | 120 |
  | Stock\_n | year\_n | value\_n | value\_n | value\_n | price\_n |
  
  So this is how my data table is structured. My original df has 100+ features and 70000k observations resp. 2000+ stocks - so this is only a simplification.
  
  I want to train a LSTM on this data table and look for features correlation with the price.
  Common idea, nothing new, so pls save your time giving me "this will not work" bla bla.
  
  I am generally interested in how you would approach this problem. We have multiple inputs (features) for our time series forecast with 8 time stamps (8 years) per stock. However, in my understanding, I'd have to train my model for every stock seperately which is inconvenient.
  
  How would you pre-process my data, so that I can train a decent model?
  
  **Tags:** long-short-term-memory, data-science
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-12-12. Score: 0
  
  No idea if this would result in a "decent" model, but can you not take the disjoint union of all features?
  
  Roughly that means you concatenate the $n$ features for all 8 stocks into a single "megastock" that has $8n$ features and $8$ outputs ($1$ price per stock), as opposed to 8 models with $n$ features and $1$ output each.
  
  In other words, for each stock you have $n$ input features and 1 output (price), so taking the disjoint union would result in $8n$ input features and 8 outputs (price for stock $1$, price for stock $2$, etc.).
  
  
  ---
  
  ### Answer by username_2 on 2022-07-15. Score: 0
  
  Maybe you can try to encode "stock" column via one hot encoding <https://stackoverflow.com/questions/37292872/how-can-i-one-hot-encode-in-python>
  
  so for example, if you have "AAPL" and "MSFT" stocks, than AAPL would be encoded as [0, 1] and MSFT would be encoded as [1, 0].
  
  And maybe it worth to do the same for "Year", like 2022 -> [0, 0, 1], 2021 -> [0, 1, 0], 2020 -> [1, 0, 0]
  
  And also, I think price should also be normalized, so instead of absolute values you can use minmax normalization, to convert price to number from 0-1 range <https://stackoverflow.com/questions/48178884/min-max-normalisation-of-a-numpy-array>
  
  > **Comments:**
  > **username_0**: thanks for the ideas. In a prior approach, I have categorised the price (-1,0,1), however, if I would encode my 2000+ stocks, wouldn't that create a horribly huge dataframe for my model?  
  
  ---
  
  