我正在嘗試編寫一個(gè)RNN模型,該模型將預(yù)測(cè)整數(shù)序列中的下一個(gè)數(shù)字。模型損失在每個(gè)時(shí)期都會(huì)變小,但是預(yù)測(cè)永遠(yuǎn)不會(huì)變得非常準(zhǔn)確。我已經(jīng)嘗試了許多火車的大小和時(shí)期,但是我的預(yù)測(cè)值總是與期望值相差幾位數(shù)。您能否給我一些提示,以改善或我做錯(cuò)了什么?這是代碼:from keras.models import Sequentialfrom keras.layers import Dense, Dropout, LSTMfrom keras.callbacks import ModelCheckpointfrom keras.utils import np_utilsfrom keras import metricsimport numpy as nptraining_length = 10000rnn_size = 512hm_epochs = 30def generate_sequence(length=10): step = np.random.randint(0,50) first_element = np.random.randint(0,10) first_element = 0 l_ist = [(first_element + (step*i)) for i in range(length)] return l_isttraining_set = []for _ in range(training_length): training_set.append(generate_sequence(10))feature_set = [i[:-1] for i in training_set]label_set = [i[-1:] for i in training_set]X = np.reshape(feature_set,(training_length, 9, 1))y = np.array(label_set)model = Sequential()model.add(LSTM(rnn_size, input_shape = (X.shape[1], X.shape[2]), return_sequences = True))model.add(Dropout(0.2))model.add(LSTM(rnn_size))model.add(Dropout(0.2))model.add(Dense(y.shape[1], activation='linear'))model.compile(loss='mse', optimizer='rmsprop', metrics=['accuracy'])filepath="checkpoint_folder/weights-improvement.hdf5"checkpoint = ModelCheckpoint(filepath, monitor='loss', verbose=1, save_best_only=True, mode='min')callbacks_list = [checkpoint]model.fit(X,y,epochs=hm_epochs, callbacks=callbacks_list)效果:30個(gè)紀(jì)元后(虧損:66.39):1順序:[0,20,40,60,80,100,120,140,160]預(yù)期:[180] || 得到了:[181.86118]2順序:[0,11,22,33,44,55,66,77,88]預(yù)期:[99] || 得到了:[102.17369]3順序:[0,47,94,141,188,235,282,329,376]預(yù)計(jì):[423] || 得到了:[419.1763]4順序:[0,47,94,141,188,235,282,329,376]預(yù)期:[423] || 得到了:[419.1763]5序列:[0,4,8,12,16,20,24,28,32]預(yù)期:[36] || 得到了:[37.506496]6序列:[0,48,96,144,192,240,288,336,384]預(yù)期:[432] || 得到了:[425.0569]7順序:[0、28、56、84、112、140、168、196、224]預(yù)期:[252] || 得到了:[253.60233]8順序:[0、18、36、54、72、90、108、126、144]預(yù)期:[162] || 得到了:[163.538]9順序:[0,19,38,57,76,95,114,133,152]預(yù)期:[171] || 得到了:[173.77933]10序列:[0,1,2,3,4,5,6,7,8]預(yù)期:[9] || 得到了:[9.577981]...
2 回答

回首憶惘然
TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊
您是否嘗試了更長(zhǎng)的順序?不需要LSTM,因?yàn)橐蕾囆圆皇呛荛L(zhǎng)。您可以嘗試使用RNN的另一個(gè)變體。
添加回答
舉報(bào)
0/150
提交
取消