How do i correctly predict the humidity values?
Sebastian Wright
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 predictionsThe 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?
1 Answer
You are not updating your history. Presumably, this is the site where most of your code comes from
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) 3