def test_retrain(self, dataset_one, dataset_two): X_train_set, y_train_set, X_test, y_test, stats = MainTransformer.get_training_and_test_set(dataset_one, 'Pollutant', 'Uncertainty', size=0.6, normalize=True) gp = GaussianProcesses() gp.train(X_train_set, y_train_set, stats=stats) instances = gp.stats['n_instances_trained'] model_stats = gp.stats['dataset_stats'] assert instances == X_train_set.shape[0] assert model_stats == stats X_train_set, y_train_set, X_test, y_test, stats = MainTransformer.get_training_and_test_set(dataset_two, 'Pollutant', 'Uncertainty', size=0.5, normalize=True) gp.train(X_train_set, y_train_set, stats) assert instances + X_train_set.shape[0] == gp.stats['n_instances_trained'] assert model_stats != gp.stats['dataset_stats'] != stats
def test_save_wrong(self, config): X_train_set, y_train_set, X_test, y_test, stats = MainTransformer.get_training_and_test_set(dataset, 'Pollutant', 'Uncertainty', size=0.5, normalize=True) gp = GaussianProcesses() gp.train(X_train_set, y_train_set, stats=stats) result, msg = gp.save_model(config) assert not result and isinstance(msg, str)
def test_eval(self, error_func): X_train_set, y_train_set, X_test, y_test, stats = MainTransformer.get_training_and_test_set(dataset, 'Pollutant', 'Uncertainty', size=0.5, normalize=True) gp = GaussianProcesses() gp.train(X_train_set, y_train_set, stats=stats) result, predictions, y_test_set = gp.eval(X_test, y_test, error_func=error_func) predictions_size = len(predictions) assert predictions_size == len(X_test)
def test_save(self, config): X_train_set, y_train_set, X_test, y_test, stats = MainTransformer.get_training_and_test_set(dataset, 'Pollutant', 'Uncertainty', size=0.5, normalize=True) gp = GaussianProcesses() gp.train(X_train_set, y_train_set, stats=stats) result, msg = gp.save_model(config) global full_gp full_gp = gp assert result and msg is None
def test_train_and_test_various_datasets(self, given_dataset): X_train_set, y_train_set, X_test, y_test, stats = MainTransformer.get_training_and_test_set(given_dataset, 'Pollutant', 'Uncertainty', size=0.5, normalize=True) gp = GaussianProcesses() gp.train(X_train_set, y_train_set, stats=stats) assert gp.stats['n_instances_trained'] == X_train_set.shape[0] assert gp.stats['dataset_stats'] == stats predictions = gp.predict(X_test, uncertainty=True) assert len(predictions) == X_test.shape[0]
def test_update_stats(self): full_gp = GaussianProcesses() X_train_set, y_train_set, _, _, stats = MainTransformer.get_training_and_test_set(dataset, 'Pollutant', 'Uncertainty', size=0.85, normalize=True) full_gp.train(X_train_set, y_train_set, stats=stats) instances = full_gp.stats['n_instances_trained'] dataset_stats = full_gp.stats['dataset_stats'] assert X_train_set.shape[0] == instances assert stats == dataset_stats X_train_set, y_train_set, _, _, stats = MainTransformer.get_training_and_test_set(dataset, 'Pollutant', 'Uncertainty', size=0.5, normalize=True) full_gp.train(X_train_set, y_train_set, stats) assert X_train_set.shape[0] + instances == full_gp.stats['n_instances_trained'] assert len(full_gp.stats['dataset_stats'].keys()) == len(stats.keys()) == len(dataset_stats.keys()) missing_data = X_train_set.drop(axis=1, columns='Temperature', inplace=False, errors='ignore') with pytest.raises(WrongNumberOfFeatures): full_gp.train(missing_data, y_train_set, stats)
def test_train_and_test(self, uncertainty): X_train_set, y_train_set, X_test, y_test, stats = MainTransformer.get_training_and_test_set(dataset_gp, 'Pollutant', 'Uncertainty', size=0.5, normalize=True) gp = GaussianProcesses() gp.train(X_train_set, y_train_set, stats=stats) assert gp.stats['n_instances_trained'] == X_train_set.shape[0] assert gp.stats['dataset_stats'] == stats predictions = gp.predict(X_test, uncertainty=uncertainty) assert len(predictions) == X_test.shape[0] if uncertainty: values_without_uncertainty = list(filter(lambda x: len(x) != 2, predictions)) assert len(values_without_uncertainty) == 0 if not isinstance(uncertainty, bool): assert len(list(filter(lambda x: not isinstance(x, tuple), predictions))) == X_test.shape[0]