An open API service indexing awesome lists of open source software.

https://github.com/kasaai/deeptriangle

DeepTriangle: A Deep Learning Approach to Loss Reserving
https://github.com/kasaai/deeptriangle

actuarial-science deep-learning insurance rstats

Last synced: 3 months ago
JSON representation

DeepTriangle: A Deep Learning Approach to Loss Reserving

Awesome Lists containing this project

README

        

---
output: github_document
---

```{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/).