Which would just bring up another question: Is an improvised weapon a melee weapon or a ranged weapon or neither?
An improvised weapon could be anything. It could be a ranged weapon used to make a melee attack, or a melee weapon, without the thrown property, used to make a ranged attack. It could also be an object not normally classified as a weapon when used to make any kind of attack. Its original identity isn't really important, only that it is being used in a way it was not designed for.
A warhammer is a melee weapon, and you can use it to make a melee weapon attack. If you use it for a ranged weapon attack, it is subject to the improvised weapon rules. These rules, like many in 5E, are guidelines for the DM to make a ruling because there are an infinite variety of objects that could be used in an attack, and the system needs to be flexible.
To make a ruling on a ranged attack using a war hammer, the first question is whether it resembles another weapon capable of making a ranged attack sufficiently for that weapon's stats to be used. For example, you could make the argument that the warhammer resembles a light hammer enough for someone's proficiency with light hammers to apply to the attack. Personally, I'd rule this is not the case due to the warhammer having the versatile property, indicating it has a handle of sufficient length to grip with two hands. In my opinion, this would preclude the weapon from having sufficient balance for a thrown attack. Likewise, a warhammer lacks the thrusting point of a spear or trident, the only weapons with both the thrown and versatile properties, and so could not be used in the manner of those weapons either.
Having ruled out the possibility that a warhammer resembles a weapon capable of a ranged attack, I would rule that the attacker's proficiency bonus does not apply and that the ability modifier for the attack is dexterity, due to the unwieldy nature of the object used and the simple fact that it's a ranged attack. The attack would deal an unmodified 1d4 bludgeoning damage because the weapon lacks the thrown property, although you could rule that an ability modifier applies if that seems reasonable, but I don't think I would.