我如何预测未来几天的温度值?
how can i predict future days' temperature values?
希望你们一切都好我基本上是机器学习的新手,我需要你们的帮助。我想每小时预测接下来 3 天的温度值,我该怎么做?谁能帮忙....?
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)))
输出:
[43 40 41 41 40 40 39]
平均绝对误差:0.5561904761904758
均方误差:1.0668126984126995
均方根误差:1.0328662538841606
您需要获取要预测的值的特征,并将它们提供给经过训练的模型。
就像在您的代码中一样,您对测试数据集 X_test
进行预测,这是存储在 X
.
中的特征的一部分
因此,要对其他数据进行预测,您需要在代码中获得类似于此行的特征
X = dataset[['mintempC','moon_illumination','date_time','uvIndex','sunHour','DewPointC','pressure','humidity','cloudcover']].values
然后像这样进行预测
predictData = regressor.predict(X)
希望你们一切都好我基本上是机器学习的新手,我需要你们的帮助。我想每小时预测接下来 3 天的温度值,我该怎么做?谁能帮忙....?
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)))
输出: [43 40 41 41 40 40 39]
平均绝对误差:0.5561904761904758
均方误差:1.0668126984126995
均方根误差:1.0328662538841606
您需要获取要预测的值的特征,并将它们提供给经过训练的模型。
就像在您的代码中一样,您对测试数据集 X_test
进行预测,这是存储在 X
.
因此,要对其他数据进行预测,您需要在代码中获得类似于此行的特征
X = dataset[['mintempC','moon_illumination','date_time','uvIndex','sunHour','DewPointC','pressure','humidity','cloudcover']].values
然后像这样进行预测
predictData = regressor.predict(X)