【发布时间】:2019-08-15 10:33:12
【问题描述】:
我的数据集包含 1000 个用户的 10 天数据。我正在为每个用户训练和测试数据,以获得更好的预测准确性。问题是第一个用户训练 100 个 epoch 需要 5 secs,而对于第 100 个用户,100 个 epoch 需要超过 five minutes。每个用户的训练时间都在增加。如何减少训练时间> 由于位置点是分类的,因此对位置点进行了一次热编码。
list = list_users[:100]
with open("accuracy_Lstm.csv","w") as f:
f.write('user,LSTM \n')
for user in list:
user_data = newdataframe[newdataframe.user==user]
encoded=encoding(user_data)
X_train = []
y_train = []
for i in range(1, len(encoded)-96):
X_train.append(encoded[i-1])
y_train.append(encoded[i])
X_train, y_train = np.array(X_train), np.array(y_train)
X_test = encoded[-192:-96,:]
X_true = encoded[-96:,:]
X_trainL=X_train.reshape(X_train.shape[0],1,X_train.shape[1])
time_steps = 1
#Lstm
model = Sequential()
model.add(LSTM(X_train.shape[1], input_shape=(time_steps,X_train.shape[1]), activation='relu'))
model.add(Dense(X_train.shape[1]))
model.compile(loss='mse', optimizer='adam')
model.fit(X_trainL, y_train, batch_size=96, epochs=100, verbose =1)
model.summary()
X_testL=X_test.reshape(X_test.shape[0],1,X_test.shape[1])
pedL =one_hot_decode(model.predict(X_testL))
true=one_hot_decode(X_true)
try:
accuracy = ((sum(x == y for x, y in zip(pedL, true)))/(len(pedL)))*100
except ZeroDivisionError:
accuracy = 0
f.write(' %d, %f \n'%(user, accuracy))
如何减少用户的培训时间?
【问题讨论】:
标签: python tensorflow machine-learning deep-learning lstm