options(lifecycle_verbosity = "quiet")
library(prophet)
## Caricamento del pacchetto richiesto: Rcpp
## Caricamento del pacchetto richiesto: rlang
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.1 ✔ tibble 3.3.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ purrr::flatten() masks rlang::flatten()
## ✖ purrr::flatten_chr() masks rlang::flatten_chr()
## ✖ purrr::flatten_dbl() masks rlang::flatten_dbl()
## ✖ purrr::flatten_int() masks rlang::flatten_int()
## ✖ purrr::flatten_lgl() masks rlang::flatten_lgl()
## ✖ purrr::flatten_raw() masks rlang::flatten_raw()
## ✖ purrr::invoke() masks rlang::invoke()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::splice() masks rlang::splice()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
data<-read_excel("C:/Users/lele/OneDrive/Desktop/APSS/data set bit.xlsx",sheet=1)
view(data)
data$ds<-as.Date(data$ds)
data$y<-as.numeric(data$y)
Model<-prophet(yearly.seasonality = TRUE,weekly.seasonality = TRUE,daily.seasonality = FALSE,changepoint.prior.scale = 0.5)
Model<-add_country_holidays(Model,country_name = 'US')
Model<-fit.prophet(Model,data)
Future<-make_future_dataframe(Model,periods=365,freq="day")
tail(Future)
## ds
## 3430 2027-01-07
## 3431 2027-01-08
## 3432 2027-01-09
## 3433 2027-01-10
## 3434 2027-01-11
## 3435 2027-01-12
Forecast<-predict(Model,Future)
tail(Forecast[c('ds','yhat','yhat_lower','yhat_upper')])
## ds yhat yhat_lower yhat_upper
## 3430 2027-01-07 145019.7 94019.05 195631.1
## 3431 2027-01-08 145182.0 95412.39 195341.1
## 3432 2027-01-09 145377.3 96102.92 196035.7
## 3433 2027-01-10 145622.2 93933.89 195436.3
## 3434 2027-01-11 145837.5 93817.77 197255.7
## 3435 2027-01-12 146068.9 94153.45 196663.5
dyplot.prophet(Model,Forecast)
prophet_plot_components(Model,Forecast)
