Allstate Claims Severity - Predictive Analytics

Posted on Aug 30, 2017


Allstate claims severity was a Kaggle competition that was open in 2016. The objective of this competition was to perform analytics to predict a model for the cost and the severity of claims. Allstate wants to develop automated methods of predicting the cost, and hence severity, of claims and claim service.

Data provided has no comprehensible variable name but has 116 categorical variables and 15 continuous variables including the response variable loss.  Each row represented a claim. No null values were available in the training or test data provided. Response variable is a continuous variable – loss. Hence the models that follow will be based on regression analysis

The training dataset contained 188,318 claim records. The prediction task was to find the loss for each of the 126546 claims in the test data set.

The scoring was done based on accuracy of submissions that were made on claim severity of a separate test file that was provided. This file was missing the column named loss.

Exploratory Data Analysis (EDA)

All the features  in the dataset were unknown making it difficult to provide insights into the data. However, there were no missing or null data in the training dataset making it easier to model. The following plots were obtained to ensure the response variable loss is predictable. To prevent high leverage from the outliers, a log transformation on ‘loss’ was performed, so it can be more normal distributed without changing the order. Both plots - with and without log transformation is as shown below

Feature Engineering/Data pre-processing

The following feature engineering methods were used.

  • Training data is split 80/20 and cross validated
  • Dummy variables are created for the categorical variables
  • Data is scale and centered

Analysis of predictors

a. ANOVA test for categorical predictors

This test was performed on the categorical variables to determine whether there are any statistically significant differences between the means of categorical (unrelated) groups.

Only 4 variables - cat58, cat62, cat64, cat68 -  have p-value greater than 0.05 which indicates that there is a large variation between these variables while the other variables do not have a large variation.

We can check if the above variables are displayed in variable importance plots generated using modeling .

b. QQ plot and residual vs fitted plot using Anova for categorical predictors

These plot are generated to find the variance of categorical predictors with respect to the response variable loss. The QQ plot shows that the variance is minimal and it is normally distributed.

The residual vs fitted values has good spread of residuals around the horizontal line indicating that the relation between the categorical predictors and the response variable follows a linear relationship.

c Correlation of numerical predictors
The plot above using numerical predictors shows strong correlation for the following variables (plotted using correlation of the data)

cont6, cont12, cont6, cont9


The models used are:

  • Forward Selection
  • Lasso and Ridge Regression
  • Decision Tree
  • Extreme Gradient Boosting
  1. Forward Selection
  • Important variables using forward selection model are as shown in the plot
  • RMSE of training data = 0.8267
  • forward_model$bestTune


18  20

  • Mean absolute error for test data using Kaggle submission = 3019.94

b. Lasso and ridge regression

  • Important variables plot using lasso and ridge regression is shown below
  • RMSE of training data = 0.7157
  • glmnet_model$bestTune

alpha    lambda

55    0.5        0.0001676833

  • Mean absolute error for test data using Kaggle submission = 3020.36

c. Multiple linear regression

  • Interpretation of variance

Adjusted R square is 0.4574 which is low indicating high variance in the data using this model

  • RMSE of training data = 0.7165
  • Mean absolute error for training data = 21908.73
  • Mean absolute error for test data using Kaggle submission = 3021.32

d. Decision Tree (with cp parameter)


  • Complexity parameter  with values 0.005, 0.002, 0.008

RMSE of training data

CP         RMSE       R squared

0.002    0.7840            0.3913        ß Best model

0.005    0.8080           0.3534

0.008     0.8137           0.3443

  • RMSE of test data = 1.17 (too high)
  • Mean absolute error for test data using Kaggle submission = 3019.19

e. Decision Tree (with depth parameter)

  •      Parameters

Depth values 5, 10, 15, 20

  •      RMSE of training data

Depth  RMSE  R squared

5       0.8262     0.3071        ß Best model

10      0.8120     0.3307

15       0.8120     0.3307

20      0.8120     0.3307

  • RMSE of test data = 0.7937
  • Mean absolute error for test data using Kaggle submission = 3019.88

f.   Extreme Gradient boosting

  • RMSE of training data = 0.667
  • xg_model$bestTune

nrounds      max_depth      eta     gamma     colsample_bytree

45               150                  3               0.3                0                 0.6

min_child_weight    subsample

45                         1                           1

  • Mean absolute error for test data using Kaggle submission = 3020.15

RMSE vs tree depth for extreme boosting


  • Comparing all models above Decision tree with complexity parameter yielded the lowest MAE.
  • However it would inappropriate to say that this is the best model.
  • Given more time, more models like SVM and random forest could be executed or the above models with more parameters can be executed.

About Author


Annie George

Annie George has more than a decade of experience using mainframe technology and databases such as DB2 and SQLServer to achieve results for organizations in the private sectors. Annie completed her Bachelors in Civil Engineering but she found...
View all posts by Annie George >

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp