Unveiling phase transitions with machine learning