Machine-learning-based photometric redshifts for galaxies of the ESO Kilo-Degree Survey data release 2