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.R
1009 views
1
# Random Selection
2
3
# Importing the dataset
4
dataset = read.csv('Ads_CTR_Optimisation.csv')
5
6
# Implementing Random Selection
7
N = 10000
8
d = 10
9
ads_selected = integer(0)
10
total_reward = 0
11
for (n in 1:N) {
12
ad = sample(1:10, 1)
13
ads_selected = append(ads_selected, ad)
14
reward = dataset[n, ad]
15
total_reward = total_reward + reward
16
}
17
18
# Visualising the results
19
hist(ads_selected,
20
col = 'blue',
21
main = 'Histogram of ads selections',
22
xlab = 'Ads',
23
ylab = 'Number of times each ad was selected')
24