Reconstructing the Galactic merger history with machine learning