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 __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