It is known for a fact that accidental magic often happens when a (young) witch or a wizard is really angry, really scared, or really confused. Not to mention in a state of a high stress which can involve all of those emotions.
And then something magical happens, usually something horrible, to the person or thing that is causing the emotions on the witch/wizard.
The books make a big deal about accidental magic, and how young children have little to no control over their magic and thus do a lot of accidental magic.
But obviously they're doing something about it, as the magical society is still mostly hidden but no one can learn magic control over-night and just wake up one morning and no longer have accidents.
Despite of the books making a big deal about the accidental magic, I don't think Rowling has ever given any official explanation as for how do witches and wizards work on the problem. Apart from there being a Squad in the Ministry of Magic for reversing accidental magic situations.
So what is it that an individual magical person can do to minimize their accidental magic outbursts?
My theory was sparked por a comment on an artigo I found on another site, in which someone viewed accidental magic as "instinct and primal need for magical children".
That sounded quite logical to me, generally for magical people though and not just children.
And so I thought maybe when a witch or a wizard recognizes that need, they can start brushing up their self-control of it while being angry, scared or confused. As in to start pushing the need down and instead focus on trying to reach a muggle way of dealing with the emotion and situation.
And then, when had enough practice and grown older, the person no longer needs to consciously try but the magic just won't manifest so easily anymore.
I also think the conscious recognision of it as a need, can help some children do the magic deliberately although they can't yet at such a young age, actually do any specific spells.
They can just choose not to control it even if they could, and instead see what happens.
Much like Voldemort as a child. (He of course didn't know it was magic, but according to his own words he knew there was something in him, and probably did recognize it as a need because he never really was taught normal ways to deal with things and was constantly unhappy.)
So, yeah. That's my theory which I will apply to my fanfiction universe and characters.