How do i correctly predict the humidity values?












0














I have the following input:



startDate = "2013-01-01"
endDate = "2013-01-01"
knownTimestamps = ['2013-01-01 00:00','2013-01-01 01:00','2013-01-01 02:00','2013-01-01 03:00','2013-01-01 04:00',
'2013-01-01 05:00','2013-01-01 06:00','2013-01-01 08:00','2013-01-01 10:00','2013-01-01 11:00',
'2013-01-01 12:00','2013-01-01 13:00','2013-01-01 16:00','2013-01-01 17:00','2013-01-01 18:00',
'2013-01-01 19:00','2013-01-01 20:00','2013-01-01 21:00','2013-01-01 23:00']
humidity = ['0.62','0.64','0.62','0.63','0.63','0.64','0.63','0.64','0.48','0.46','0.45','0.44','0.46','0.47','0.48','0.49','0.51','0.52','0.52']
timestamps = ['2013-01-01 07:00','2013-01-01 09:00','2013-01-01 14:00','2013-01-01 15:00','2013-01-01 22:00']


And I am using following function to predict the humidity values using AR model in python.



from statsmodels.tsa.arima_model import ARIMA
def predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps):
data_prediction = pd.DataFrame({'knownTimestamps': knownTimestamps,'humidity': humidity})
print(data_prediction.head(10))
history = [float(x) for x in data_prediction.humidity]
predictions =
test = timestamps
for t in range(len(test)):
model = ARIMA(history, order=(2,2,0))
model_fit = model.fit(disp=0)
output = model_fit.forecast()
yhat = output[0]
predictions.append(float(yhat))
obs = test[t]
history.append(float(obs))
print(predictions)
return predictions


The model predict the same value of humidity for the values in time stamp list.



res = predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps) 
print(res)


output = [0.5287247355700563, 0.5287247355700563, 0.5287247355700563,
0.5287247355700563, 0.5287247355700563]


Can someone tell me where I am wrong?










share|improve this question





























    0














    I have the following input:



    startDate = "2013-01-01"
    endDate = "2013-01-01"
    knownTimestamps = ['2013-01-01 00:00','2013-01-01 01:00','2013-01-01 02:00','2013-01-01 03:00','2013-01-01 04:00',
    '2013-01-01 05:00','2013-01-01 06:00','2013-01-01 08:00','2013-01-01 10:00','2013-01-01 11:00',
    '2013-01-01 12:00','2013-01-01 13:00','2013-01-01 16:00','2013-01-01 17:00','2013-01-01 18:00',
    '2013-01-01 19:00','2013-01-01 20:00','2013-01-01 21:00','2013-01-01 23:00']
    humidity = ['0.62','0.64','0.62','0.63','0.63','0.64','0.63','0.64','0.48','0.46','0.45','0.44','0.46','0.47','0.48','0.49','0.51','0.52','0.52']
    timestamps = ['2013-01-01 07:00','2013-01-01 09:00','2013-01-01 14:00','2013-01-01 15:00','2013-01-01 22:00']


    And I am using following function to predict the humidity values using AR model in python.



    from statsmodels.tsa.arima_model import ARIMA
    def predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps):
    data_prediction = pd.DataFrame({'knownTimestamps': knownTimestamps,'humidity': humidity})
    print(data_prediction.head(10))
    history = [float(x) for x in data_prediction.humidity]
    predictions =
    test = timestamps
    for t in range(len(test)):
    model = ARIMA(history, order=(2,2,0))
    model_fit = model.fit(disp=0)
    output = model_fit.forecast()
    yhat = output[0]
    predictions.append(float(yhat))
    obs = test[t]
    history.append(float(obs))
    print(predictions)
    return predictions


    The model predict the same value of humidity for the values in time stamp list.



    res = predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps) 
    print(res)


    output = [0.5287247355700563, 0.5287247355700563, 0.5287247355700563,
    0.5287247355700563, 0.5287247355700563]


    Can someone tell me where I am wrong?










    share|improve this question



























      0












      0








      0







      I have the following input:



      startDate = "2013-01-01"
      endDate = "2013-01-01"
      knownTimestamps = ['2013-01-01 00:00','2013-01-01 01:00','2013-01-01 02:00','2013-01-01 03:00','2013-01-01 04:00',
      '2013-01-01 05:00','2013-01-01 06:00','2013-01-01 08:00','2013-01-01 10:00','2013-01-01 11:00',
      '2013-01-01 12:00','2013-01-01 13:00','2013-01-01 16:00','2013-01-01 17:00','2013-01-01 18:00',
      '2013-01-01 19:00','2013-01-01 20:00','2013-01-01 21:00','2013-01-01 23:00']
      humidity = ['0.62','0.64','0.62','0.63','0.63','0.64','0.63','0.64','0.48','0.46','0.45','0.44','0.46','0.47','0.48','0.49','0.51','0.52','0.52']
      timestamps = ['2013-01-01 07:00','2013-01-01 09:00','2013-01-01 14:00','2013-01-01 15:00','2013-01-01 22:00']


      And I am using following function to predict the humidity values using AR model in python.



      from statsmodels.tsa.arima_model import ARIMA
      def predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps):
      data_prediction = pd.DataFrame({'knownTimestamps': knownTimestamps,'humidity': humidity})
      print(data_prediction.head(10))
      history = [float(x) for x in data_prediction.humidity]
      predictions =
      test = timestamps
      for t in range(len(test)):
      model = ARIMA(history, order=(2,2,0))
      model_fit = model.fit(disp=0)
      output = model_fit.forecast()
      yhat = output[0]
      predictions.append(float(yhat))
      obs = test[t]
      history.append(float(obs))
      print(predictions)
      return predictions


      The model predict the same value of humidity for the values in time stamp list.



      res = predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps) 
      print(res)


      output = [0.5287247355700563, 0.5287247355700563, 0.5287247355700563,
      0.5287247355700563, 0.5287247355700563]


      Can someone tell me where I am wrong?










      share|improve this question















      I have the following input:



      startDate = "2013-01-01"
      endDate = "2013-01-01"
      knownTimestamps = ['2013-01-01 00:00','2013-01-01 01:00','2013-01-01 02:00','2013-01-01 03:00','2013-01-01 04:00',
      '2013-01-01 05:00','2013-01-01 06:00','2013-01-01 08:00','2013-01-01 10:00','2013-01-01 11:00',
      '2013-01-01 12:00','2013-01-01 13:00','2013-01-01 16:00','2013-01-01 17:00','2013-01-01 18:00',
      '2013-01-01 19:00','2013-01-01 20:00','2013-01-01 21:00','2013-01-01 23:00']
      humidity = ['0.62','0.64','0.62','0.63','0.63','0.64','0.63','0.64','0.48','0.46','0.45','0.44','0.46','0.47','0.48','0.49','0.51','0.52','0.52']
      timestamps = ['2013-01-01 07:00','2013-01-01 09:00','2013-01-01 14:00','2013-01-01 15:00','2013-01-01 22:00']


      And I am using following function to predict the humidity values using AR model in python.



      from statsmodels.tsa.arima_model import ARIMA
      def predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps):
      data_prediction = pd.DataFrame({'knownTimestamps': knownTimestamps,'humidity': humidity})
      print(data_prediction.head(10))
      history = [float(x) for x in data_prediction.humidity]
      predictions =
      test = timestamps
      for t in range(len(test)):
      model = ARIMA(history, order=(2,2,0))
      model_fit = model.fit(disp=0)
      output = model_fit.forecast()
      yhat = output[0]
      predictions.append(float(yhat))
      obs = test[t]
      history.append(float(obs))
      print(predictions)
      return predictions


      The model predict the same value of humidity for the values in time stamp list.



      res = predictMissingHumidity(startDate, endDate, knownTimestamps, humidity, timestamps) 
      print(res)


      output = [0.5287247355700563, 0.5287247355700563, 0.5287247355700563,
      0.5287247355700563, 0.5287247355700563]


      Can someone tell me where I am wrong?







      python time-series statsmodels arima






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 11:51









      desertnaut

      16.2k63566




      16.2k63566










      asked Nov 23 at 0:02









      CEXDSINGH

      133




      133
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You are not updating your history. Presumably, this is the site where most of your code comes from



          https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/



          There you can see how, on line 23, the history is updated and used for the forecast at the next step on the test set:



          history.append(obs)





          share|improve this answer





















          • It didnt worked. I added these two lines. obs = test[t]; history.append(obs)
            – CEXDSINGH
            Nov 23 at 0:17












          • your test variable contains timestamps while your history contains floats. You should fix that too.
            – Phoenix87
            Nov 23 at 0:22










          • casted it to float. history.append(float(obs)) Still doesn't work
            – CEXDSINGH
            Nov 23 at 0:37













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439260%2fhow-do-i-correctly-predict-the-humidity-values%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You are not updating your history. Presumably, this is the site where most of your code comes from



          https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/



          There you can see how, on line 23, the history is updated and used for the forecast at the next step on the test set:



          history.append(obs)





          share|improve this answer





















          • It didnt worked. I added these two lines. obs = test[t]; history.append(obs)
            – CEXDSINGH
            Nov 23 at 0:17












          • your test variable contains timestamps while your history contains floats. You should fix that too.
            – Phoenix87
            Nov 23 at 0:22










          • casted it to float. history.append(float(obs)) Still doesn't work
            – CEXDSINGH
            Nov 23 at 0:37


















          0














          You are not updating your history. Presumably, this is the site where most of your code comes from



          https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/



          There you can see how, on line 23, the history is updated and used for the forecast at the next step on the test set:



          history.append(obs)





          share|improve this answer





















          • It didnt worked. I added these two lines. obs = test[t]; history.append(obs)
            – CEXDSINGH
            Nov 23 at 0:17












          • your test variable contains timestamps while your history contains floats. You should fix that too.
            – Phoenix87
            Nov 23 at 0:22










          • casted it to float. history.append(float(obs)) Still doesn't work
            – CEXDSINGH
            Nov 23 at 0:37
















          0












          0








          0






          You are not updating your history. Presumably, this is the site where most of your code comes from



          https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/



          There you can see how, on line 23, the history is updated and used for the forecast at the next step on the test set:



          history.append(obs)





          share|improve this answer












          You are not updating your history. Presumably, this is the site where most of your code comes from



          https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/



          There you can see how, on line 23, the history is updated and used for the forecast at the next step on the test set:



          history.append(obs)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 at 0:13









          Phoenix87

          242312




          242312












          • It didnt worked. I added these two lines. obs = test[t]; history.append(obs)
            – CEXDSINGH
            Nov 23 at 0:17












          • your test variable contains timestamps while your history contains floats. You should fix that too.
            – Phoenix87
            Nov 23 at 0:22










          • casted it to float. history.append(float(obs)) Still doesn't work
            – CEXDSINGH
            Nov 23 at 0:37




















          • It didnt worked. I added these two lines. obs = test[t]; history.append(obs)
            – CEXDSINGH
            Nov 23 at 0:17












          • your test variable contains timestamps while your history contains floats. You should fix that too.
            – Phoenix87
            Nov 23 at 0:22










          • casted it to float. history.append(float(obs)) Still doesn't work
            – CEXDSINGH
            Nov 23 at 0:37


















          It didnt worked. I added these two lines. obs = test[t]; history.append(obs)
          – CEXDSINGH
          Nov 23 at 0:17






          It didnt worked. I added these two lines. obs = test[t]; history.append(obs)
          – CEXDSINGH
          Nov 23 at 0:17














          your test variable contains timestamps while your history contains floats. You should fix that too.
          – Phoenix87
          Nov 23 at 0:22




          your test variable contains timestamps while your history contains floats. You should fix that too.
          – Phoenix87
          Nov 23 at 0:22












          casted it to float. history.append(float(obs)) Still doesn't work
          – CEXDSINGH
          Nov 23 at 0:37






          casted it to float. history.append(float(obs)) Still doesn't work
          – CEXDSINGH
          Nov 23 at 0:37




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439260%2fhow-do-i-correctly-predict-the-humidity-values%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo