def __prediction(self, extractor: AppearanceExtractor, classifier: Classifier, predict_season: int) -> \ Dict[Player, MultiLayerResult]: """ Execute the prediction phase of the Appearance Layer. Arguments: extractor (AppearanceExtractor): The extractor which delivers the prediction data. classifier (Classifier): A classifier which classifies players as either Mol or non-Mol based on how often they appear. predict_season (int): For which season we make the prediction. Returns: A dictionary with as key the players that participated in the prediction season and as value a MultiLayerResult which contains the predictions. """ all_predictions = dict() predict_data = extractor.get_predict_data() if not predict_data: return EmptyMultiLayer().predict(predict_season, 0, set()) for player in get_players_in_season(predict_season): if player in predict_data: predictions = [] for data in predict_data[player]: predictions.append(classifier.predict_proba([data])) all_predictions[player] = MultiLayerResult(np.array(predictions), False) else: all_predictions[player] = MultiLayerResult(np.array([]), True) return all_predictions
def predict(self, predict_season: int, latest_episode: int, train_seasons: Set[int]) -> Dict[Player, np.array]: train_seasons = {season for season in train_seasons if season >= self.__first_season} max_episode = self.__latest_available_episode(predict_season, latest_episode) if max_episode == 0 or predict_season < self.__first_season: return EmptyMultiLayer().predict(predict_season, latest_episode, train_seasons) extractor = AppearanceExtractor(predict_season, max_episode, train_seasons, self.__aug_num_cuts, self.__aug_min_cuts_on) classifier = self.__training(extractor) return self.__prediction(extractor, classifier, predict_season)
def predict(self, predict_season: int, latest_episode: int, train_seasons: Set[int]) -> Dict[Player, MultiLayerResult]: available_seasons = MONEY_DATA.keys() train_seasons = train_seasons.intersection(available_seasons) if predict_season not in available_seasons: return EmptyMultiLayer().predict(predict_season, latest_episode, train_seasons) extractor = MoneyExtractor(predict_season, latest_episode, train_seasons, self.__pca_explain, self.__spline_clusters, self.__num_other_money_quantiles, self.__random_generator) classifier = self.__training(extractor) predict_data = extractor.get_predict_data() if not predict_data: return EmptyMultiLayer().predict(predict_season, latest_episode, train_seasons) return self.__predict(predict_season, latest_episode, predict_data, classifier)
def predict(self, predict_season: int, latest_episode: int, train_seasons: Set[int]) -> Dict[Player, MultiLayerResult]: available_seasons = EXAM_DATA.keys() train_seasons = train_seasons.intersection(available_seasons) if predict_season not in available_seasons: return EmptyMultiLayer().predict(predict_season, latest_episode, train_seasons) extractor = ExamDropExtractor(predict_season, latest_episode, train_seasons, self.__anova_f_significance, self.__pca_explain, self.__max_splits) classifier = self.__training(extractor) predict_data = extractor.get_predict_data() if not predict_data: alive_players = EXAM_DATA[predict_season].get_alive_players( latest_episode) return EmptyMultiLayer(alive_players).predict( predict_season, latest_episode, train_seasons) return self.__predict(predict_season, latest_episode, predict_data, classifier)
def predict(self, predict_season: int, latest_episode: int, train_seasons: Set[int]) -> Dict[Player, MultiLayerResult]: available_seasons = EXAM_DATA.keys() train_seasons = train_seasons.intersection(available_seasons) if predict_season not in available_seasons: return EmptyMultiLayer().predict(predict_season, latest_episode, train_seasons) extractor = ExamDropExtractor(predict_season, latest_episode, train_seasons, self.__min_cluster_size, self.__spline_curves, self.__random_generator) in_classifier, out_classifier = self.__training(extractor) predict_data = extractor.get_predict_data() if not predict_data: alive_players = EXAM_DATA[predict_season].get_alive_players( latest_episode) return EmptyMultiLayer(alive_players).predict( predict_season, latest_episode, train_seasons) return self.__predict(predict_season, latest_episode, predict_data, in_classifier, out_classifier)
def __prediction(self, extractor: AppearanceExtractor, non_mol_kde: gaussian_kde, mol_kde: gaussian_kde, predict_season: int) -> Dict[Player, MultiLayerResult]: """ Execute the prediction phase of the Appearance Layer. Arguments: extractor (AppearanceExtractor): The extractor which delivers the prediction data. non_mol_kde (gaussian_kde): The Kernel Density Estimator for non-Mol appearance values. mol_kde (gaussian_kde): The Kernel Density Estimator for Mol appearance values. predict_season (int): For which season we make the prediction. Returns: A dictionary with as key the players that participated in the prediction season and as value a MultiLayerResult which contains the predictions. """ all_predictions = dict() predict_data = extractor.get_predict_data() if not predict_data: return EmptyMultiLayer().predict(predict_season, 0, set()) min_value = self.get_boundary(non_mol_kde, mol_kde, len(predict_data), self.__cdf_cutoff / 2, self.MIN_VALUE, self.MAX_VALUE) max_value = self.get_boundary(non_mol_kde, mol_kde, len(predict_data), 1 - self.__cdf_cutoff / 2, self.MIN_VALUE, self.MAX_VALUE) for player in get_players_in_season(predict_season): if player in predict_data: predictions = [] for data in predict_data[player]: data = min(max(data, min_value), max_value) non_mol_likelihood = non_mol_kde.pdf(data)[0] * ( len(predict_data) - 1) / len(predict_data) mol_likelihood = mol_kde.pdf(data)[0] / len(predict_data) likelihood = mol_likelihood / (non_mol_likelihood + mol_likelihood) predictions.append(likelihood) all_predictions[player] = MultiLayerResult( np.array(predictions), False) else: all_predictions[player] = MultiLayerResult(np.array([]), True) return all_predictions