How many military units per city/population is recommended in Civilization IV?
Solution 1:
From my experience, 3 military is good enough for average defense, it allows you to hold out till you can reinforce.
But for your style of play, perhaps 5-10 would be better, you don't want to many as it causes slow down in tech etc..., but then you don't want to get crushed. You should have more on the outer cities and reinforce from your inner ones, I try to always have 3 minimum in all cities, but doesn't always work, then any bigger cities up it to 4-5.
If you notice your enemies normally attack you with massive stacks, the only way to counter those are with a large stack yourself. Have 1 large stack that walks between cities and does the attacking, then leave 3 units in all your cities for normal defense, remember if you suddenly get attacked at a choke point (hopefully you have one) you can always reinforce from your other cities, knocking them down to 1-2 stuff like that.
Solution 2:
Notes: I played mostly on Monarch, took occasional tries at Emperor with mixed results there. Also, the weaker your defenses the more likely the AI is to declare war, regardless of how good your relations are so good relations alone do not suffice.
That said, I tended to keep 2 of the most modern defensive units in each of my cities while accumulating old ones. Thus, if I founded a city when I had archers and now have riflemen, my city would have 2 archers, 2 longbowmen, and 2 riflemen. Beyond 6 units I would either upgrade or delete the oldest ones to lower my army costs. On a border with an AI I knew was likely to attack me I would increase this to 3 during peacetime. I rarely built walls. You can generally notice a large shift of units within the AI's territory prior to it declaring war on you. Use this time to pump more defensive units and possibly try to appease them or get them in a war with someone else. Once they actually declare war, you can upgrade units in the cities they are attacking for a quick defensive boost.
If you are having trouble during the war itself there are a few possibilities. One is you can try to get other AI to go to war with them. This will take much of the burden off of you and weaken two AI at once. Generally though, if you are having trouble with wars that means your production is simply too low. How many cities are you founding? 6 or 9 are generally ideal for peaceful strategies. Are you keeping up with improvements? You want every worked tile to be improved. 1-2 workers per city will usually do a good enough job for that. Are you practicing city specialization? Are you just sitting back and defending? The best defense is usually a good offense. Building some stacks with 1-2 defensive units, and lots of attacking units and siege weapons will make for nice "stacks of doom" to repel the invaders with.
For more details on balancing your army and your empire growth, see this article.