Tutorial | Generalized Linear Models#

Get started#

This tutorial introduces Generalized Linear Models (GLM) in a practical way—by modelling the car insurance claim risk. You’ll learn how to build, interpret, and apply the model directly within the webapp.

Objectives#

In this tutorial, you will:

  • Create the Visual GLM webapp.

  • Configure and train a GLM model.

  • Visualize the results.

  • Deploy the model.

Prerequisites#

To use the Generalized Linear Model, you’ll need:

  • Dataiku 14.2 or later.

  • An Advanced Analytics Designer or Full Designer user profile.

  • An installed Generalized Linear Models plugin.

Create the project#

  1. From the Dataiku Design homepage, click + New Project.

  2. Select Learning projects.

  3. Search for and select Generalized Linear Model.

  4. If needed, change the folder into which the project will be installed, and click Create.

  5. From the project homepage, click Go to Flow (or type g + f).

Note

You can also download the starter project from this website and import it as a zip file.

The GLM webapp#

Create the webapp#

The first thing you must do is create the visual webapp the plugin has provided.

  1. Navigate to Code (Code icon.) > Webapps.

  2. Click + New Webapp and select Visual Webapp.

  3. Search for GLM Analysis thanks to the search bar and select it.

  4. In the Webapp name field, name it GLM tutorial.

  5. Click Create.

Setting up#

The goal is to create a GLM to model claim frequency for a car insurance company. The exposure is the period of time during which the contract was held, expressed in years. You can set it up that way.

  1. In the View tab, click Create a New Analysis and enter Car Insurance Claims as the Analysis Name.

  2. In Train Dataset, select the synthetic_claims.

  3. Select Random as the Splitting Policy.

  4. Select claim_count and exposure as the target and exposure variables, respectively.

  5. Click Create Analysis to confirm.

Dataiku screenshot of the GLM analysis creation.

Train a model#

You have created an analysis in your project, you can now train a new model with the variables you want. You also need to configure your GLM with the relevant parameters. Here, you will create your first model to predict the claim count depending on bonus/malus and region variables.

  1. Navigate to the Model/Variable Configuration tab.

  2. Name the model Region-bonus-malus.

  3. You can leave the Poisson and Log functions as the Distribution and Link, respectively.

  4. Check the bonus_malus_level and region variables in the Variable Configuration panel to include them in the model.

  5. Click Train Model to confirm.

Dataiku screenshot of GLM training model session.

You should see a loading screen and a notification that the training job has been done properly.

Tip

You can find your different analysis and models in the Visual ML menu of your project.

Visualize results#

The webapp allows you to visualize the predictions alongside their observed counterparts.

  1. Navigate to the Observed vs Predicted Chart tab.

  2. Select the Region-bonus-malus model.

  3. Select the region variable.

  4. Run the analysis on the Test dataset.

  5. Click Create Chart.

Dataiku screenshot of the observed vs predicted chart created.

You can compare the model’s predictions with the actual observed values for the claim frequency, while displaying the total exposure per region. The model performs well and you can see that the claim frequency is way lower in rural region, which is expected given the lower density.

You can also visualize the results through statistics.

  1. Navigate to the Variable-Level Statistics tab.

  2. Select the Region-bonus-malus.

Note

You can click on the upload icon to export the statistics in a spreadsheet.

You can see relevant model outputs such as the relativity, the coefficient and statistics such as the p-value and the standard error.

The last visualization tool of the webapp is the lift chart. A lift chart is a visual tool used to evaluate a model’s performance by comparing its predictions to actual results. This chart plots your data after it has been sorted by the model’s prediction and grouped into bins. Observed data is the ground truth, it shows the actual average outcome for the data points within each bin. Predicted data is the model’s average guess, it shows the average predicted value for the data points within each bin. This charts lets you see if your predictions match the observed values over the full range of predictions and if not, on which particular range you notice larger gaps. This chart shows a strong, predictive model that effectively separates risk, though it has minor calibration issues where the observed values slightly differ from the predictions for intermediate values of risk.

  1. Navigate to the Lift Chart tab.

  2. Slide the number of bins to 10.

  3. Switch to Test for the dataset.

  4. Click Create Chart.

Dataiku screenshot of the lift chart tab.

You can see that the fit is smooth.

Deploy your model#

  1. Navigate to the GLM Model Management tab.

  2. Click on the rocket icon to deploy the model.

Dataiku screenshot of model management of the webapp.

What’s next?#

Congratulations! In this tutorial, you’ve created the Visual GLM webapp, configured and trained a GLM model, visualized the results, and even deployed the model. You’re now ready to apply these skills to real-world car insurance claim prediction and beyond. You can explore the Solution | Insurance Claims Modeling for a complex case.