-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
175 lines (124 loc) · 4.85 KB
/
README.Rmd
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
message = F,
warning = F,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "90%",
fig.align = "center"
)
```
# neuralprophet
<!-- badges: start -->
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/neuralprophet)](https://cran.r-project.org/package=neuralprophet)
![](http://cranlogs.r-pkg.org/badges/neuralprophet?color=brightgreen)
![](http://cranlogs.r-pkg.org/badges/grand-total/neuralprophet?color=brightgreen)
[![R-CMD-check](https://github.com/AlbertoAlmuinha/neuralprophet/workflows/R-CMD-check/badge.svg)](https://github.com/AlbertoAlmuinha/neuralprophet/actions)
<!-- badges: end -->
> The NEW Neural Prophet arrives to R!
```
# Install Development Version
remotes::install_github("AlbertoAlmuinha/neuralprophet")
```
Not on CRAN yet:
```{r}
#install.packages("neuralprophet")
```
## Neural Prophet Algorithm
Using `neural_prophet()`, which connects to `Python NeuralProphet()`.
```{r example, warning=FALSE, message=FALSE}
library(neuralprophet)
library(tidymodels)
library(tidyverse)
library(timetk)
m <- m4_monthly %>% filter(id == "M750")
splits <- initial_time_split(m)
model_fit_nprophet <- neural_prophet(
freq = "M",
growth = "linear",
trend_reg = 3,
learn_rate = 0.1,
changepoint_range = 0.8,
seasonality_mode = "additive"
) %>%
set_engine("prophet") %>%
fit(value ~ ., training(splits))
# Forecast with 95% Confidence Interval
modeltime_table(
model_fit_nprophet
) %>%
modeltime_calibrate(new_data = testing(splits)) %>%
modeltime_forecast(
new_data = testing(splits),
actual_data = m,
conf_interval = 0.95
) %>%
plot_modeltime_forecast(.interactive = FALSE)
```
## Installation
There are 2 key components to installing neuralprophet:
1. Download the R-Package, `neuralprophet`. This installs the R-Bindings, which allows you to interface with NeuralProphet
2. Set up the Python Environment so `neuralprophet` can connect to the `neuralprophet` python package.
### Step 1 - Download & Install neuralprophet
Download the latest development version.
``` r
remotes::install_github("AlbertoAlmuinha/neuralprophet")
```
### Step 2 - Python Environment Setup
Next, you'll need to set up a Python Environment that contains at a minimum:
- `neuralprophet==0.2.7`
- `pillow==8.3.0`
- `pandas==1.2.5`
- `numpy`
- `pytorch==1.6`
The python environment then needs to be activated with `reticulate`.
__Fast Setup__
You can use `install_nprophet()` to prepare and bind to a python environment containing `neuralprophet` and the required python packages.
- You only need to run this one time, and then you are good to go.
- Each time you load `neuralprophet`, the package will include this environment in it's search process.
```{r, eval=F}
# Neural Prophet Installation - Run 1st time
install_nprophet()
```
### Step 3 - Restart R and Try an Example
Restart your R session (if in RStudio, close and re-open). Then try this example.
```{r, eval=F}
library(neuralprophet)
library(tidymodels)
library(tidyverse)
library(timetk)
m <- m4_monthly %>% filter(id == "M750")
splits <- initial_time_split(m)
model_fit_nprophet <- neural_prophet(
freq = "M",
growth = "linear",
trend_reg = 3,
learn_rate = 0.1,
changepoint_range = 0.8,
seasonality_mode = "additive"
) %>%
set_engine("prophet") %>%
fit(value ~ ., training(splits))
# Forecast with 95% Confidence Interval
modeltime_table(
model_fit_nprophet
) %>%
modeltime_calibrate(new_data = testing(splits)) %>%
modeltime_forecast(
new_data = testing(splits),
actual_data = m,
conf_interval = 0.95
) %>%
plot_modeltime_forecast(.interactive = FALSE)
```
## Troubleshooting Installation
Python Environment setup is always fun. Here are a few recommendations if you run into an issue.
- __Check to make sure Conda or Miniconda is available__ using `reticulate::conda_version()`. If no conda version is returned, then use `reticulate::install_miniconda()` to install Miniconda (recommended vs full Aniconda). Then (re-)run `install_gluonts()`.
- __Check if Neural Prophet (Python) is available__ using `reticulate::py_module_available("neuralprophet")`. If this returns `TRUE`, then your installation has succeeded in building the environment, but you may have other issues like missing C++ build tools (next).
- __Windows 10 error: Microsoft Visual C++ is required.__ [Here are the instructions for installing the C++ tools needed.](https://github.com/business-science/modeltime.gluonts/issues/4)
- __Other installation issues.__ [Please file a GitHub issue here.](https://github.com/AlbertoAlmuinha/neuralprophet/issues)