def test_ols(self): print('OLS tests of fit()...') algorithm = SemanticLearningMachine(100, MaxGenerationsCriterion(200), 3, 'optimized', 50, Mutation2()) X = get_input_variables(self.training).as_matrix() y = get_target_variable(self.training).as_matrix() algorithm.fit(X, y, RootMeanSquaredError, verbose=True) self.assertTrue(expr=algorithm.champion) print()
def test_edv(self): print('EDV tests of fit()...') algorithm = SemanticLearningMachine( 100, ErrorDeviationVariationCriterion(0.25), 3, 0.01, 50, Mutation2()) X = get_input_variables(self.training).as_matrix() y = get_target_variable(self.training).as_matrix() algorithm.fit(X, y, RootMeanSquaredError, verbose=True) self.assertTrue(expr=algorithm.champion) print()
def test_tie(self): print('TIE tests of fit()...') def time_seconds(): return default_timer() start_time = time_seconds() algorithm = SemanticLearningMachine(100, TrainingImprovementEffectivenessCriterion(0.25), 3, 0.01, 50, Mutation2(), RootMeanSquaredError, True) X = get_input_variables(self.training).values y = get_target_variable(self.training).values start_time = time_seconds() algorithm.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=algorithm.champion) print()
def test_ols(self): print('OLS tests of fit()...') def time_seconds(): return default_timer() start_time = time_seconds() algorithm = SemanticLearningMachine(100, MaxGenerationsCriterion(200), 3, 'optimized', 50, Mutation2(), RootMeanSquaredError, True) X = get_input_variables(self.training).values y = get_target_variable(self.training).values start_time = time_seconds() algorithm.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=algorithm.champion) print()
def test_slm_fls(self): print("testing fit() for SLM (FLS) ...") base_learner = SemanticLearningMachine(50, MaxGenerationsCriterion(100), 2, 1, 10, Mutation2()) ensemble_learner = EnsembleRandomIndependentWeighting(base_learner, 100, weight_range=1) X = get_input_variables(self.training).values y = get_target_variable(self.training).values def time_seconds(): return default_timer() start_time = time_seconds() ensemble_learner.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=ensemble_learner.learners) print()
def test_slm_ols_wo_edv(self): print("testing fit() for SLM (OLS) without EDV ...") base_learner = SemanticLearningMachine(50, MaxGenerationsCriterion(20), 2, 'optimized', 10, Mutation2()) ensemble_learner = EnsembleBoosting(base_learner, 100, meta_learner=median, learning_rate=1) X = get_input_variables(self.training).values y = get_target_variable(self.training).values def time_seconds(): return default_timer() start_time = time_seconds() ensemble_learner.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=ensemble_learner.learners) print()
def test_predict(self): print("testing predict()...") base_learner = SemanticLearningMachine(50, ErrorDeviationVariationCriterion(0.25), 2, 1, 10, Mutation2()) ensemble_learner = EnsembleRandomIndependentWeighting(base_learner, 100, weight_range=2) X = get_input_variables(self.training).values y = get_target_variable(self.training).values def time_seconds(): return default_timer() start_time = time_seconds() ensemble_learner.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) start_time = time_seconds() prediction = ensemble_learner.predict(get_input_variables(self.validation).values) print("time to predict algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=len(prediction) == len(get_target_variable(self.validation).values)) print()
def setUp(self): base_learner = SemanticLearningMachine(50, MaxGenerationsCriterion(10), 2, 'optimized', 10, Mutation2()) self.ensemble_learner = Ensemble(base_learner, 50) self.training, self.validation, self.testing = load_samples('c_diabetes', 0)