Last active
March 17, 2020 18:00
-
-
Save jeffgswanson/3a1d3f731422d258a9efc1492f5b0578 to your computer and use it in GitHub Desktop.
Forecast website sessions from a CSV document in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install/Library these functions: | |
library(forecast) | |
library (tidyr) | |
library (dplyr) | |
library (highcharter) | |
# Upload CSV file to R Studio, or other GUI containing only monthly sessions and dates | |
aa_data <- read.csv("~/[name of file].csv", stringsAsFactors = FALSE, header = TRUE, sep = ",") | |
# Check data structure of uploaded data | |
str(aa_data$sessions) | |
# Convert dates from characters to integers or numeric (may not apply to all data sets) | |
yearMonth <- c("yearMonth") | |
# Identify the column, start and end dates, and that new data should be in months | |
aa_ts <- ts(aa_data$sessions, start = c(2010,02), end = c(2016,12), frequency = 12) | |
# Apply Holt Winters forecast model to data | |
forecast1 <- HoltWinters(aa_ts) | |
# Forecast for next 36 months | |
hchart(forecast(forecast1, h = 36)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment