Install & Compatibility
Where this runs
tested against v2.7.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 18.0s · import 4.280s · 427MB
445MB installed
● package 445MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MAB
✓ from mabwiser.mab import MAB
✗ from mabwiser import MAB
MAB is not exposed at the package level; it's in the mab submodule.
LearningPolicy
✓ from mabwiser.mab import LearningPolicy
Commonly used to specify learning policies like LearningPolicy.EpsilonGreedy.
NeighborhoodPolicy
✓ from mabwiser.mab import NeighborhoodPolicy
Used for contextual bandits with nearest neighbor policies.
Minimal example: non-contextual epsilon-greedy bandit with partial_fit, and contextual bandit with Cluster neighborhood.
import numpy as np
from mabwiser.mab import MAB, LearningPolicy, NeighborhoodPolicy
# Non-contextual bandit
arms = ['arm1', 'arm2']
mab = MAB(arms, LearningPolicy.EpsilonGreedy(epsilon=0.1))
# Simulate fitting: use dummy rewards
for _ in range(100):
arm = mab.predict()
reward = np.random.binomial(1, 0.7 if arm == 'arm1' else 0.3)
mab.partial_fit(arm, reward)
# Contextual bandit with nearest neighbor
contexts = np.array([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])
mab_ctx = MAB(arms, LearningPolicy.EpsilonGreedy(epsilon=0.1), NeighborhoodPolicy.Cluster())
mab_ctx.fit(contexts, np.array(['arm1', 'arm2', 'arm1']), np.array([1, 0, 1]))
print(mab_ctx.predict(contexts[-1:]))
Errors
Common errors & fixes
AttributeError: module 'mabwiser' has no attribute 'MAB'
Importing MAB from the top-level package instead of the mab submodule.
fixUse: from mabwiser.mab import MAB
TypeError: 'LearningPolicy' object is not callable
Using LearningPolicy as a function with a string argument instead of using the enum attribute directly.
fixUse: LearningPolicy.EpsilonGreedy(epsilon=0.1)
ValueError: The truth value of an array with more than one element is ambiguous
Passing a full context matrix to predict() for a non-contextual bandit.
fixFor non-contextual, call predict() with no arguments or an empty array.
Upgrade
Version history
2.7.4latest on PyPI · released Aug 30, 2024
Audit
Dependencies
No dependency data recorded yet.