You are on page 1of 6

AI: Photovoltaic Power Forecasting Using LSTM Networks | ... https://medium.com/grid-solutions/ai-photovoltaic-power-for...

1 of 6 11/22/2021, 10:42 AM
AI: Photovoltaic Power Forecasting Using LSTM Networks | ... https://medium.com/grid-solutions/ai-photovoltaic-power-for...

2 of 6 11/22/2021, 10:42 AM
AI: Photovoltaic Power Forecasting Using LSTM Networks | ... https://medium.com/grid-solutions/ai-photovoltaic-power-for...

3 of 6 11/22/2021, 10:42 AM
AI: Photovoltaic Power Forecasting Using LSTM Networks | ... https://medium.com/grid-solutions/ai-photovoltaic-power-for...

// Reshape data into [samples, timesteps, features]


traint_len = len(data) - test_len

test_data = series[traint_len:]
train_data = series[:traint_len]

trainX = train_data[:, :-1] // features


trainY = train_data[:, -1] // predict parameter

trainX = trainX.reshape((trainX.shape[0], 1,
trainX.shape[1]))

testX = test_data[:, :-1] // features


testY = test_data[:, -1] // predict parameter

trainX = testX.reshape((trainX.shape[0], 1,
trainX.shape[1]))

from tensorflow.keras.layers import LSTM, Dense,


Dropout
from tensorflow.keras import Sequential

model = Sequential()
model.add(LSTM(128, activation=’relu’, input_shape=
(trainX.shape[1], trainX.shape[2]),

4 of 6 11/22/2021, 10:42 AM
AI: Photovoltaic Power Forecasting Using LSTM Networks | ... https://medium.com/grid-solutions/ai-photovoltaic-power-for...

return_sequences=True))
model.add(LSTM(32, activation=’relu’,
return_sequences=False))
model.add(Dense(1))
model.compile(optimizer=’adam’, loss=’mse’)
model.summary()

train_history = model.fit(trainX, trainY, epochs= 20,


validation_data=(testX, testY))

yhat = model.evaluate(testX, testY)

yhat = model.predict(testX)

5 of 6 11/22/2021, 10:42 AM
AI: Photovoltaic Power Forecasting Using LSTM Networks | ... https://medium.com/grid-solutions/ai-photovoltaic-power-for...

6 of 6 11/22/2021, 10:42 AM

You might also like