无法绘制MAPE和MSE的训练和测试值吗?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法绘制MAPE和MSE的训练和测试值吗?相关的知识,希望对你有一定的参考价值。
我正在编写可预测风速的代码。起初,我使用print(history.history.keys())>] >>来打印损失,val_loss,mape和val_mean_absolute_percentage_error值,但是,它仅显示dict_keys(['loss', 'mape'])。然后,由于它没有val_loss和val_mean_absolute_percentage_error值,因此会显示KeyError:‘val_mean_absolute_percentage_error’
您能帮我吗?
这是我的代码:
from __future__ import print_function from sklearn.metrics import mean_absolute_error import math import numpy as np import matplotlib.pyplot as plt from pandas import read_csv from keras.models import Sequential from keras.layers import Dense, LSTM from sklearn.preprocessing import MinMaxScaler from sklearn.metrics import mean_squared_error # convert an array of values into a dataset matrix def create_dataset(dataset, look_back=1): dataX, dataY = [], [] for i in range(len(dataset)-look_back-1): a = dataset[i:(i+look_back), 0] dataX.append(a) dataY.append(dataset[i + look_back, 0]) return np.array(dataX), np.array(dataY) # fix random seed for reproducibility np.random.seed(7) # load the dataset dataframe = read_csv(‘OND_Q4.csv’, usecols=[7], engine=’python’, header=3) dataset = dataframe.values print(dataframe.head) dataset = dataset.astype(‘float32′) # normalize the dataset scaler = MinMaxScaler(feature_range=(0, 1)) dataset = scaler.fit_transform(dataset) # split into train and test sets train_size = int(len(dataset) * 0.7) # Use 70% of data to train test_size = len(dataset) – train_size train, test = dataset[0:train_size,:], dataset[train_size:len(dataset),:] # reshape into X=t and Y=t+1 look_back = 1 trainX, trainY = create_dataset(train, look_back) testX, testY = create_dataset(test, look_back) # reshape input to be [samples, time steps, features] trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1])) testX = np.reshape(testX, (testX.shape[0], 1, testX.shape[1])) # create and fit the LSTM network model = Sequential() model.add(LSTM(4, input_shape=(1, look_back))) model.add(Dense(1)) #compile model model.compile(loss=’mean_squared_error’, optimizer=’adam’,metrics=[‘mape’]) history=model.fit(trainX, trainY, epochs=5, batch_size=1, verbose=2) # list all data in history print(history.history.keys()) train_MAPE = history.history[‘mape’] valid_MAPE = history.history[‘val_mean_absolute_percentage_error’] train_MSE = history.history[‘loss’] valid_MSE = history.history[‘val_loss’]
谢谢
我正在编写可预测风速的代码。起初,我使用print(history.history.keys())来打印损失,val_loss,mape和val_mean_absolute_percentage_error值,但是,它仅...
您需要在model.fit()
中定义一个验证集
您可以用validation_split=0.2
(0到1之间的浮点数进行操作。要用作验证数据的训练数据的分数。)
以上是关于无法绘制MAPE和MSE的训练和测试值吗?的主要内容,如果未能解决你的问题,请参考以下文章
深度学习-回归问题的评估指标:MAE, MAPE, MSE, RMSE, R2_Score
回归任务中的评价指标之MSE,RMSE,MAE,R-Squared,MAPE
我应该使用训练数据集的函数来处理训练数据集和测试数据集的缺失值吗
matlab BP神经网络中,最后算出的MSE值应该为多少?