Learning from the past: predicting critical transitions with machine learning trained on surrogates of historical data