Machine learning prediction of critical transition and system collapse