<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 如何為長短期記憶網絡準備單變量時間序列數據 > 原文: [https://machinelearningmastery.com/prepare-univariate-time-series-data-long-short-term-memory-networks/](https://machinelearningmastery.com/prepare-univariate-time-series-data-long-short-term-memory-networks/) 當您剛剛開始深度學習時,很難準備數據。 長期短期記憶,或 LSTM,循環神經網絡期望在 Keras Python 深度學習庫中進行三維輸入。 如果您的時間序列數據中包含數千個長序列,則必須將時間序列拆分為樣本,然后將其重新整形為 LSTM 模型。 在本教程中,您將了解如何使用 Keras 在 Python 中為 LSTM 模型準備單變量時間序列數據。 讓我們開始吧。 ![How to Prepare Univariate Time Series Data for Long Short-Term Memory Networks](https://3qeqpr26caki16dnhd19sv6by6v-wpengine.netdna-ssl.com/wp-content/uploads/2017/11/How-to-Prepare-Univariate-Time-Series-Data-for-Long-Short-Term-Memory-Networks.jpg) 如何為長期短期記憶網絡準備單變量時間序列數據 照片來自 [Miguel Mendez](https://www.flickr.com/photos/flynn_nrg/8487128120/) ,保留一些權利。 ## 如何準備時間序列數據 也許我得到的最常見問題是如何為監督學習準備時間序列數據。 我寫過一些關于這個主題的帖子,例如: * [如何將時間序列轉換為 Python 中的監督學習問題](https://machinelearningmastery.com/convert-time-series-supervised-learning-problem-python/) * [時間序列預測作為監督學習](https://machinelearningmastery.com/time-series-forecasting-supervised-learning/) 但是,這些帖子對每個人都沒有幫助。 我最近收到了這封郵件: > 我的數據文件中有兩列有 5000 行,第 1 列是時間(間隔 1 小時),第 2 列是比特/秒,我試圖預測比特/秒。在這種情況下,您可以幫我設置[LSTM]的樣本,時間步長和功能嗎? 這里幾乎沒有問題: * LSTM 期望 3D 輸入,并且第一次了解這個問題可能具有挑戰性。 * LSTM 不喜歡超過 200-400 個時間步長的序列,因此需要將數據拆分為樣本。 在本教程中,我們將使用此問題作為顯示為 Keras 中的 LSTM 網絡專門準備數據的一種方法的基礎。 ## 1.加載數據 我假設你知道如何將數據加載為 Pandas Series 或 DataFrame。 如果沒有,請參閱以下帖子: * [如何在 Python 中加載和探索時間序列數據](https://machinelearningmastery.com/load-explore-time-series-data-python/) * [如何在 Python 中加載機器學習數據](https://machinelearningmastery.com/load-machine-learning-data-python/) 在這里,我們將通過在 5,000 個時間步長內存中定義新數據集來模擬加載。 ```py from numpy import array # load... data = list() n = 5000 for i in range(n): data.append([i+1, (i+1)*10]) data = array(data) print(data[:5, :]) print(data.shape) ``` 運行此片段既會打印前 5 行數據,也會打印已加載數據的形狀。 我們可以看到我們有 5,000 行和 2 列:標準的單變量時間序列數據集。 ```py [[ 1 10] [ 2 20] [ 3 30] [ 4 40] [ 5 50]] (5000, 2) ``` ## 2.停機時間 如果您的時間序列數據隨著時間的推移是一致的并且沒有缺失值,我們可以刪除時間列。 如果沒有,您可能希望查看插入缺失值,將數據重新采樣到新的時間刻度,或者開發可以處理缺失值的模型。看帖子如: * [如何使用 Python 處理序列預測問題中的缺失時間步長](https://machinelearningmastery.com/handle-missing-timesteps-sequence-prediction-problems-python/) * [如何使用 Python 處理丟失的數據](https://machinelearningmastery.com/handle-missing-data-python/) * [如何使用 Python 重新取樣和插值您的時間序列數據](https://machinelearningmastery.com/resample-interpolate-time-series-data-python/) 在這里,我們只刪除第一列: ```py # drop time data = data[:, 1] print(data.shape) ``` 現在我們有一個 5,000 個值的數組。 ```py (5000,) ``` ## 3.拆分成樣品 LSTM 需要處理樣品,其中每個樣品是單個時間序列。 在這種情況下,5,000 個時間步長太長;根據我讀過的一些論文,LSTM 可以更好地完成 200 到 400 個步驟。因此,我們需要將 5,000 個時間步驟分成多個較短的子序列。 我在這里寫了更多關于拆分長序列的文章: * [如何處理具有長短期記憶循環神經網絡的超長序列](https://machinelearningmastery.com/handle-long-sequences-long-short-term-memory-recurrent-neural-networks/) * [如何準備 Keras 中截斷反向傳播的序列預測](https://machinelearningmastery.com/truncated-backpropagation-through-time-in-keras/) 有很多方法可以做到這一點,你可能想根據你的問題探索一些。 例如,您可能需要重疊序列,也許非重疊是好的,但您的模型需要跨子序列的狀態等等。 在這里,我們將 5,000 個時間步驟分成 25 個子序列,每個子序列有 200 個時間步長。我們將采用老式方式,而不是使用 NumPy 或 Python 技巧,以便您可以看到正在發生的事情。 ```py # split into samples (e.g. 5000/200 = 25) samples = list() length = 200 # step over the 5,000 in jumps of 200 for i in range(0,n,length): # grab from i to i + 200 sample = data[i:i+length] samples.append(sample) print(len(samples)) ``` 我們現在有 25 個子序列,每個子序列有 200 個時間步長。 ```py 25 ``` 如果您更喜歡在一個班輪中這樣做,那就去吧。我很想知道你能想出什么。 在下面的評論中發布您的方法。 ## 4.重塑子序列 LSTM 需要具有[樣本,時間步長和特征]格式的數據。 在這里,我們有 25 個樣本,每個樣本 200 個時間步長和 1 個特征。 首先,我們需要將我們的數組列表轉換為 25 x 200 的 2D NumPy 數組。 ```py # convert list of arrays into 2d array data = array(samples) print(data.shape) ``` 運行這件作品,你應該看到: ```py (25, 200) ``` 接下來,我們可以使用 _reshape()_ 函數為我們的單個特征添加一個額外的維度。 ```py # reshape into [samples, timesteps, features] # expect [25, 200, 1] data = data.reshape((len(samples), length, 1)) print(data.shape) ``` 就是這樣。 現在,數據可用作 LSTM 模型的輸入(X)。 ```py (25, 200, 1) ``` ## 進一步閱讀 如果您希望深入了解,本節將提供有關該主題的更多資源。 ### 相關文章 * [如何將時間序列轉換為 Python 中的監督學習問題](https://machinelearningmastery.com/convert-time-series-supervised-learning-problem-python/) * [時間序列預測作為監督學習](https://machinelearningmastery.com/time-series-forecasting-supervised-learning/) * [如何在 Python 中加載和探索時間序列數據](https://machinelearningmastery.com/load-explore-time-series-data-python/) * [如何在 Python 中加載機器學習數據](https://machinelearningmastery.com/load-machine-learning-data-python/) * [如何使用 Python 處理序列預測問題中的缺失時間步長](https://machinelearningmastery.com/handle-missing-timesteps-sequence-prediction-problems-python/) * [如何使用 Python 處理丟失的數據](https://machinelearningmastery.com/handle-missing-data-python/) * [如何使用 Python 重新取樣和插值您的時間序列數據](https://machinelearningmastery.com/resample-interpolate-time-series-data-python/) * [如何處理具有長短期記憶循環神經網絡的超長序列](https://machinelearningmastery.com/handle-long-sequences-long-short-term-memory-recurrent-neural-networks/) * [如何準備 Keras 中截斷反向傳播的序列預測](https://machinelearningmastery.com/truncated-backpropagation-through-time-in-keras/) ### API * [Keras 的 LSTM API](https://keras.io/layers/recurrent/#lstm) * [numpy.reshape API](https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html) ## 摘要 在本教程中,您了解了如何將長的單變量時間序列數據轉換為可用于在 Python 中訓練 LSTM 模型的表單。 這篇文章有幫助嗎?你有任何問題嗎? 請在下面的評論中告訴我。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看