Quantcast
Channel: Active questions tagged feed-forward+python+neural-network - Stack Overflow
Viewing all articles
Browse latest Browse all 25

Predict future points Feed forward neural networks

$
0
0

I was able to test it but i would like to add future 30 points and forecast the data - pls advise how to add them to get the future data points

enter image description here

import numpy as npimport matplotlib.pyplot as pltfrom pandas import read_csvimport mathfrom keras.models import Sequentialfrom keras.layers import Densefrom sklearn.preprocessing import MinMaxScalerfrom sklearn.metrics import mean_squared_error# normalize the datasetscaler = MinMaxScaler(feature_range=(0, 1)) dataset = scaler.fit_transform(dataset)# split into train and test setstrain_size = int(len(dataset) * 0.60)test_size = len(dataset) - train_sizetrain, test = dataset[0:train_size,:], dataset[train_size:len(dataset),:]def to_sequences(dataset, seq_size=1):    x = []    y = []    for i in range(len(dataset)-seq_size-1):        #print(i)        window = dataset[i:(i+seq_size), 0]        x.append(window)        y.append(dataset[i+seq_size, 0])    return np.array(x),np.array(y)seq_size = 35 trainX, trainY = to_sequences(train, seq_size)testX, testY = to_sequences(test, seq_size)model = Sequential()model.add(Dense(64, input_dim=seq_size, activation='relu')) #12model.add(Dense(32, activation='relu'))  #8model.add(Dense(1))model.compile(loss='mean_squared_error', optimizer='adam', metrics = ['acc'])print(model.summary())model.fit(trainX, trainY, validation_data=(testX, testY),          verbose=2, epochs=100)# make predictionstrainPredict = model.predict(trainX)testPredict = model.predict(testX)# Estimate model performance#SInce we used minmaxscaler we can now use scaler.inverse_transform#to invert the transformation.trainPredict = scaler.inverse_transform(trainPredict)trainY_inverse = scaler.inverse_transform([trainY])testPredict = scaler.inverse_transform(testPredict)testY_inverse = scaler.inverse_transform([testY])# calculate root mean squared errortrainScore = math.sqrt(mean_squared_error(trainY_inverse[0], trainPredict[:,0]))print('Train Score: %.2f RMSE' % (trainScore))testScore = math.sqrt(mean_squared_error(testY_inverse[0], testPredict[:,0]))print('Test Score: %.2f RMSE' % (testScore))trainPredictPlot = np.empty_like(dataset)trainPredictPlot[:, :] = np.nantrainPredictPlot[seq_size:len(trainPredict)+seq_size, :] = trainPredicttestPredictPlot = np.empty_like(dataset)testPredictPlot[:, :] = np.nantestPredictPlot[len(trainPredict)+(seq_size*2)+1:len(dataset)-1, :] = testPredict# plot baseline and predictionsplt.plot(scaler.inverse_transform(dataset))plt.plot(trainPredictPlot)plt.plot(testPredictPlot)plt.show()

I was able to test it but i would like to add future 30 points and forecast the data - pls advise how to add them to get the future data pointsI was able to test it but i would like to add future 30 points and forecast the data - pls advise how to add them to get the future data points


Viewing all articles
Browse latest Browse all 25

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>