# Allstate Claims Severity - Predictive Analytics

**Introduction**

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**

cont6, cont12, cont6, cont9

**Modeling**

The models used are:

- Forward Selection
- Lasso and Ridge Regression
- Decision Tree
- Extreme Gradient Boosting

**Forward Selection**

- Important variables using forward selection model are as shown in the plot
- RMSE of training data = 0.8267
- forward_model$bestTune

nvmax

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)**

Parameters

- 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**

**CONCLUSION**

- 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.