Beep your horn, that works most of the time.
Nope, not "most" anyways.
I spent a bit of playtime trying to see if there was any way to mitigate random killing, and tested a few methods. I used the invincibility glitch to get the most data in the shortest amount of time possible, since it wouldn't affect their initial reaction. I session hopped a number of times, and selected targets at random. The only similarity they all shared was being located in Los Santos.
Whether you just walk up to someone, or do a hand gesture, or put away your weapon, it doesn't matter. All of these were the same, which was being attacked well over 90% of the time.
There were two ways that actually did reduce this frequency, and one of them was honking your horn. When approaching people like that, I was still attacked over 70% of the time.
The last way reduced the frequency quite dramatically, though. All the way to 0%. This method was "communicate with them on the mic". Of course, it only works with people that actually have a mic and are willing to communicate, but if they do, it allows you to determine if they will shoot you or not before you even put yourself at risk.
And it seems to largely demotivate people from wanting to kill you in general (again, assuming there is communication taking place).