Anticipating synchronization with machine learning