Training and validating the model