hope you are fine i am basically new in machine learning and i need help from you guys. I want to predict next 3 days temperature values hourly how can i do that ? Can anyone help....??
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\Rawalpindi.csv")
#print(dataset.head)
X = dataset[['moon_illumination','sunHour','date_time','mintempC','uvIndex','DewPointC','humidity','cloudcover','pressure','windspeedKmph']].values
Y = dataset['maxtempC'].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=300, random_state=0)
regressor.fit(X_train, Y_train)
predictData = regressor.predict(X_test)
#df = pd.DataFrame({'Actual': Y_test, 'Predicted': predictData})
#res = df.head()
#print(df)
print(predictData.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)))
Output: [43 40 41 41 40 40 39]
Mean Absolute Error: 0.5561904761904758
Mean Squared Error: 1.0668126984126995
Root Mean Squared Error: 1.0328662538841606
You need to get the features for the values you want to predict and feed them to your trained model.
Like in your code you do a prediction on the test dataset X_test
, which is a part of the features stored in X
.
So to do a prediction for other data you need to get the features similar to this line in your code
X = dataset[['mintempC','moon_illumination','date_time','uvIndex','sunHour','DewPointC','pressure','humidity','cloudcover']].values
and then do the prediction like this
predictData = regressor.predict(X)