Volume 10,Issue 7
Accurate real-time electricity price forecasting is of critical importance for market participants seeking to optimize energy procurement, dispatch scheduling, and arbitrage strategies in liberalized electricity markets. However, existing forecasting approaches suffer from several key limitations: (1) conventional statistical models fail to capture the complex nonlinear interactions among generation mix, load demand, and temporal variables that collectively drive price dynamics; (2) single-model approaches lack robustness and are sensitive to overfitting, limiting their generalizability across diverse market conditions; (3) the interpretability of black-box prediction models remains insufficient, hindering the practical deployment of data-driven forecasting systems in operational decision-making. To address these challenges, this study proposes a comprehensive machine learning framework based on six tree-based ensemble models for hourly electricity price prediction in the Spanish electricity market. The proposed framework introduces three key contributions: (1) a systematic feature engineering pipeline incorporating lagged price variables, rolling statistics, and calendar-based temporal encodings; (2) a rigorous comparative evaluation of Decision Tree, Random Forest, Extra Trees, Gradient Boosting, XGBoost, and LightGBM under identical experimental conditions; (3) a SHAP-based interpretability analysis that quantifies feature contributions and interaction effects at both global and local levels. Experimental results on the ENTSO-E Spanish market dataset demonstrate that XGBoost achieves the best overall predictive performance, with an R² of 0.9660 and MAE of 1.5631 €/MWh.