-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweatherPredictor.R
More file actions
33 lines (24 loc) · 1005 Bytes
/
weatherPredictor.R
File metadata and controls
33 lines (24 loc) · 1005 Bytes
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
# weatherPredictor.R
# Ryan Zembrodt
# Creates a model to predict how many customers will be in the cafeteria based on time and weather
library(RWeka)
source("rSquared.R")
source("mase.R")
weatherPredictor <- function(dataset) {
# Randomize the dataset
randData <- dataset[sample(1:nrow(dataset)),]
# Train data is first 70%
trainData <- randData[1:(floor(nrow(randData)*0.7)),]
# Test data is the last 30%
testData <- randData[(floor(nrow(randData)*0.7)+1):nrow(randData),]
# Create a model and prediction vector for M5Prime
m <- M5P(InCount ~ Minute+Temp+Precipitation+DayOfWeek, data = trainData)
p <- predict(m, testData)
print(sprintf("rSquared accuracy: %f", rSquared(testData$InCount, p)))
print(sprintf("MASE accuracy: %f", mase(actualValues = testData$InCount, predictedValues = p)))
return(m)
}
# Input data from csv (generated by parser)
weatherData <- read.csv("weatherGatesData.csv")
# Create the model
weatherData.m <- weatherPredictor(weatherData)