def __training(self, extractor: AppearanceExtractor) -> Classifier: """ Execute the training phase of the Appearance Layer. Arguments: extractor (AppearanceExtractor): The extractor which delivers the training data. Returns: A classifier which classifies players as either Mol or non-Mol based on how often they appear. """ train_input, train_output = extractor.get_train_data() classifier = NaiveKDEClassifier(cdf_cutoff = self.__cdf_cutoff) classifier.train(train_input, train_output) return classifier
def __training( self, extractor: AppearanceExtractor ) -> Tuple[gaussian_kde, gaussian_kde]: """ Execute the training phase of the Appearance Layer. Arguments: extractor (AppearanceExtractor): The extractor which delivers the training data. Returns: The kernel density estimator for respectively the Mol data and non-Mol data. """ train_input, train_output = extractor.get_train_data() non_mol_input = np.array( [ti[0] for ti, to in zip(train_input, train_output) if to == 0.0]) mol_input = np.array( [ti[0] for ti, to in zip(train_input, train_output) if to == 1.0]) non_mol_kde = self.kernel_density_estimation(non_mol_input) mol_kde = self.kernel_density_estimation(mol_input) return non_mol_kde, mol_kde
from Layers.Appearance.AppearanceExtractor import AppearanceExtractor from scipy.stats import norm import matplotlib.pyplot as plt import numpy as np TEST_SEASONS = {13, 14, 15, 16, 17, 18, 19, 20} extractor = AppearanceExtractor(0, 0, TEST_SEASONS, 1, 1, 0.0) train_input, train_output = extractor.get_train_data() non_mol = [ data[0] for data, label in zip(train_input, train_output) if label == 0.0 ] mol = [ data[0] for data, label in zip(train_input, train_output) if label == 1.0 ] plt.figure(figsize=(12, 3)) plt.xlabel("Relative Appearance") plt.ylabel("Is 'mol'") plt.yticks(np.linspace(0.0, 1.0, 11)) plt.gcf().subplots_adjust(bottom=0.15) mol_norm = norm.fit(mol) X = np.linspace(-1.5, 1.0, 500) mol_Y = [norm.pdf(x, loc=mol_norm[0], scale=mol_norm[1]) for x in X] plt.plot(X, mol_Y, color='r') non_mol_norm = norm.fit(non_mol) non_mol_Y = [ norm.pdf(x, loc=non_mol_norm[0], scale=non_mol_norm[1]) for x in X ]
from Layers.Appearance.AppearanceExtractor import AppearanceExtractor import matplotlib.pyplot as plt import numpy as np TEST_SEASONS = {13, 14, 15, 16, 17, 18, 19, 20, 21} AUGMENTATION_CUTS = 1 AUGMENTATION_MIN_CUTS_ON = 1 OUTLIER_CUTOFF = 0.00 extractor = AppearanceExtractor(0, 0, TEST_SEASONS, AUGMENTATION_CUTS, AUGMENTATION_MIN_CUTS_ON) train_input, _ = extractor.get_train_data() train_input = np.squeeze(np.exp(train_input) - AppearanceExtractor.SMALL_LOG_ADDITION, axis=1) plt.hist(train_input, bins=10, edgecolor='black') plt.xlabel("Absolute Appearance") plt.ylabel("#Occurrences") plt.show()