When walking, the movements are gentle, and the changes of acceleration and angular velocity tend to be gentle. Data collected within the range set by the system will be recognized as "walking". Similarly, when you walk fast, the acceleration of angular velocity will increase, and it will be recognized as "running" in a certain range.
That's why when you shake your phone regularly, it will recognize "you are exercising" and then record the steps.