You need to learn and practice situational awareness, and some form of self-defence like martial arts or just techniques.
About fighting, it's always best to avoid it. Even as an experienced martial artist, you don't know if someone is carrying a weapon or has others backing them up.
This means that if you have to run away from danger, there is no shame in doing so. Run and file the police report.
But you must know how to fight and defend yourself, and know how to read a situation... to determine whether a fight is inevitable and what options you have, you might have to strike first if the fight is inevitable. Striking first in imminent danger counts as self-defence and is legal in most countries, as long as you do not use excessive force.