Be Confident
Even if you are not confident in your abilities to protect yourself, act it. Confidence is the key to overcome anything. Confidence may also intimidate your opponient into surrendering. The best thing about confidence is by acting confident enough times, you may actually become confident.
Create Distraction
This works both ways, if you can distract your attacker, you may get a hit in or be able to escape. Another way distraction works is that attackers normally while looking for a victim look for weaknesses and disadvantages, therefore if the attacker notices your distracted or not paying attention he might attack. But if you watching and paying attention, he might not attack.
Be Aware
This is the final, most important step. Take a mental note of what is happening around you, the people, the area, whether or not anything suspicious is happing and whether there are any random acts of violence. Awareness is the core of avoiding an attack and the one that should be taken most seriously.