This research aims to compare the performance of two types of recurrent neural network models, Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU), in forecasting gold prices based on historical closing price data. Historical gold price data from December 14, 2017, to March 14, 2024, was downloaded using the yfinance library. The data was normalized using MinMaxScaler and split into training and testing sets with an 80:20 ratio. LSTM and GRU models were constructed with two recurrent layers followed by a Dense layer for output. Both models were trained using the training data and evaluated using Mean Squared Error (MSE), Mean Absolute Error (MAE), and R-squared (R²) metrics. The experimental results indicate that the GRU model outperformed the LSTM model in predicting gold prices. GRU achieved an MSE of 337.70, MAE of 14.05, and R² of 0.933, whereas LSTM achieved an MSE of 808.98, MAE of 22.71, and R² of 0.839. Based on the model performance evaluation, it can be concluded that GRU consistently produced more accurate predictions closer to the actual values of gold prices compared to LSTM. This finding suggests that GRU may be a preferable choice in applications for forecasting gold prices using historical data.
Copyrights © 2024