The jedi training had nothing to do with it.
It has everything to do with that. Anaking didn't turn bad because he was bad. He turned bad because the grown men around them told him to shut down his feelings to be a more appreciated member of society... and this repressed feeling were used at the time against him by a sith lord to manipulate him.. at a moment where his mother was being tortured.
The jedi way had EVERYTHING to do with that. That's the point of the story of Anakin.
Luke, on the other hand had little to no education. His was constantly shut down by hiw oncle and forced to stay in place. The one jedi advice he had were made by two old man explaining him just how great and peacefull the jedi were.. that "there was not try" and the guy found out later the greatest jedi became the worst person in the Universe.
So yeah.. Luke, like Anakin were not trained to be good and yet Luke managed to control his feeling quite well because he had times to learn his own way.
Everything Anakin did was for the Jedi Code. Anakin was a former slave, he wanted one thing : to be recognized. Becoming a master was his purpose. So while he tried to do everything his own way, his was attached more than anyone to the jedi code and the ideology behind it. But the jedi way was so flawed that Anakin saw in it a way to gain power and not to be better.
It's the flaws of the jedi ideology that allowed Anakin (a rebel by nature) to bend it the way he wanted.
So when Windu choosed to strike down Palpatine, it made him switch in a moment. The jedi way was now on the side of Palpatine and not on the side of the jedi.