A learning algorithm with emergent scaling behavior for classifying phase transitions