The Gaia-ESO Survey: Chemical evolution of Mg and Al in the Milky Way with machine learning