As noted it was more than just numbers and specifically in both cases had to do with lack of proper planning, etc. And unlike Vietnam the US military initially had a single goal of winning a straight up fight with the nominal "military" in Iraq and Afghanistan but failed to follow through. Again...