我想在数字序列列表上训练我的模型。我不希望它能提供高精度,但至少会达到25%。我使用Sequential()
方法开发了一个小模型,但最终它给了我0.0xy的输出。这真的很糟糕。我什至尝试在Neural Network
上使用Azure ML workspace
建立模型,但没有成功。
我有一个文件,其中包含200,000个txt格式的随机数。我已将其转换为具有150个值的csv,其中150th是可预测的值。尽管起初我只用2000
来处理50 size
大块。
我已经搜索了这个主题,发现了很多与此有关的问题,但是找不到完美的解决方案。
这是我的构建模型代码
def build_model():
model = Sequential()
layers = [1, 50, 100, 1]
model.add(LSTM(
layers[1],
input_shape=(None, layers[0]),
return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(
layers[2],
return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(
layers[3]))
model.add(Activation("linear"))
start = time.time()
model.compile(loss="mse", optimizer="rmsprop")
print("Compilation Time : ", time.time() - start)
return model
及其运行代码
def run_network(model=None, data=None):
global_start_time = time.time()
epochs = 1
ratio = 1.0
sequence_length = 50
path_to_dataset = open('InputNumber6_demo.txt','r+',encoding = "utf-8-sig")
if data is None:
print("Loading data...")
X_train, y_train, X_test, y_test = dpc.data_power_consumption(
path_to_dataset, sequence_length, ratio)
else:
X_train, y_train, X_test, y_test = data
print('\nData Loaded. Compiling...\n')
if model is None:
model = bm.build_model()
try:
model.fit(
X_train, y_train,
batch_size=512, nb_epoch=epochs, validation_split=0.05)
predicted = model.predict(X_test)
predicted = np.reshape(predicted, (predicted.size,))
except KeyboardInterrupt:
print('Training duration (s) : ', time.time() - global_start_time)
return model, y_test, 0
try:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(y_test[:100])
plt.plot(predicted[:100])
plt.show()
except Exception as e:
print(str(e))
print('Training duration (s) : ', time.time() - global_start_time)
print("y_test :" ,y_test)
print("predicted : ", predicted)
return model, y_test, predicted
我在以下部分得到输出:
[7.896141 7.8818192 7.8702197 7.8729057 7.887852 7.8909307 7.880986
7.8800116 7.8971305 7.8821206 7.872368 7.8670635 7.859713 7.866045
7.895461 7.884264 7.89429 7.891604 7.9120145 7.9183216 7.9248204
7.9104924 7.9158993 7.897169 7.916412 7.9040785 7.920195 7.9250274
7.933447 7.93625 7.8920164 7.9262824 7.9311395 7.936692 7.943627
7.9117746 7.921586 7.9338064 7.9352465 7.913917 7.9132504 7.9155235
7.892686 7.8813086 7.904029 7.902289 7.886468 7.88697 7.920277
7.9392414 7.935853 7.9325123 7.9430776 7.9166965 7.8978596]
请告诉我这种情况下的问题,或者是否有任何算法可以创建模型