If someone approaches your vehicle in a threatening manner, pull away. When using public transportation - travel with a friend or buddy if possible. When waiting be alert and avoid isolated areas whenever possible. Keep a low profile, ride near the front, let others know that you know they are there, smile. If you are bothered advise the driver or attendant, change seats if necessary.
Mechanical devices can give a false sense of security.
They should be used in addition to common sense. Whistles, noisemakers, anything that attracts attention to your situation are usually enough. The subject does not want to attract attention to what they are doing. You need to know what pepper spray can do before you use it. Think before you act, use your common sense.