How many ships to I need hunting pirates to stop raids?

The total number of guns of the ships is used to find the efficiency at which they hunt the pirates. The trade power of pirates is reduced by hunt pirate efficiency. 0%, when no fleet is hunting pirates, up to 99%, if the total number of guns from the hunting fleet is greater than or equal twice the total number of guns from pirating fleet.

In addition, it is helpful to know that this is also effective at stopping other nations from raiding your coasts.

So ideally you need twice as many guns as enemy fleet.

I didn't played or modded EU4 for a long time, but from what I recall (and it's not on wiki) naval raiding efficiency goes along with pirating efficiency. AI shouldn't raid when privateer efficiency is over 90%, but I'm not 100% sure about that. As a player you can raid even at 99% privateer efficiency, it's just not worth it.

Source: https://eu4.paradoxwikis.com/Naval_warfare