NYC Data Science Academy| Blog
Bootcamps
Lifetime Job Support Available Financing Available
Bootcamps
Data Science with Machine Learning Flagship 🏆 Data Analytics Bootcamp Artificial Intelligence Bootcamp New Release 🎉
Free Lesson
Intro to Data Science New Release 🎉
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook Graduate Outcomes Must See 🔥
Alumni
Success Stories Testimonials Alumni Directory Alumni Exclusive Study Program
Courses
View Bundled Courses
Financing Available
Bootcamp Prep Popular 🔥 Data Science Mastery Data Science Launchpad with Python View AI Courses Generative AI for Everyone New 🎉 Generative AI for Finance New 🎉 Generative AI for Marketing New 🎉
Bundle Up
Learn More and Save More
Combination of data science courses.
View Data Science Courses
Beginner
Introductory Python
Intermediate
Data Science Python: Data Analysis and Visualization Popular 🔥 Data Science R: Data Analysis and Visualization
Advanced
Data Science Python: Machine Learning Popular 🔥 Data Science R: Machine Learning Designing and Implementing Production MLOps New 🎉 Natural Language Processing for Production (NLP) New 🎉
Find Inspiration
Get Course Recommendation Must Try 💎 An Ultimate Guide to Become a Data Scientist
For Companies
For Companies
Corporate Offerings Hiring Partners Candidate Portfolio Hire Our Graduates
Students Work
Students Work
All Posts Capstone Data Visualization Machine Learning Python Projects R Projects
Tutorials
About
About
About Us Accreditation Contact Us Join Us FAQ Webinars Subscription An Ultimate Guide to
Become a Data Scientist
    Login
NYC Data Science Acedemy
Bootcamps
Courses
Students Work
About
Bootcamps
Bootcamps
Data Science with Machine Learning Flagship
Data Analytics Bootcamp
Artificial Intelligence Bootcamp New Release 🎉
Free Lessons
Intro to Data Science New Release 🎉
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook
Graduate Outcomes Must See 🔥
Alumni
Success Stories
Testimonials
Alumni Directory
Alumni Exclusive Study Program
Courses
Bundles
financing available
View All Bundles
Bootcamp Prep
Data Science Mastery
Data Science Launchpad with Python NEW!
View AI Courses
Generative AI for Everyone
Generative AI for Finance
Generative AI for Marketing
View Data Science Courses
View All Professional Development Courses
Beginner
Introductory Python
Intermediate
Python: Data Analysis and Visualization
R: Data Analysis and Visualization
Advanced
Python: Machine Learning
R: Machine Learning
Designing and Implementing Production MLOps
Natural Language Processing for Production (NLP)
For Companies
Corporate Offerings
Hiring Partners
Candidate Portfolio
Hire Our Graduates
Students Work
All Posts
Capstone
Data Visualization
Machine Learning
Python Projects
R Projects
About
Accreditation
About Us
Contact Us
Join Us
FAQ
Webinars
Subscription
An Ultimate Guide to Become a Data Scientist
Tutorials
Data Analytics
  • Learn Pandas
  • Learn NumPy
  • Learn SciPy
  • Learn Matplotlib
Machine Learning
  • Boosting
  • Random Forest
  • Linear Regression
  • Decision Tree
  • PCA
Interview by Companies
  • JPMC
  • Google
  • Facebook
Artificial Intelligence
  • Learn Generative AI
  • Learn ChatGPT-3.5
  • Learn ChatGPT-4
  • Learn Google Bard
Coding
  • Learn Python
  • Learn SQL
  • Learn MySQL
  • Learn NoSQL
  • Learn PySpark
  • Learn PyTorch
Interview Questions
  • Python Hard
  • R Easy
  • R Hard
  • SQL Easy
  • SQL Hard
  • Python Easy
Data Science Blog > Machine Learning > Kaggle Competition: Allstate Claims Severity

Kaggle Competition: Allstate Claims Severity

Wen Li, Chuan Hong, leizhang and Lydia Kan
Posted on Dec 5, 2016

1.Introduction

Allstate Corporation is one of the largest insurance companies in the United State. The main products that Allstate offers are car insurance, recreational vehicles insurance, home, property, condo, renters insurance, and so on. In order to provide better claims service for Allstate’s customers, the company is developing automated methods to predict claims serverity. Allstate launched this challenge on Kaggle, and invited all the Kagglers to tackle down this task with their technical skills and creativity.

The goal of this challenge is to build a model that can help Allstate to predict the server of the claims accuratly. At the same time, to provide the important factors that have strong impact on the severity. With these information, Allstate can proposed or adjust more suitable insurance packages for their customers.

On top of this, as a team, we wanted to implant the data manipulating, features engineering, and the machine learning skills that we have learn to perform a strategic process, and established a model that has strong capability to achieve the best prediction possible.

2.Workflow

workflow

In order to tackle down this challenge within two weeks as a team, we were following the pipline showing above from the begining. The workflow is dividing into three main parts:

1) Exploratory Data Analysis (EDA): Due to all the features are annonymous, EDA became a very important stage for us to understand more insights of the data. This stage is also crucial for the next stage - Feature Engineering

2) Feature Engineering: Feature Engineering is the stage that allow data scientists to exert their creativity. It is also the stage that can help to differenciate the models from others. For the initial features selections, we decide to use unsupervised learning methods, PCA and K-means to see is there any possibility to reduce dimensions and cluster the features. After the first attampt, we also used three different encodi09ng methods:

  • Dummify the categorical variables and keep all of them
  • Dummify the categorical variables and drop the variables that have near zero variance
  • Dummify the categorical variables and releveled the variables that have high numbers of levels.
  • Model implementing: the third stage is implementing single models and fine-turning them. From there, we have selected the best performing models to do model stacking.

3) The models we have used are:

  • Multiple Linear Regression
  • Ridge Regression
  • Lasso Regression
  • Random Forest
  • Gradient Boosting Model
  • XGBoosting

3.EDA

The complete training data set contain    observations, 130 continuous and categorical input variables, and 1 continuous output variables with no missing value. The density plot of loss below provide the information about the distribution of the output variables. It indicates that the observation is skewed to the right. To prevent high leverage from the outliers, we did a shifting and log transformation on ‘loss’, so it can be more normal distributed without changing the order. Second density plot is the result after traformating the output variable.

screen-shot-2016-12-05-at-1-58-40-pm

From the numeric graphic analysis, it inicates that the data set has 116 categorical variables and 14 continuous variables for the input features. For the categorical variables, the lowest number of levels of variables is 2 levels, and the highest number of levels that appears in the variables is 326 levels. With such high number of levels in the variables, this is the part will be focused on during the feature engineering. After further investigation, another import information about the categorical variables is that some variables containing levels only in the test set, but not in the training set. The chart below lists out the unique levels for the categorical variables that have this behavior.

cat-chart

For the continuous inputs, the correlaiton plot provides the insight among the variables. The plot indicates that there are some strong relationship between some variables. This is important information for building model later on.

cor-plot

4.Initial Feature Selection (PCA, K-means)

y-graph

In order to explore the potential dimension reduction, the unsupervised machine learning methods PCA and K-means were applied to the training set. Based on the resurlts of the scree plots from PCA and K-means, the dimensions are not able to have a siginificant reduced. For PCA, with about 48 princial components, around 88% variance is explained, under 95%. For K-Means, even with 20 clusters, the within-cluster variance is still very large. As the result, we have to move forward with other feature engineering methods to improve the accuracy, and reduce the computation expenses at the same time.

5.Feature Engineering

feature

In this project, we did three different types of feature engineering. The findings form EDA showed that there are more than 100 categorial variables in this dataset. Most of them have two levels, which is fine for modling. However, a few of them have many different levels; some of them have levels greater than 100. So, we did a dummy transformation first. We broke categorical variables with many levels into several dummy variables. It means that for a categorical variable, when one of its levels have one observation, it becomes a dummy variable having (n-1) zeroes. Hence, after the first step, there were many dummny variables which were near zero variance (NZV) predictiors. We could keep all of them or drop the features which had NZV. , we used both of them to build models, however, the results were not good.

On one hand, removing data should be avoided, if possible. We were not sure if the NZV predictors wrere non-informative. Those NZV features could in fact turn out to be very inofrmation. However, keeping all of features took us long time than expected to build models, and it might result in overfitting as well.

On the other hand, we used the function nearZeroVar from the Caret package to remove NZV predictor. By default, a predictor is classified as NZV if the percentage of unique values in the samples is less than 5%. The advantage was that this method saved us a lot of time to build models, however, the drawback was that it increased the error and resulted in losing some potentially important information.

In order to balance between time consumption and error reducing, this project regroups those categorical variables over 15 levels, to keep as much information as possible. After regrouping, this project dummifies the new categorical variables with the rest for the third round machine learning. The good thing in this way is that useful information is kept. However, there are multiple ways to group variables.

Let’s first explain the reason why 15 levels here is a good cutting point. When using near zero variance to drop features, for categorical variables, it removes those levels with less than 5 percent of observations. For such a large dataset, 5% means around 9500 observations. Even if a level having 9000 observations, which must have some useful information, will be removed from the dataset. For variables like cat116, which has 326 levels, only 3 levels are kept after near zero variance feature engineering. Even in an ideal case, only 19 out of 326 levels can be used for the further machine learning, which is certainly not desirable. Meanwhile, this ‘ideal’ situation also tells the fact that 20 is not a good cutting point. To be more conservative, this project determines to regroup categorical variables over 15 levels. In other words, keep over 5 percent of observations in each level.

graph1

Here are two graphs. Each graph represents one categorical variable. Each point here is one level. The x-axis is counts. That is how many observations in each level. The y-axis is mean of the loss for each level. An interesting finding is that, in most cases, the scatterplot is like two straight lines, one vertical, one horizontal, like in the left graph. The right graph, Cat112, is an exception.

However, the ways to regroup are using the same idea: first, keep the original levels having over 5% of observations, and then split them based on the average loss and counts, regroup them into high loss, low count group, low loss low count group, low loss low count group, and so on and so forth.

By doing feature engineering in this way, it also manually builds a connection between loss and those categorical variables. The next step is the third round of machine learning.

6.Models:

6.1 Linear Regression

The first individual supervised model we tried was Multiple Linear Regression. We mainly used this model to check would there be any difference between different feature engineering methods. The Linear model had been tried on 3 encoding methods. The first encoding method did not go through due to high number of variables has 0 variance. After dropping the variables has near zero variance, the model gave the RMSE around 0.57659.

On top of using the third encoding method, which was to relevel the categorical variables that had high number of levels, we also droped the highly correlated continuous variables to test. The model returned  the RMSE around 0.56557 this time, which indicated that the third encoding method performs better on the linear model.

6.2 Ridge & Lasso Regression

ridge_lasso

Based on three types of feature engineering, the new group gives the best results. In ridge regression, the best lambda is 1e-05, and the RMSE is 0.56414. In lasso regression, the best lambda is 1.592283e-05, and the RMSE is 0.56415.

6.3 RandomForest

For the random forest model, we used the data set from second encoding method, which is drop the variables have near zero variance. The default setting was used for the initial fit, which is 500 trees, and 51 mtry. However, the model took two days to finish the training without cross validation. Due to high computational expenses, we choose to move forward to other individual models.

6.4 GBM

gbmgbm-imp

Three Gradient Boosting model were trained:

  1. the variables with less than 5% variance were removed
  2. all the variables were ustilized for the model
  3. reduce the levels of category variables

Four parameter were cross validated based on the subtest data, such as ntree (number of trees), shrinkage factor, depth of trees and number of the minmun obersevation in the nodes(figure 3&4),From the models with the best parameter, the model 2 show the best accuracy (RMSE 0.51)but expensive computation(3 days), the model1 lower accuracy(0.54) but efficient(1.5 days),and the model3 sufficiently appoach the balance of the accuracy(0.53)and the computation(2days).

6.5 XGBoost

xgboostxgb-imp

We also tried XGBoost from Caret package to build models. Similarly, the new group shows the best results. Compared with running XGBoost package directly, the XGBoost from Caret already reduces the total number of parameters people can tune to seven. After trying different combinations of parameters, we found that there were two of them really affected the model, which were nrounds and max_depth. The rest were less relevant. The left graph above shows the result of the cross validation which gave us the best model, the corresponding smallest RMSE is 0.5436. Meanwhile, the most important feaure is cat80D  (see also right graph above), also similar with the results of gbm.

6.6 Model Stacking

Different error distributions are derived from different models. The nature of stacking is to combine those error distributions into one "aggregated" model in order to compensate each other's weakness.

For example, as the non-linear features expanding, Neural Network usually works better for the numeric variables than Ridge or Lasso regression does. Meanwhile, the boosting model costs less computation on the dummy variables. Here the boosting and neural network models are selected to stack through linear regression algorithm and neural network algorithm, respectively shown in the figures above. As the result of stacking, the Kaggle scores are significantly improved.

7.Results and Summary

screen-shot-2016-12-05-at-3-28-36-pm

According to the RMSEs of each models, the best individual model is the gradient boosting machine learning. The rationale behind this best performance is multiple attempts of cross-validation and the third method of feature engineering - new group. However, model stacking gives the best predictive accuracy. The greater the differences of the learning algorithms, the better performance the stacking model provides.

About Authors

Wen Li

View all posts by Wen Li >

Chuan Hong

Chuan Hong is a Ph.D. Candidate majoring in Public Health at the University of South Carolina. Her main research areas are environmental health sciences, with a focus on environmental epidemiology. By using a series of data collection, statistical...
View all posts by Chuan Hong >

leizhang

He got his PhD degree in Physics from City University of New York in 2013, and recently completed his post doctoral projects funded by CDMRP (Congressionally Directed Medical Research Programs, Department of Defense) and US Department of Energy,...
View all posts by leizhang >

Lydia Kan

View all posts by Lydia Kan >

Related Articles

Capstone
Catching Fraud in the Healthcare System
Capstone
Acquisition Due Dilligence Automation for Smaller Firms
Machine Learning
Pandemic Effects on the Ames Housing Market and Lifestyle
Machine Learning
The Ames Data Set: Sales Price Tackled With Diverse Models
Meetup
Machine learning Uber vs. Lyft price prediction modeling

Leave a Comment

Cancel reply

You must be logged in to post a comment.

No comments found.

View Posts by Categories

All Posts 2399 posts
AI 7 posts
AI Agent 2 posts
AI-based hotel recommendation 1 posts
AIForGood 1 posts
Alumni 60 posts
Animated Maps 1 posts
APIs 41 posts
Artificial Intelligence 2 posts
Artificial Intelligence 2 posts
AWS 13 posts
Banking 1 posts
Big Data 50 posts
Branch Analysis 1 posts
Capstone 206 posts
Career Education 7 posts
CLIP 1 posts
Community 72 posts
Congestion Zone 1 posts
Content Recommendation 1 posts
Cosine SImilarity 1 posts
Data Analysis 5 posts
Data Engineering 1 posts
Data Engineering 3 posts
Data Science 7 posts
Data Science News and Sharing 73 posts
Data Visualization 324 posts
Events 5 posts
Featured 37 posts
Function calling 1 posts
FutureTech 1 posts
Generative AI 5 posts
Hadoop 13 posts
Image Classification 1 posts
Innovation 2 posts
Kmeans Cluster 1 posts
LLM 6 posts
Machine Learning 364 posts
Marketing 1 posts
Meetup 144 posts
MLOPs 1 posts
Model Deployment 1 posts
Nagamas69 1 posts
NLP 1 posts
OpenAI 5 posts
OpenNYC Data 1 posts
pySpark 1 posts
Python 16 posts
Python 458 posts
Python data analysis 4 posts
Python Shiny 2 posts
R 404 posts
R Data Analysis 1 posts
R Shiny 560 posts
R Visualization 445 posts
RAG 1 posts
RoBERTa 1 posts
semantic rearch 2 posts
Spark 17 posts
SQL 1 posts
Streamlit 2 posts
Student Works 1687 posts
Tableau 12 posts
TensorFlow 3 posts
Traffic 1 posts
User Preference Modeling 1 posts
Vector database 2 posts
Web Scraping 483 posts
wukong138 1 posts

Our Recent Popular Posts

AI 4 AI: ChatGPT Unifies My Blog Posts
by Vinod Chugani
Dec 18, 2022
Meet Your Machine Learning Mentors: Kyle Gallatin
by Vivian Zhang
Nov 4, 2020
NICU Admissions and CCHD: Predicting Based on Data Analysis
by Paul Lee, Aron Berke, Bee Kim, Bettina Meier and Ira Villar
Jan 7, 2020

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans 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 boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day ChatGPT citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay football gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income industry Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis 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 seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI

NYC Data Science Academy

NYC Data Science Academy teaches data science, trains companies and their employees to better profit from data, excels at big data project consulting, and connects trained Data Scientists to our industry.

NYC Data Science Academy is licensed by New York State Education Department.

Get detailed curriculum information about our
amazing bootcamp!

Please enter a valid email address
Sign up completed. Thank you!

Offerings

  • HOME
  • DATA SCIENCE BOOTCAMP
  • ONLINE DATA SCIENCE BOOTCAMP
  • Professional Development Courses
  • CORPORATE OFFERINGS
  • HIRING PARTNERS
  • About

  • About Us
  • Alumni
  • Blog
  • FAQ
  • Contact Us
  • Refund Policy
  • Join Us
  • SOCIAL MEDIA

    © 2025 NYC Data Science Academy
    All rights reserved. | Site Map
    Privacy Policy | Terms of Service
    Bootcamp Application