Modified R scripts and added methods to handle training and testing requests.