According to groundhog.org, for 125 years Phil "comes out of his hole after a long winter sleep to look for his shadow. If he sees it, he regards it as an omen of six more weeks of bad weather and returns to his hole. If the day is cloudy and, hence, shadowless, he takes it as a sign of spring and stays above ground."
Perhaps it's an inexact science.
According to LiveScience, Groundhog Day originated "in the Old World with an ancient celebration of the midpoint between the winter solstice and spring Equinox." As of 2011, biology professor Stam Zervanos told the news organization that Punxsutawney Phil had about a 39 percent accuracy of predicting the weather.
Take a look at Phil's prediction from the last 10 years: