Moved classifier training to its own function.