-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFPredictionsByPositionPredictiveExperiment.R
67 lines (34 loc) · 1.56 KB
/
FFPredictionsByPositionPredictiveExperiment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
## Set the workspace id
wsid = "paste your workspace id here within the quotation marks"
## Set the workspace authentication key
auth = "paste your authentication token here within the quotation marks "
## Input the name of the Experiment
serviceName = "paste your service’s name here within the quotation marks "
## Load the AzureML library if not previously installed: install.packages("AzureML")
library("AzureML")
## Create a reference to the workspace
ws <- workspace(wsid, auth)
## Create a reference to the experiment
s <- services(ws, name = serviceName)
## Send the dataset to the Azure ML web service for scoring and store the result in ds
ds <- consume(s, dataset)
## Aggregate the scores to a single value by month
scores <- data.frame(Prediction = tapply(ds$Scored.Labels, ds$Month_ID, sum))
## Aggregate the revenue to a single value by month (for comparison)
revenue <- data.frame(Actuals = tapply(ds$Revenue, ds$Month_ID, sum))
## Combine the two resulting vectors in the new data.frame timePlot
timePlot <- cbind(scores, revenue)
## Load the ggplot library if not previously installed: install.packages("ggplot2")
require(ggplot2)
## Specify the data to plot and set the x-axis
ggplot(data = timePlot, aes(x = 1:nrow(timePlot))) +
## Plot the two lines
geom_line(aes(y = Prediction, colour = 'Prediction')) +
geom_line(aes(y = Actuals, colour = 'Actuals')) +
## Rename the x and y axis
xlab("Time") +
ylab("Result $") +
## Name the legend
labs(colour = "Legend") +
## Change the colors of the line
scale_color_manual(values = c("green", "red"))