def test_random_seed(X_y_binary): X, y = X_y_binary automl = AutoMLSearch(X_train=X, y_train=y, problem_type='binary', objective=Precision(), max_iterations=5, random_seed=0, n_jobs=1) automl.search() automl_1 = AutoMLSearch(X_train=X, y_train=y, problem_type='binary', objective=Precision(), max_iterations=5, random_seed=0, n_jobs=1) automl_1.search() assert automl.rankings.equals(automl_1.rankings)
def test_callback(X_y_binary): X, y = X_y_binary counts = { "start_iteration_callback": 0, "add_result_callback": 0, } def start_iteration_callback(pipeline_class, parameters, automl_obj, counts=counts): counts["start_iteration_callback"] += 1 def add_result_callback(results, trained_pipeline, automl_obj, counts=counts): counts["add_result_callback"] += 1 max_iterations = 3 automl = AutoMLSearch(X_train=X, y_train=y, problem_type='binary', objective=Precision(), max_iterations=max_iterations, start_iteration_callback=start_iteration_callback, add_result_callback=add_result_callback, n_jobs=1) automl.search() assert counts["start_iteration_callback"] == len( get_estimators('binary')) + 1 assert counts["add_result_callback"] == max_iterations
def test_init_objective(X_y_binary): X, y = X_y_binary automl = AutoMLSearch(X_train=X, y_train=y, problem_type='binary', objective=Precision(), max_iterations=1) assert isinstance(automl.objective, Precision) automl = AutoMLSearch(X_train=X, y_train=y, problem_type='binary', objective='Precision', max_iterations=1) assert isinstance(automl.objective, Precision)
def test_precision_binary(): obj = Precision() assert obj.score(np.array([1, 1, 1, 1, 1, 1]), np.array([0, 0, 0, 1, 1, 1])) == pytest.approx(1.0, EPS) assert obj.score(np.array([0, 0, 0, 1, 1, 1]), np.array([1, 1, 1, 1, 1, 1])) == pytest.approx(0.5, EPS) assert obj.score(np.array([0, 0, 0, 0, 0, 0]), np.array([1, 1, 1, 1, 1, 1])) == pytest.approx(0.0, EPS) assert obj.score(np.array([0, 0, 0, 0, 0, 0]), np.array([0, 0, 0, 0, 0, 0])) == pytest.approx(0.0, EPS)