If you are travelling by yourself and you know how to get home, using public transport is much safer than walking. However, you should still use your common sense if you don't want become a victim.
Make sure that you catch a bus at a stop that has other people waiting there. It might mean queuing for longer than you'd like, but it's less scary than waiting by yourself.
Once you get on the bus, try to sit downstairs as it's easier to alert the driver if something does happen that makes you uncomfortable. If you can, sit in a seat next to the aisle so you can move seats easily if you want to.