Are we talking like a direct attack, one on one with the zombie, or like a legion of zombies is attacking your house? OR how to survive in a zombie apocalypse in general?
One on one a shotgun would work best, they do the most damage, giving you a better chance at stopping them in their tracks. Make sure you have plenty of ammo as sometimes it is difficult to "kill" a zombie (and by "kill" I mean render unable to be of further danger to you). Hint: Aim for the head. Or the legs.
If a legion of zombies is attacking your house (and here it depends on the type of zombies, whether they are the stereotypical slow moving type, or the type that is capable of moving at fast, human-like speeds, such as in the movie "I am Legend") you have two options, stay and fend them off, or run the heck out of there.
I would recommend staying and fending off only if the following two facts are true: 1. Your house is sturdy and capable of surviving a good-sized zombie attack intact, and 2. The legion is a manageable size, say, less than 25 zombies. If the legion is greater than that, I would recommend the second option, getting out of there to a safer location. The best way to exit your own house, if you don't already have a "Zombie Attack Escape Tunnel" is to choose the exit with the smallest gathering of zombies, whether it be door, window, vent, or area of wall you can easily blow open with a few shotgun blasts (or other explosive means, if you have those kind of supplies), and exit after having every part of your body covered. You wouldn't want to be injured and infected would you? While exiting, use your shotgun (or other choice of weapon) to keep zombies at a safe distance, and head for the nearest reliably usable vehicle, one that can attain a good amount of speed is preferable (actually the most preferable would be an armored, "zombie-proof" truck or van).
Here is where the type of zombies is necessary to know. If they are slow-moving zombies, you may not need a vehicle, as you should be able to outrun them on foot (keep in mind though, you can't run forever, and vehicles are good for smashing through large numbers of zombies if necessary. Also vehicles are handy for getting to safe locations that may be a great distance away). If the zombies are capable of moving at greater speeds (especially if for some reason the zombie virus gives them "superhuman" speed, I know crazy right? but sometimes it happens) you will definitely need a vehicle, and I would strongly recommend a covered one at that (like a car instead of a motorcycle).
As soon as you get to a safe place (and by safe place I mean somewhere either 1. surrounded by water 2. deep in the mountains 3. underground or 4. a shelter that has previously been, or is capable of being, zombie-proofed) figure out more plans on surviving similar zombie attacks or/and inventing a cure to the zombie virus.
Now finally (I know, it's really long, but hey, zombies attacks are more complicated than most people think) on surviving a zombie attack in general, as in, you are aware of an imminent zombie apocalypse beforehand, MOVE YOUR FRICKIN' SELF (and loved ones if you have any) TO THE FURTHEST ISLAND AWAY FROM HUMAN LIFE. Spend your time zombie proofing the island (zombies usually do not travel on water as they usually don't have the brain capacity the think of it, and also because they have no need, as they don't believe there to be any food on the water, BUT the zombies could evolve to where they could be smart enough, and/or run out of food on land and search for it elsewhere, namely YOUR island) and finding a cure for the zombie virus, if you think one is possible.
So how was that, confident you could survive a zombie attack now?