This study has two primary objectives. Firstly, it enhances the reliability and transparency of machine-learning-based models for predicting future changes in environmental, social and governance (ESG) performance. Secondly, it explores the relationship between ex-ante expected changes in ESG and future stock returns. This study collects 3258 STOXX Europe 600 firm-year observations. In the ESG prediction phase, two machine learning algorithms (logistic regression and random forest) are utilised to develop ESG forecasting models. Hyperparameter optimisation and walk-forward validation techniques are employed to address issues of underestimation and information leakage. The machine-learning-based ESG forecasting models are evaluated using three metrics: accuracy, area under the curve (AUC) and area under the precision-recall curve (AUPR). Subsequently, this study investigates the relationship between ex-ante expected ESG changes and future stock returns using the predicted ESG changes. A positive correlation is found between ex-ante expected ESG changes and future stock returns. The supplementary tests also reveal that this positive relationship is highly and statistically significant among large firms and after the COVID-19 pandemic. Moreover, this study introduces a robust and transparent approach for constructing effective machine-learning-based ESG forecasting models using hyperparameter optimisation and walk-forward validation. Additionally, traditional regression analyses are modernised by incorporating machine-learning-predicted independent variables. Furthermore, the findings provide empirical support for stakeholder, agency and resource-based theories. Finally, practical insights are provided to facilitate ESG-focused investment portfolio decision making.