Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
debakarr
GitHub Repository: debakarr/machinelearning
Path: blob/master/Part 6 - Reinforcement Learning/Upper Confidence Bound/random_selection.py
1009 views
1
# Random Selection
2
3
# Importing the libraries
4
import numpy as np
5
import matplotlib.pyplot as plt
6
import pandas as pd
7
8
# Importing the dataset
9
dataset = pd.read_csv('Ads_CTR_Optimisation.csv')
10
11
# Implementing Random Selection
12
import random
13
N = 10000
14
d = 10
15
ads_selected = []
16
total_reward = 0
17
for n in range(0, N):
18
ad = random.randrange(d)
19
ads_selected.append(ad)
20
reward = dataset.values[n, ad]
21
total_reward = total_reward + reward
22
23
# Visualising the results
24
plt.hist(ads_selected)
25
plt.title('Histogram of ads selections')
26
plt.xlabel('Ads')
27
plt.ylabel('Number of times each ad was selected')
28
plt.show()
29