{"id":24001,"library":"mabwiser","title":"MABWiser","description":"MABWiser is a Python library for parallelizable, contextual multi-armed bandits. It supports a wide range of bandit learning policies (e.g., epsilon-greedy, Thompson Sampling, LinUCB) and neighborhood policies for contextual bandits. Version 2.7.4 is the latest release, with active development.","status":"active","version":"2.7.4","language":"python","source_language":"en","source_url":"https://github.com/fidelity/mabwiser","tags":["multi-armed bandits","contextual bandits","reinforcement learning","A/B testing","machine learning"],"install":[{"cmd":"pip install mabwiser","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"MAB is not exposed at the package level; it's in the mab submodule.","wrong":"from mabwiser import MAB","symbol":"MAB","correct":"from mabwiser.mab import MAB"},{"note":"Commonly used to specify learning policies like LearningPolicy.EpsilonGreedy.","symbol":"LearningPolicy","correct":"from mabwiser.mab import LearningPolicy"},{"note":"Used for contextual bandits with nearest neighbor policies.","symbol":"NeighborhoodPolicy","correct":"from mabwiser.mab import NeighborhoodPolicy"}],"quickstart":{"code":"import numpy as np\nfrom mabwiser.mab import MAB, LearningPolicy, NeighborhoodPolicy\n\n# Non-contextual bandit\narms = ['arm1', 'arm2']\nmab = MAB(arms, LearningPolicy.EpsilonGreedy(epsilon=0.1))\n# Simulate fitting: use dummy rewards\nfor _ in range(100):\n    arm = mab.predict()\n    reward = np.random.binomial(1, 0.7 if arm == 'arm1' else 0.3)\n    mab.partial_fit(arm, reward)\n\n# Contextual bandit with nearest neighbor\ncontexts = np.array([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])\nmab_ctx = MAB(arms, LearningPolicy.EpsilonGreedy(epsilon=0.1), NeighborhoodPolicy.Cluster())\nmab_ctx.fit(contexts, np.array(['arm1', 'arm2', 'arm1']), np.array([1, 0, 1]))\nprint(mab_ctx.predict(contexts[-1:]))","lang":"python","description":"Minimal example: non-contextual epsilon-greedy bandit with partial_fit, and contextual bandit with Cluster neighborhood."},"warnings":[{"fix":"Replace `arm_to_scaler` argument with `scale=True` and let MABWiser fit scalers internally.","message":"In version 2.4.0, the scaler argument changed from a pre-trained scaler dict to a boolean `scale` flag. Code using `arm_to_scaler` will break.","severity":"breaking","affected_versions":">=2.4.0"},{"fix":"Replace `np.Inf` with `np.inf`.","message":"np.Inf removed in 2.7.4. Code referencing `np.Inf` will raise AttributeError.","severity":"breaking","affected_versions":">=2.7.4"},{"fix":"Use `LearningPolicy.EpsilonGreedy(epsilon=0.1)` instead of `LearningPolicy('epsilon_greedy')`.","message":"Direct use of `LearningPolicy` strings (e.g., `LearningPolicy('epsilon_greedy')`) is deprecated in favor of the enum-like `LearningPolicy.EpsilonGreedy` objects.","severity":"deprecated","affected_versions":">=2.7.1"},{"fix":"Call `mab.predict()` without arguments or pass an empty array like `np.array([[]])` for batch predictions.","message":"MAB.predict() for non-contextual policies expects an empty or None context array when using recent versions (>=2.4.0). Providing a non-empty context will raise an error.","severity":"gotcha","affected_versions":">=2.4.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: from mabwiser.mab import MAB","cause":"Importing MAB from the top-level package instead of the mab submodule.","error":"AttributeError: module 'mabwiser' has no attribute 'MAB'"},{"fix":"Use: LearningPolicy.EpsilonGreedy(epsilon=0.1)","cause":"Using LearningPolicy as a function with a string argument instead of using the enum attribute directly.","error":"TypeError: 'LearningPolicy' object is not callable"},{"fix":"For non-contextual, call predict() with no arguments or an empty array.","cause":"Passing a full context matrix to predict() for a non-contextual bandit.","error":"ValueError: The truth value of an array with more than one element is ambiguous"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}