def check_adaboost_predict(base_estimator, algorithm, expected_score): train_fs, test_fs = make_sparse_data() # train an AdaBoostClassifier on the training data and evalute on the # testing data learner = Learner('AdaBoostClassifier', model_kwargs={'base_estimator': base_estimator, 'algorithm': algorithm}) learner.train(train_fs, grid_search=False) test_score = learner.evaluate(test_fs)[1] assert_almost_equal(test_score, expected_score)
def check_sparse_predict(learner_name, expected_score, use_feature_hashing=False): train_fs, test_fs = make_sparse_data( use_feature_hashing=use_feature_hashing) # train the given classifier on the training # data and evalute on the testing data learner = Learner(learner_name) learner.train(train_fs, grid_search=False) test_score = learner.evaluate(test_fs)[1] assert_almost_equal(test_score, expected_score)
def check_sparse_predict_sampler(use_feature_hashing=False): train_fs, test_fs = make_sparse_data( use_feature_hashing=use_feature_hashing) if use_feature_hashing: sampler = 'RBFSampler' sampler_parameters = {"gamma": 1.0, "n_components": 50} else: sampler = 'Nystroem' sampler_parameters = {"gamma": 1.0, "n_components": 50, "kernel": 'rbf'} learner = Learner('LogisticRegression', sampler=sampler, sampler_kwargs=sampler_parameters) learner.train(train_fs, grid_search=False) test_score = learner.evaluate(test_fs)[1] expected_score = 0.48 if use_feature_hashing else 0.45 assert_almost_equal(test_score, expected_score)
def check_sparse_predict_sampler(use_feature_hashing=False): train_fs, test_fs = make_sparse_data( use_feature_hashing=use_feature_hashing) if use_feature_hashing: sampler = 'RBFSampler' sampler_parameters = {"gamma": 1.0, "n_components": 50} else: sampler = 'Nystroem' sampler_parameters = { "gamma": 1.0, "n_components": 50, "kernel": 'rbf' } learner = Learner('LogisticRegression', sampler=sampler, sampler_kwargs=sampler_parameters) learner.train(train_fs, grid_search=False) test_score = learner.evaluate(test_fs)[1] expected_score = 0.48 if use_feature_hashing else 0.45 assert_almost_equal(test_score, expected_score)