Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Now i have predictions on test sets and now With the model trained, how do I use RF to predict future values? My goal is to predict next 3 days temperature values but I'm kind of stuck on how to do that.


What I have tried:

Python
import pandas as pd
import numpy as np
import datetime as dt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestRegressor
from sklearn import metrics
dataset = pd.read_csv(r"C:\Users\saadh\Desktop\The Weather Forecast(RFR)\Rawalpindi.csv",index_col='date_time',parse_dates=True)
#print(dataset.head)
X = dataset[['maxtempC', 'WindChillC', 'FeelsLikeC', 'HeatIndexC', 'mintempC', 'uvIndex', 'pressure']].values
Y = dataset['tempC'].values
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.20, random_state=0)
regressor = RandomForestRegressor(n_estimators=30, random_state=0)
regressor.fit(X_train, Y_train)
#test model on test data 
predictData = regressor.predict(X_test)
print("test outputs")
print(predictData[:10].astype(int))
print(Y_test[:10].astype(int))
print('Mean Absolute Error:', metrics.mean_absolute_error(Y_test, predictData))
print('Mean Squared Error:', metrics.mean_squared_error(Y_test, predictData))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(Y_test, predictData)))

test outputs
[16 16 40 45 36 19 20 41 24 36]
[16 16 40 45 36 19 20 41 24 36]
Mean Absolute Error: 0.022748815165876773
Mean Squared Error: 0.013322801474460246
Root Mean Squared Error: 0.11542444054211502
Posted
Updated 30-Dec-20 22:34pm
Comments
[no name] 30-Dec-20 15:40pm    
You have "test output"; wasn't that the point? It makes picks; nothing more.
Muhammad Saad Hassan 30-Dec-20 15:52pm    
yeah but i don't want test outputs i want future predictions for n days let say 3 days in future.
How i will do that ?
Richard MacCutchan 31-Dec-20 4:01am    
Buy yourself a crystal ball. Or get a feed from the local weather stations.
Mr Bobcat 1-Jan-21 13:08pm    
Weather prediction doesn't work like that buddy. Let's say you want to predict the weather for the 15th of June. Then you would have to look at the previous year's temperature records for that specific day or maybe decades-old records i.e. more data more accurate the predictions would be. Then take the average of all the temperature values and that's how you can predict the weather.

1 solution

Assuming that you want to predict temperature for today (2020-12-31) based on the values from last 3 years of december 31.:
2017-12-31  5
2018-12-31  3
2018-12-31  4

The value of predicted temperature might be equal to:
=SUM(LINEST({5;3;4},{2017-12-31;2018-12-31;2019-12-31}))

See Excel LINEST function[^]

There's few other ways to calculate "predicted value". For further details, please read this: Prediction - Wikipedia[^]
 
Share this answer
 
Comments
Muhammad Saad Hassan 31-Dec-20 9:09am    
can't get your point

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900