Observed since 20 Oct, 17:15 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Canonical Artificial Bee Colony (ABC) optimization with a scikit-learn compatible hyperparameter search
Canonical Artificial Bee Colony (ABC) optimization for Python, with a scikit-learn compatible hyperparameter search.
abcopt implements the Artificial Bee Colony algorithm of Derviş Karaboğa (2005) step for step as in the reference implementation published by the ABC research group at Erciyes University, and wraps it in ABCSearchCV, a drop-in alternative to GridSearchCV and RandomizedSearchCV.
A real CanonicalABCSolver run on the 2-D Rastrigin function (many local minima, one global minimum ★).
Employed bees move one dimension at a time, onlookers revisit the best sources, and a scout restarts an exhausted source at a random spot.
Numbers are failed-trial counters. Generated by docs/make_animation.py.
ABCSearchCV provides fit, predict, predict_proba, score, best_params_, best_estimator_ and a cv_results_ table in the same format as GridSearchCV.max_evals) and random_state for identical runs.numpy and scikit-learn.Contents: Installation · Quick start · How ABC works · Benchmark · API reference · Notes and limitations · Examples · Citation
pip install abcopt
Requires Python 3.9+, NumPy and scikit-learn.
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import HistGradientBoostingClassifier
from abcopt import ABCSearchCV
X, y = load_breast_cancer(return_X_y=True)
param_space = {
"learning_rate": {"type": "float", "range": (0.01, 0.3), "log": True},
"max_iter": {"type": "int", "range": (50, 300)},
"max_leaf_nodes": {"type": "int", "range": (8, 64)},
"l2_regularization": {"type": "float", "range": (1e-6, 1.0), "log": True},
}
search = ABCSearchCV(
HistGradientBoostingClassifier(random_state=0),
param_space,
cv=5,
scoring="accuracy",
max_evals=60, # candidates evaluated by ABC
random_state=0,
)
search.fit(X, y)
print(search.best_score_, search.best_params_)
search.predict(X[:5]) # best_estimator_, refit on all data
Any scikit-learn compatible estimator works, including XGBoost and LightGBM.
import numpy as np
from abcopt import CanonicalABCSolver
def rastrigin(x):
return 10 * len(x) + np.sum(x**2 - 10 * np.cos(2 * np.pi * x))
solver = CanonicalABCSolver(rastrigin, n_params=5, lb=[-5.12] * 5, ub=[5.12] * 5,
max_evals=20_000, random_state=0)
best_x, best_f, history = solver.solve()
import pandas as pd
import matplotlib.pyplot as plt
results = pd.DataFrame(search.cv_results_) # one row per unique configuration
results.sort_values("rank_test_score").head()
evals, best = zip(*search.history_) # best CV score after each ABC cycle
plt.plot(evals, best); plt.xlabel("candidates evaluated"); plt.ylabel("best CV score")
ABC models the foraging behaviour of a honey bee colony. Each food source is a candidate solution and its nectar amount is the solution's fitness. Three kinds of bees share the work:
| Phase | What happens | Why |
|---|---|---|
| Employed bees | Each source changes one random dimension relative to a random other source, v_ij = x_ij + φ·(x_ij − x_kj), φ ∈ [−1, 1], and keeps the better of old and new. | Local search around every source |
| Onlooker bees | Sources are visited in turn; source i gets an extra try with probability p_i = 0.9 · fit_i / max(fit) + 0.1, until pop_size tries have been made. | More effort on promising regions |
| Scout bee | Once per cycle, the source with the most failed tries is replaced by a random one if its counter has reached limit. | Escapes local minima |
Fitness is derived from cost as 1 / (1 + f) for f ≥ 0 and 1 + |f| otherwise. The best solution found so far is always kept.
abcopt was compared with Random Search and Optuna TPE under identical evaluation budgets (notebook).
Black-box functions (D = 10, mean over 10 seeds, lower is better):
| Function | ABC @ 1k | TPE @ 1k | ABC @ 10k | TPE @ 2k | Random @ 10k |
|---|---|---|---|---|---|
| Sphere | 1.5 | 0.27 | 4e-11 | 0.22 | 12.3 |
| Rosenbrock | 1.3e3 | 88.5 | 0.51 | 114 | 1.1e4 |
| Rastrigin | 29.9 | 59.7 | 0.09 | 47.3 | 71.2 |
| Ackley | 12.8 | 5.58 | 0.0003 | 5.8 | 16.7 |

When to use which: TPE for very small budgets of expensive evaluations (for example deep-learning tuning); ABC when evaluations are cheap enough to afford thousands, when the landscape is rugged, or when you want a dependency-light scikit-learn drop-in.
CanonicalABCSolverCanonicalABCSolver(objective_func, n_params, lb, ub,
pop_size=20, max_evals=1000, limit=None, random_state=None)
| Parameter | Description |
|---|---|
objective_func | Callable taking a 1-D np.ndarray and returning a scalar cost to minimize. NaN is treated as the worst cost. |
n_params | Number of dimensions |
lb, ub | Lower and upper bound of each dimension |
pop_size | Number of food sources (SN), equal to the number of employed and of onlooker bees. The colony size in the reference code is 2 × pop_size. |
max_evals | Budget of objective evaluations |
limit | A source is abandoned once its failed-trial counter reaches limit. Default: pop_size × n_params. |
random_state | Seed or np.random.Generator |
solve() returns (best_params, best_cost, history), where history lists (evaluations_used, best_cost_so_far) after initialization and after every cycle.
ABCSearchCVABCSearchCV(estimator, param_space, cv=3, scoring="accuracy", pop_size=20, max_evals=200,
limit=None, random_state=None, n_jobs=None, error_score=np.nan,
refit=True, cache=True, verbose=False)
Search space (param_space), one entry per hyperparameter:
| Kind | Specification |
|---|---|
| Continuous | {"type": "float", "range": (0.01, 0.3)} |
| Continuous, log scale | {"type": "float", "range": (1e-4, 1e-1), "log": True} |
| Integer (both ends inclusive) | {"type": "int", "range": (2, 12)} |
| Categorical | {"type": "categorical", "choices": ["gini", "entropy"]} |
Parameters
| Parameter | Description |
|---|---|
cv, scoring, n_jobs, refit | As in GridSearchCV. Higher scores are better; use neg_* scorers for errors. |
pop_size, max_evals, limit, random_state | Passed to CanonicalABCSolver. max_evals counts every candidate ABC proposes. |
error_score | Score for candidates that fail to fit (a RuntimeWarning is issued); "raise" stops the search. |
cache | Reuse the score of a configuration ABC has already evaluated instead of cross-validating it again. Saves time; the search is unchanged. |
fit(X, y=None, groups=None, **fit_params): groups is passed to group-aware splitters and fit_params (for example sample_weight) to the estimator.
Attributes after fit
| Attribute | Content |
|---|---|
best_params_, best_score_, best_index_ | Best configuration, its mean CV score and its row in cv_results_ |
best_estimator_, refit_time_ | Best configuration refit on all data (refit=True) |
cv_results_ | One row per unique configuration, in GridSearchCV format |
results_ | Every candidate in proposal order with params, score and cached |
history_ | (evaluations_used, best_score_so_far) after each cycle |
n_evals_, n_unique_evals_, n_splits_ | Candidates evaluated, distinct configurations (cross-validation runs), CV folds |
Methods: predict, predict_proba, predict_log_proba, decision_function, transform, score and classes_, whenever the underlying estimator supports them.
ABCSearchCV, cached repeats still count towards max_evals.n_jobs inside each cross-validation.CanonicalABCSolver minimizes; to maximize, return the negative value.| Example | Content |
|---|---|
| Benchmark | ABC vs Random Search vs Optuna TPE on test functions and two tuning tasks |
| Federated learning on MedMNIST | ABC tunes FedAvg's learning rate and momentum on non-IID PathMNIST (5 clients, Dirichlet α = 0.5); test accuracy rises from 78.05% to 85.28%. Run with abcopt 0.1. |
| Animation | Records every phase of a solver run and renders the GIF above |
git clone https://github.com/yusufkorkmazyigit/abc-optimizer-lib.git
cd abc-optimizer-lib
pip install -e ".[test]"
pytest
The test suite includes the reference-equivalence test (tests/test_reference_equivalence.py) and runs on Python 3.9, 3.11 and 3.12 for every push. Release notes are in CHANGELOG.md. Issues and pull requests are welcome.
If abcopt helps your work, please cite the original algorithm and this software:
@techreport{karaboga2005abc,
author = {Karaboğa, Derviş},
title = {An Idea Based on Honey Bee Swarm for Numerical Optimization},
institution = {Erciyes University, Engineering Faculty, Computer Engineering Department},
number = {TR06},
year = {2005}
}
@software{korkmazyigit_abcopt,
author = {Korkmazyiğit, Yusuf},
title = {abcopt: Canonical Artificial Bee Colony optimization for Python},
url = {https://github.com/yusufkorkmazyigit/abc-optimizer-lib},
version = {0.2.2},
year = {2026}
}
MIT. See LICENSE. The reference port used in the tests is MIT licensed by its authors.
Developed by Yusuf Korkmazyiğit, Computer Engineering, Erciyes University.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.2 | 13 Oct 2026 | 4 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 17:15 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:5d8cac896217d2a220f4612ab8aa5009cb4bcd5797d27691fde5de8aa6e3c924