{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Identifying Right AD Banner Using MAB" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "Let us say you are running a website and you have five different banners for the same ad and you want to know which banner attracts the user? We model this problem statement as a bandit problem. Let us say these five banners are five bandits and we assign reward 1 if the user clicks the ad and reward 0 if the user does not click the ad.\n", "\n", "In a normal A/B testing, we perform complete exploration of all these five banners alone before deciding which banner is the best. But that will cost us lot of regret. Instead, we will use good exploration strategy for deciding which banner will give us most rewards (most clicks)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ " First, let us import necessary libraries" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2018-06-01 12:43:31,568] Making new env: BanditTenArmedGaussian-v0\n" ] } ], "source": [ "import gym_bandits\n", "import gym\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import seaborn as sns\n", "env = gym.make(\"BanditTenArmedGaussian-v0\")" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "scrolled": true }, "source": [ "Let us simulate a dataset with 5*10000 as shape where the column is the ad banner type and rows are either 0 or 1 i.e whether the ad has been clicked or not clicked by the user respectively\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df = pd.DataFrame()\n", "df['Banner_type_0'] = np.random.randint(0,2,100000)\n", "df['Banner_type_1'] = np.random.randint(0,2,100000)\n", "df['Banner_type_2'] = np.random.randint(0,2,100000)\n", "df['Banner_type_3'] = np.random.randint(0,2,100000)\n", "df['Banner_type_4'] = np.random.randint(0,2,100000)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
| \n", " | Banner_type_0 | \n", "Banner_type_1 | \n", "Banner_type_2 | \n", "Banner_type_3 | \n", "Banner_type_4 | \n", "
|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
| 1 | \n", "0 | \n", "1 | \n", "0 | \n", "1 | \n", "1 | \n", "
| 2 | \n", "1 | \n", "0 | \n", "0 | \n", "1 | \n", "1 | \n", "
| 3 | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "0 | \n", "
| 4 | \n", "0 | \n", "1 | \n", "1 | \n", "0 | \n", "1 | \n", "
| 5 | \n", "1 | \n", "0 | \n", "1 | \n", "0 | \n", "1 | \n", "
| 6 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "
| 7 | \n", "0 | \n", "1 | \n", "1 | \n", "1 | \n", "0 | \n", "
| 8 | \n", "0 | \n", "1 | \n", "1 | \n", "0 | \n", "1 | \n", "
| 9 | \n", "0 | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "