我们使用Keras序列模型来创建和运行预测天气变量的模型然而,模型的预测结果与输入值存在相同的问题,我们减少了隐藏的人数,降低了学习率,并应用了提前停止。但问题还没解决我不知道怎么解决
import numpy as np
import tensorflow as tf
import pandas as pd
from keras.models import Sequential
from keras.layers import Embedding, LSTM, GRU, Dense, Dropout
from keras.models import load_model
from keras.optimizers import Adam
from keras.preprocessing import sequence
from keras.callbacks import EarlyStopping
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
df1 = pd.DataFrame({'T' : df['기온(°C)'],
'WS' : df['풍속(m/s)'],
'RH' : df['습도(%)'],
'P' : df['해면기압(hPa)'],
'VS' : df['시정(10m)'],
'TD' : df['이슬점온도(°C)']})
wfm.add(Dense(12, input_dim = 6, activation = 'tanh'))
wfm.add(Dense(12, activation = 'tanh'))
wfm.add(Dense(6, activation = 'relu'))
wfm.add(Dense(6, activation = 'relu'))
wfm.add(Dense(6, activation = 'relu'))
wfm.add(Dense(6, activation = 'relu'))
wfm.add(Dense(6, activation = 'relu'))
wfm.add(Dense(6, activation = 'relu'))
wfm.compile(loss = 'mean_squared_logarithmic_error', optimizer = tf.keras.optimizers.Adam(learning_rate = 0.001))
wfm.fit(x_train, y_train, epochs = 100, batch_size = 10,
validation_data = (x_val, y_val))
def predict(data):
result = wfm.predict(data)
result = scaler.inverse_transform(data)
print("1시간 뒤 기상변수 예측")
print("기온 : ", result[0,0], "degreeC")
print("풍속 : ", result[0,1], "m/s")
print("습도 : ", result[0,2], "%")
print("기압 : ", result[0,3], "hPa")
print("시정 : ", result[0,4]*10, "m")
print("이슬점 온도 : ", result[0,5], "degreeC")
n = pd.DataFrame({'T' : [35.2],
'WS' : [0.8],
'RH' : [48],
'P' : [1004.3],
'VS' : [1963],
'TD' : [22.5]})
now = (n - df1.min())/(df1.max() - df1.min())
predict(now)
字符串
这就是结果
1/1 [==============================] - 0s 129ms/step
1시간 뒤 기상변수 예측
기온 : 35.2 degreeC
풍속 : 0.8 m/s
습도 : 48.0 %
기압 : 1004.3 hPa
시정 : 19629.999999999996 m
이슬점 온도 : 22.50000000000001 degreeC
型
使用MinMaxScaler将df 1标准化为scikit-learn
1条答案
按热度按时间lx0bsm1f1#
如果Sequential模型的预测值与输入值相同,则表明模型没有从数据中正确学习,预测没有意义。这种行为可能有几个原因。