code for training and prediction