为什么 LSTM 预测的值很低?

如何解决为什么 LSTM 预测的值很低?

我需要预测具有 N 个虚拟机的数据中心的工作负载。数据的结构如下:

id,date,hour,dayofweek,cpu,ram,ram_tot,users,id_vm

5fff03b99b56dba65a873e2a,2020-12-14,00:00,1,2,820,8000,10,1

5fff03ba9b56dba65a873e2c,2458,16000,2

数据包括:id、日期、小时、星期几 (1-7)、VM 的 CPU 数量、使用的 RAM、总 RAM、连接到相关 VM 的用户数、VM id(1 或 2)。 这是在熊猫数据框中导入的。在数据框中,我构建了一个名为 peak 的列,如果存在虚拟机的工作负载(% ram 使用率非常高,> 80%),则其值为 1,否则为 0。 我构建了一个时间序列数据集并将其标准化。我构建了一个 LSTM 网络来预测是否会出现工作负载峰值(预测变量为峰值),具有训练和测试阶段 我在验证阶段得到了非常糟糕的结果:预测值与实际值相比非常低。 我想如果网络在预测峰值时运行良好,则相关值接近 1。

这是我的代码:

#read data from a mongo db and passed in a pandas dataframe
df = DataFrame(list_cur)
 
# calc for %mem used
df['pmem'] = (df['ram']/df['ram_tot'])*100
 
conditions = [(df['pmem'] <= 80),(df['pmem'] > 80)] #80
values = [0,1]
df['peak'] = np.select(conditions,values)
 
df['datetime'] = df['data'] + ' ' + df['ora']
 
# extract hour and minutes to build 2 new columns
df[['hh','mm']] = df.ora.str.split(":",expand=True,)
 
# dataset with 6 features and 1 label
# oevery row of the dataset = 1 observation
dataset = df[['hh','mm','dayofweek','users','pmem','id_app','peak']]
 
# normalization of the dataset
sc = MinMaxScaler(feature_range = (0,1))
dfn = sc.fit_transform(dataset) 
 
# build temporal series
x = []
y = []
 
n_steps = 192
for i in range(len(dfn)):
    # find the end of this pattern
    end_ix = i + n_steps
    # check if we are beyond the sequence
    if end_ix > len(dfn)-1:
        break
    # gather input and output parts of the pattern
    seq_x,seq_y = dfn[i:end_ix,0:5],dfn[end_ix,6]
    x.append(seq_x)
    y.append(seq_y)
 
# splitting dataset in train and test
X_train,X_test,y_train,y_test = train_test_split(x,y,test_size=0.33,random_state=42)
 
# convert in arrays
X_train = np.asarray(X_train,dtype=np.float32)
X_test = np.asarray(X_test,dtype=np.float32)
y_train = np.asarray(y_train,dtype=np.float32)
y_test = np.asarray(y_test,dtype=np.float32)
 
# LSTM neural network model
model = Sequential()
#Adding the first LSTM layer and some Dropout regularisation
model.add(LSTM(units = 6,return_sequences = True,input_shape = (X_train.shape[1],X_train.shape[2])))
model.add(Dropout(0.2))
# Adding a second LSTM layer and some Dropout regularisation
model.add(LSTM(units = 32,return_sequences = True))
model.add(Dropout(0.2))
# Adding a third LSTM layer and some Dropout regularisation
model.add(LSTM(units = 64,return_sequences = True))
model.add(Dropout(0.2))
# Adding a fourth LSTM layer and some Dropout regularisation
model.add(LSTM(units = 32))
model.add(Dropout(0.2))
# Adding the output layer
model.add(Dense(units = 1))
 
model.summary()
 
# Compiling the LSTM
model.compile(loss = 'categorical_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
 
# Fitting the LSTM to the Training set
history = model.fit(X_train,epochs = 5,batch_size = 32,validation_data=(X_test,y_test))
model.evaluate(X_test,y_test,verbose=1,return_dict=True)
print("test loss,test acc:",history)
 
print("Generate predictions for all samples")
yhat = model.predict(X_test,verbose=1)
plot.figure(figsize=(20,10))
 
y1 = np.array(y_test)
y2 = np.array(yhat[:,0])
 
plt.plot(y1,label = "Test",marker="o",linewidth=0)
plt.plot(y2,label = "Previsto",marker="x",)
 
plt.xlabel('x - axis')
# Set the y axis label of the current axis.
plt.ylabel('y - axis')
# Set a title of the current axes.
plt.title('Two or more lines on same plot with suitable legends ')
# show a legend on the plot
plt.legend()
# Display a figure.
plt.show()

这是我的结果。

LSTM Forecast vs real

有错误吗?

解决方法

我不确定,但可以尝试对输出进行逆变换 minmaxscaler。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-