Stellar masses of giant clumps in CANDELS and simulated galaxies using machine learning