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
Model | RMSE | MAE | MAPE | |
---|---|---|---|---|
Without exogenous inputs | 1050.4 | 857.3 | 14.2% | |
With exogenous inputs | 875.7 | 656.2 | 11.5% |
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
results <- vector(mode = 'numeric', length = nrow(prophetGrid)) | |
# Search best parameters | |
for (i in seq_len(nrow(prophetGrid))) { | |
# Select the parameters to try | |
parameters <- prophetGrid[i, ] | |
if (parameters$growth == 'logistic') { | |
train$cap <- parameters$capacity | |
} |
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
# Search grid | |
prophetGrid <- expand.grid(changepoint_prior_scale = c(0.05, 0.5), | |
seasonality_prior_scale = c(1, 10), | |
holidays_prior_scale = c(1, 10), | |
regressor_prior_scale = c(1, 10), | |
capacity = c(6000, 7000, 8000), | |
growth = 'logistic') |
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
# Libraries | |
library(tidyverse) | |
library(lubridate) | |
library(prophet) | |
library(forecast) | |
# Read data | |
bikes <- read_csv('bikes.csv') %>% | |
mutate(datetime = date(datetime)) |
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
df <- read_csv("trump_lies.csv") | |
#> Parsed with column specification: | |
#> cols( | |
#> date = col_date(format = ""), | |
#> lie = col_character(), | |
#> explanation = col_character(), | |
#> url = col_character() | |
#> ) |
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
write_csv(df, "trump_lies.csv") |
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
# Load packages | |
library(rvest) | |
library(stringr) | |
library(dplyr) | |
library(lubridate) | |
library(readr) | |
# Read web page | |
webpage <- read_html("https://www.nytimes.com/interactive/2017/06/23/opinion/trumps-lies.html") |
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
library(lubridate) | |
df$date <- mdy(df$date) | |
glimpse(df) | |
#> Observations: 116 | |
#> Variables: 4 | |
#> $ date <date> 2017-01-21, 2017-01-21, 2017-01-23, 2017-01-25, 2017-01-25, 2017-01-... | |
#> $ lie <chr> "I wasn't a fan of Iraq. I didn't want to go into Iraq.", "A reporter... | |
#> $ explanation <chr> "He was for an invasion before he was against it.", "Trump was on the... | |
#> $ url <chr> "https://www.buzzfeed.com/andrewkaczynski/in-2002-donald-trump-said-h... |
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
library(dplyr) | |
records <- vector("list", length = length(results)) | |
for (i in seq_along(results)) { | |
date <- str_c(results[i] %>% html_nodes("strong") %>% html_text(trim = TRUE), ", 2017") | |
lie <- str_sub(xml_contents(results[i])[2] %>% html_text(trim = TRUE), 2, -2) | |
explanation <- str_sub(results[i] %>% html_nodes(".short-truth") %>% html_text(trim = TRUE), 2, -2) | |
url <- results[i] %>% html_nodes("a") %>% html_attr("href") | |
records[[i]] <- data_frame(date = date, lie = lie, explanation = explanation, url = url) | |
} |
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
url <- first_result %>% html_node("a") %>% html_attr("href") | |
url | |
#> [1] "https://www.buzzfeed.com/andrewkaczynski/in-2002-donald-trump-said-he-supported-invading-iraq-on-the" |
NewerOlder