Hi Quasimodem,
For once as jasper1979 says is partly correct: The original cause of an attack is for most parts related to your defense value. If you put 20 turrents into a shed without any door, your settlement will be attacked less frequently.
As far as I know, there is no "zero" chance.
There are two "modes" of an attack: one you re partifipating in and two those attacks you do not participate. I am not completely sure how the chances of a success are determined if you are not participating (I had times were a perfectly defended settlement were overrun while I was not around).
About fences: They are not entirely for show. You have to know where enemies spawn. The very best example is Somerville Place. I had the whole place fortified and two times super mutants seemed to spawn right next to the central house.
In this case, no fortification helps whatsoever.
If you are present when a attack starts (e.g. Sanctuary), enemies will spawn outside of the perimeter. In those cases it helps to have a light fortification.
After my forth or so play-through (each time at least until level 40) I do not advise to really build a wall around your settlements. While it looks awesome, you will soon lack material (which you need to purchase after scraping every tree).
Of course how you fortify is a bit dependent of your play-style. I tend to setup watchtowers within "sight" to each other (e.g. in Sanctuary I fill out the gapes in the hedges with Watch posts).
As I learned some weeks ago, if you setup sirens (Resources -> Misc), these are operated by nearby settlers in case of an attack (including switching them off afterwards).
One final hints regarding turrets: While AI seems not very strong in FO4, attackers will primarily shot down generators. If your whole base consists of electrified turrets you will sometimes lack defenses if generators are "just covering the needs".