def rating_prediction_switch(self, dataset, dataset_switch, model_manager, force): from graphlab.data_structures.sframe import SFrame from graphlab.data_structures.sarray import SArray import os for folder in dataset.folders: rating_prediction_file = self._get_rating_prediction_file(dataset_switch, folder) class_prediction_file = self._get_class_prediction_file(dataset_switch, folder) if os.path.exists(rating_prediction_file) and not force: print "Model " + self.id + " in " + dataset_switch.id + " " + folder.id + " already tested." continue cf_predictions = model_manager.get_predictions(dataset, folder) if self.id == 'best': test_sframe = folder.test_sframe target = test_sframe.select_column(key = 'rating') rating_predictions = map(lambda t, *p: self._get_best_prediction(t, *p), target, *cf_predictions) rating_array = SArray(rating_predictions) rating_array.save(filename = rating_prediction_file) else: sf = SFrame.read_csv(class_prediction_file, header = True, quote_char = '"', column_type_hints = [int, str]) switch_predictions = sf.select_column(key = 'x') index_switch_predictions = model_manager.get_index_model(switch_predictions) rating_predictions = map(lambda t, *p: self._get_switch_prediction(t, *p), index_switch_predictions, *cf_predictions) rating_array = SArray(rating_predictions) rating_array.save(filename = rating_prediction_file)