def test_grid_search(self): # Test that the best estimator contains the right value for foo_param clf = MockClassifier() grid_search = ATGridSearchCV(clf, {'foo_param': [1, 2, 3]}, verbose=3, webserver_url=self.live_server_url) # make sure it selects the smallest parameter in case of ties old_stdout = sys.stdout sys.stdout = StringIO() wait(grid_search.fit(X, y)) sys.stdout = old_stdout self.assertIn(grid_search.best_estimator_.foo_param, [2, 3]) _mock_sort = partial(_sort_grid_scores, param='foo_param') for idx, tup in enumerate( sorted(grid_search.grid_scores_, key=cmp_to_key(_mock_sort))): self.assertEqual(tup[0], {'foo_param': idx + 1}, '%d%s' % (idx, tup)) # Smoke test the score etc: grid_search.score(X, y) grid_search.predict_proba(X) grid_search.decision_function(X) grid_search.transform(X) # Test exception handling on scoring grid_search.scoring = 'sklearn' self.assertRaises(ValueError, grid_search.fit, X, y)
def test_transform_inverse_transform_round_trip(self): clf = MockClassifier() grid_search = ATGridSearchCV(clf, {'foo_param': [1, 2, 3]}, verbose=3, webserver_url=self.live_server_url) wait(grid_search.fit(X, y)) X_round_trip = grid_search.inverse_transform(grid_search.transform(X)) assert_array_equal(X, X_round_trip)