Package: thompson
Multi-armed banditThompson is Python package to evaluate the multi-armed bandit problem. In addition to thompson, Upper Confidence Bound (UCB) algorithm, and randomized results are also implemented.In probability theory, the multi-armed bandit problem is a problem in which a fixed limited set of resources must be allocated between competing (alternative) choices in a way that maximizes their expected gain, when each choice's properties are only partially known at the time of allocation, and may become better understood as time passes or by allocating resources to the choice. This is a classic reinforcement learning problem that exemplifies the exploration-exploitation tradeoff dilemmawikipedia.In the problem, each machine provides a random reward from a probability distribution specific to that machine. The objective of the gambler is to maximize the sum of rewards earned through a sequence of lever pulls. The crucial tradeoff the gambler faces at each trial is between "exploitation" of the machine that has the highest expected payoff and "exploration" to get more information about the expected payoffs of the other machines. The trade-off between exploration and exploitation is also faced in machine learning. In practice, multi-armed bandits have been used to model problems such as managing research projects in a large organization like a science foundation or a pharmaceutical companywikipedia.ContentsInstallationRequirementsQuick StartContributeCitationMaintainersLicenseInstallationInstall thompson from PyPI (recommended). thompson is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.Distributed under the MIT license.RequirementspipinstallmatplotlibnumpypandasQuick Startpip install thompsonAlternatively, install thompson from the GitHub source:gitclonehttps://github.com/erdogant/thompson.gitcdthompson
pythonsetup.pyinstallImport thompson packageimportthompsonasmabLoad example data:df=mab.example_data()Compute multi-armed bandit using thompsonout=mab.thompson(df)fig=mab.plot(out)Compute multi-armed bandit using UCB-Upper confidence Boundout=mab.UCB(df)fig=mab.plot(out)Compute multi-armed bandit using randomized dataout=mab.UCB_random(df)fig=mab.plot(out)df looks like this:Ad 1  Ad 2  Ad 3  Ad 4  Ad 5  Ad 6  Ad 7  Ad 8  Ad 9  Ad 10
0        1     0     0     0     1     0     0     0     1      0
1        0     0     0     0     0     0     0     0     1      0
2        0     0     0     0     0     0     0     0     0      0
3        0     1     0     0     0     0     0     1     0      0
4        0     0     0     0     0     0     0     0     0      0
   ...   ...   ...   ...   ...   ...   ...   ...   ...    ...
9995     0     0     1     0     0     0     0     1     0      0
9996     0     0     0     0     0     0     0     0     0      0
9997     0     0     0     0     0     0     0     0     0      0
9998     1     0     0     0     0     0     0     1     0      0
9999     0     1     0     0     0     0     0     0     0      0

[10000 rows x 10 columns]Referenceshttps://en.wikipedia.org/wiki/Multi-armed_banditMaintainersErdogan Taskesen, github:erdogantContributeAll kinds of contributions are welcome!If you wish to buy me aCoffeefor this work, it is very appreciated :)LicenceSeeLICENSEfor details.