微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

寻找提高 Keras 模型准确率的方法和经验

如何解决寻找提高 Keras 模型准确率的方法和经验

我是一名电气工程师,我正在寻找一种解决方案来计算永磁同步电机的直流电流。因此,我决定使用 Keras 等检查 ANN 解决方案。长话短说,我将向您展示一些测得的 signals 的屏幕截图。

前 5 个信号是测量信号。最后一个是直流电流,我将对其进行估算。这里的值是在电流钳的帮助下记录的。好的,我开始用 Python 构建模型并尝试了一些我认为会提高模型准确性的方法。但毕竟,我没有从模型中得到那么好的结果,我希望我可能选择了错误的参数,或者不是一个理想的模型。

这是我的代码

import numpy as np
from keras.layers import Dense,LSTM
from keras.models import Sequential
from keras.callbacks import EarlyStopping
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score
from matplotlib import pyplot as plt
import seaborn as sns

# Import input (x) and output (y) data,and asign these to df1 and df1
df = pd.read_csv('train_data.csv')
df = df[['rpm','iq','uq','udc','idc']]
X = df[df.columns[:-1]]
Y = df.idc

plt.figure()
sns.heatmap(df.corr(),annot=True)
plt.show()

# Split the data into input (x) training and testing data,and ouput (y) training and testing data,# with training data being 80% of the data,and testing data being the remaining 20% of the data
X_train,X_test,y_train,y_test = train_test_split(X,Y,test_size=0.2)#,shuffle=True)

# Scale both training and testing input data
X_train = preprocessing.maxabs_scale(X_train)
X_test = preprocessing.maxabs_scale(X_test)

model = Sequential()
model.add(Dense(4,input_shape=(4,)))
model.add(Dense(4,)))
model.add(Dense(1,)))

model.compile(optimizer="adam",loss="msle",metrics=['mean_squared_logarithmic_error','accuracy'])

# Pass several parameters to 'EarlyStopping' function and assign it to 'earlystopper'
earlystopper = EarlyStopping(monitor='val_loss',min_delta=0,patience=15,verbose=1,mode='auto')

model.summary()
history = model.fit(X_train,epochs = 2000,validation_split = 0.3,verbose = 2,callbacks = [earlystopper])

# Runs model (the one with the activation function,although this doesn't really matter as they perform the same) 
# with its current weights on the training and testing data
y_train_pred = model.predict(X_train)
y_test_pred = model.predict(X_test)

# Calculates and prints r2 score of training and testing data
print("The R2 score on the Train set is:\t{:0.3f}".format(r2_score(y_train,y_train_pred)))
print("The R2 score on the Test set is:\t{:0.3f}".format(r2_score(y_test,y_test_pred)))

df = pd.read_csv('test_two_data.csv')
df = df[['rpm','idc']]
X = df[df.columns[:-1]]
Y = df.idc
X_validate = preprocessing.maxabs_scale(X)

y_pred = model.predict(X_validate)

plt.plot(Y)
plt.plot(y_pred)
plt.show()

(weight_0,bias_0) = model.layers[0].get_weights()
(weight_1,bias_1) = model.layers[1].get_weights()

一个限制是我不能使用 LSTM 层或其他复杂的算法,因为我稍后需要在电机应用程序的微控制器中实现经过训练的模型。

我想你可以为我找到一些词来让我的模型在准确性上更好一点。

最后是一张图,我向您展示了更差的预测性能。橙色是预测值,蓝色是测量值 current

training dataset 就是这个。

可以找到各个值之间的相关性here。由于 id 和 ud 的值与 idc 没有关联,我决定删除它们。

解决方法

  1. 在尝试提高模型的准确性时要记住的最重要的事情是始终标准化输入数据,这基本上意味着将实值数值属性重新缩放到范围 0 和1. 我无法理解您向模型提供训练数据的方式。你能解释一下吗。更好地理解和识别更高准确度的范围。

  2. 现在,如果我们谈论参数,我建议您为参数添加调优算法,以获得每个参数的优化值。 包含可以提供更好的特征提取的隐藏层总是一个不错的选择。

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