Implemented the train script

Fixed a number of bugs and added functions to compute the result class
and the sum of squared errors.