-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathREADME.Rmd
95 lines (69 loc) · 2.95 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(deeptriangle)
library(tidyverse)
```
[![Travis build status](https://travis-ci.org/kasaai/deeptriangle.svg?branch=master)](https://travis-ci.org/kasaai/deeptriangle)
# DeepTriangle
This is the companion repository to the paper [*DeepTriangle: A Deep Learning Approach to Loss Reserving*](https://www.mdpi.com/2227-9091/7/3/97).
## Experiments
To get started, either clone the repo and build the R package, or install with
``` r
devtools::install_github("kasaai/deeptriangle")
```
You will also need the [insurance](https://github.com/kasaai/insurance) package, which can be installed with
```r
devtools::install_github("kasaai/insurance")
```
The experiments can be found in `analysis/main.R`. It is recommended that you use a GPU since many instances of the models are fit.
For convenience, we provide a `predictions.feather` file in the release.
```{r, message = FALSE}
predictions <- feather::read_feather("datasets/predictions.feather")
model_results <- dt_compute_metrics(predictions) %>%
bind_rows(stochastic_model_results) %>%
bind_rows(read_csv("datasets/automl_results.csv")) %>%
gather(metric, value, mape, rmspe)
dt_tabulate_metrics(model_results, metric = "mape") %>%
knitr::kable(booktabs = "T", digits = 3)
```
To create actual vs. predicted plots, use the `dt_plot_predictions()` function. Here are successful and unsuccessful examples of the model's forecasting attempts.
Company 1767 commercial auto.
```{r, echo = FALSE, message = FALSE, out.width = "80%"}
library(cowplot)
p1 <- dt_plot_predictions(predictions, "1767", "commercial_auto", "paid_loss") + xlab("")
p2 <- dt_plot_predictions(predictions, "1767", "commercial_auto", "claims_outstanding")
p12 <- plot_grid(
p1 + theme(legend.position = "none"),
p2 + theme(legend.position = "none"),
align = "v",
ncol = 1
)
legend <- get_legend(p1)
plot_grid(p12, legend, rel_widths = c(1, 0.2), nrow = 1)
```
Company 337 workers' compensation.
```{r, echo = FALSE, message = FALSE, out.width = "80%"}
library(cowplot)
p1 <- dt_plot_predictions(predictions, "337", "workers_compensation", "paid_loss") + xlab("")
p2 <- dt_plot_predictions(predictions, "337", "workers_compensation", "claims_outstanding")
p12 <- plot_grid(
p1 + theme(legend.position = "none"),
p2 + theme(legend.position = "none"),
align = "v",
ncol = 1
)
legend <- get_legend(p1)
plot_grid(p12, legend, rel_widths = c(1, 0.2), nrow = 1)
```
## Testing different architectures
If you would like to try out different architectures or hyperparameters, you can do so by providing a function that returns a keras model. See the source code of `dt_model()` for a template.
For more details on the **keras** R package, visit [https://keras.rstudio.com/](https://keras.rstudio.com/).