0% found this document useful (0 votes)
8 views24 pages

Insurance Fraud Detection Using Machine Learning

The document outlines a project for detecting insurance fraud using machine learning, detailing the process from problem definition to model deployment. It includes steps for data collection, preparation, exploratory data analysis, model building, and performance testing. The project aims to create a predictive system to distinguish between fraudulent and legitimate insurance claims, utilizing various machine learning algorithms.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views24 pages

Insurance Fraud Detection Using Machine Learning

The document outlines a project for detecting insurance fraud using machine learning, detailing the process from problem definition to model deployment. It includes steps for data collection, preparation, exploratory data analysis, model building, and performance testing. The project aims to create a predictive system to distinguish between fraudulent and legitimate insurance claims, utilizing various machine learning algorithms.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INSURANCE FRAUD DETECTION USING

MACHINE LEARNING
Project Hand-out, Faculty Development Program – NaanMudhalvan

SmartInternz
[Link]
Insurance Fraud Detection Using Machine Learning
Insurance are claimed in order to get a relief amount for any damage cause. Insurance is a means of
protection from financial loss , but now-a-days Many people are claiming the Insurance by fraud claims. It
can be called as a scam. It is called as fraud claim when a claimant attempts to obtain some benefit or
advantage they are not entitled to, or when an insurer knowingly denies some benefit that is due.
These type of Insurance claims cause loss to the company. So, It is necessary to detect the claims
which are fraud. The number of cases of insurance fraud that are detected is much lower than the number
of acts that are actually committed. So the main purpose of the Insurance Fraud Detection system is to
predict the Insurance claim is a Fraud or Legal Claim based on the different appeals and parameters.

Technical Architecture:

[Link] Page 1 of 22
Project Flow:
● User interacts with the UI to enter the input.
● Entered input is analysed by the model which is integrated.
● Once model analyses the input the prediction is showcased on the UI

To accomplish this, we have to complete all the activities listed below,

● Define Problem / Problem Understanding


○ Specify the business problem
○ Business requirements
○ Literature Survey
○ Social or Business Impact.
● Data Collection & Preparation
○ Collect the dataset
○ Data Preparation
● Exploratory Data Analysis
○ Descriptive statistical
○ Visual Analysis
● Model Building
○ Training the model in multiple algorithms
○ Testing the model
● Performance Testing & Hyperparameter Tuning
○ Testing model with multiple evaluation metrics
○ Comparing model accuracy before & after applying hyperparameter tuning
● Model Deployment
○ Save the best model
○ Integrate with Web Framework
● Project Demonstration & Documentation
○ Record explanation Video for project end to end solution
○ Project Documentation-Step by step project development procedure

[Link] Page 2 of 22
Prior Knowledge:
You must have prior knowledge of following topics to complete this project.
∙ ML Concepts
o Supervised learning: [Link]
o Unsupervised learning: [Link]
∙ Decision tree: [Link]
algorithm
∙ Random forest: [Link]
∙ KNN: [Link]
∙ Xgboost: [Link]
understand-the-math-behind-xgboost/
∙ Evaluation metrics: [Link]
evaluation-error-metrics/
∙ Flask Basics : [Link]

Project Structure:
Create the Project folder which contains files as shown below

● We are building a flask application which needs HTML pages stored in the templates folder and a
python script [Link] for scripting.
● Dtc_model.pkl is our saved model. Further we will use this model for flask integration.
● Data Folder contains the Dataset used
● The Notebook file contains procedure for building th model.

[Link] Page 3 of 22
Milestone 1: Define Problem / Problem Understanding
Activity 1: Specify the business problem
Refer Project Description

Activity 2: Business requirements

A drug classification project can have a variety of business requirements, depending on


the specific goals and objectives of the project. Some potential requirements may include:
∙ Accurate and up-to-date information: The project should use the most recent and
reliable data to classify drugs, in order to ensure that the information is accurate
and relevant to current medical practices.
∙ Flexibility: The classification system should be flexible and able to adapt to new
drugs and changing information as it becomes available.
∙ Compliance: The project should comply with all relevant laws and regulations,
such as FDA guidelines for classifying drugs.
∙ User-friendly interface: The classification system should be easy to use and
understand for both medical professionals and patients.

Activity 3: Literature Survey (Student Will Write)

A literature survey for a drug classification project would involve researching and
reviewing existing studies, articles, and other publications on the topic of drug
classification. The survey would aim to gather information on current classification
systems, their strengths and weaknesses, and any gaps in knowledge that the project
could address. The literature survey would also look at the methods and techniques used
in previous drug classification projects, and any relevant data or findings that could inform
the design and implementation of the current project.

Activity 4: Social or Business Impact.

Social Impact :- Improved patient care: By providing accurate and up-to-date information
on drugs, a drug classification project can help healthcare professionals make more
informed decisions about treatment options, leading to improved patient care.
Business Model/Impact :- New drug development: By providing information on the
properties and interactions of different drugs, a drug classification project can assist in the
development of new treatments and therapies.

[Link] Page 4 of 22
Milestone 2: Data Collection & Preparation
ML depends heavily on data. It is the most crucial aspect that makes algorithm training possible. So, this
section allows you to download the required dataset.

Activity 1: Collect the dataset


There are many popular open sources for collecting the data. Eg: [Link], UCI repository, etc.

In this project we have used .csv data. This data is downloaded from [Link]. Please refer to
the link given below to download the dataset.

Link: [Link]

As the dataset is downloaded. Let us read and understand the data properly with the help of some
visualisation techniques and some analysing techniques.
Note: There are a number of techniques for understanding the data. But here we have used
some of it. In an additional way, you can use multiple techniques.

Activity 1.1: Importing the libraries


Import the necessary libraries as shown in the image. (optional) Here we have used
visualisation style as fivethirtyeight.

Activity 1.2: Read the Dataset


Our dataset format might be in .csv, excel files, .txt, .json, etc. We can read the dataset with
the help of pandas.

In pandas we have a function called read_csv() to read the dataset. As a parameter we have
to give the directory of the csv file.

[Link] Page 5 of 22
● For checking the null values, [Link]().any( ) function is used. To sum those null
values we use .sum() function. From the below image we found that there are no
null values present in our dataset. So we can skip handling the missing values
step.

Activity 2: Data Preparation

As we have understood how the data is, let's pre-process the collected data.
The download data set is not suitable for training the machine learning model as it might have so
much randomness so we need to clean the dataset properly in order to fetch good results. This
activity includes the following steps.

● Handling missing values


● Handling Outliers
Note: These are the general steps of pre-processing the data before using it for machine learning.
Depending on the condition of your dataset, you may or may not have to go through all these
steps.

Activity 2.1: Handling missing values

● For checking the null values, [Link]().any( ) function is used. To sum those null values
we use .sum() function. From the below image we found that there are no null values
present in our dataset. So we can skip handling the missing values step.

[Link] Page 6 of 22
Activity 2.2: Handling Outliers
With the help of boxplot, outliers are visualized. And here we are going to find upper bound
and lower bound of policy_annual_premium feature with some mathematical formula.

∙ From the below diagram, we could visualize that policy_annual_premium feature has
outliers. Boxplot from seaborn library is used here.

∙ To find upper bound we have to multiply IQR (Interquartile range) with 1.5 and add it with
3rd quantile. To find lower bound instead of adding, subtract it with 1st quantile. Take
image attached below as your reference.

[Link] Page 7 of 22
∙ To handle the outliers transformation technique is used. Here log transformation is used.
We have created a function to visualize the distribution and probability plot of
policy_annual_premium feature.

[Link] Page 8 of 22
Milestone 3: Exploratory Data Analysis

Activity 1: Descriptive statistical

Descriptive analysis is to study the basic features of data with the statistical process. Here
pandas has a worthy function called describe. With this describe function we can
understand the unique, top and frequent values of categorical features. And we can find
mean, std, min, max and percentile values of continuous features.

Activity 2: Visual analysis


Visual analysis is the process of using visual representations, such as charts, plots,
and graphs, to explore and understand data. It is a way to quickly identify patterns,
trends, and outliers in the data, which can help to gain insights and make informed
decisions.

Activity 2.1: Univariate analysis

In simple words, univariate analysis is understanding the data with single feature.
Here we have displayed two different graphs such as Piechart and countplot.
Seaborn package provides a wonderful function countplot. It is more useful for
categorical features. With the help of countplot, we can Number of unique values in
the feature. From the countplot we can say that there are only 247 fraud cases
reported in 1000 insurance claims.

[Link] Page 9 of 22
• Pie chart describes the composition of Incident Severity Feature. It describes the
35.4% of Minor damage cases and almost equal composition of Major Damage
and Total Loss and only 9% of Trivial Damage.
• From the below histogram we can say that ‘age’ Feature is almost Normally
distributed. Majority of Insurance claims are of age 30 to 50.

Activity 2.2: Bivariate analysis

To find the relation between two features we use bivariate analysis. Here we can
used barplot.

[Link] Page 10 of 22
∙ Barplot is used here. As a 1st parameter we are passing auto_year and as a
2nd parameter we are passing total_claim_amount.
∙ From the below plot you can understand that distribution of total_claim_amount
on auto_year.
∙ The Most of the claim amounts are of 50,000 to 60,000 from the years 1995 to
2015.

∙ From the below barplot we can able to figure that Females are more Insured
than Males across the different states.

Activity 2.3: Multivariate analysis

In simple words, multivariate analysis is to find the relation between multiple features.
Here we have used heatmap from seaborn package.

[Link] Page 11 of 22
∙ From the below image, we came to a conclusion that there are some features
which are highly correlated.
∙ The correlation between the months_as_customer and age is highly correlated
with 0.92 value .
∙ The features like total_claim_amount,injury_claim, property_claim,
vehicle_claim are also highly correlated.
∙ These Highly correlated features should be dropped.

Encoding the Categorical Features:

• The categorical Features are can’t be passed directly to the Machine Learning Model. So we convert
them into Numerical data based on their order. This Technique is called Encoding.
• Here we are importing Label Encoder from the Sklearn Library.
• Here we are applying fit_transform to transform the categorical features to numerical features.

[Link] Page 12 of 22
Splitting data into train and test

Now let’s split the Dataset into train and test sets. First split the dataset into x and y and then split the
data set
Here x and y variables are created. On x variable, df is passed with dropping the target variable. And on
y target variable is passed. For splitting training and testing data we are using train_test_split() function
from sklearn. As parameters, we are passing x, y, test_size, random_state.

Handling Imbalanced dataset

• Imbalanced data is a common problem in machine learning and data analysis, where the number of
observations in one class is significantly higher or lower than the other class. Handling imbalanced
data is important to ensure that the model is not biased towards the majority class and can
accurately predict the minority class.
• Here we are using SMOTE Technique.

Scaling

• Scaling is a technique used to transform the values of a dataset to a similar scale to improve
the performance of machine learning algorithms. Scaling is important because many machine
learning algorithms are sensitive to the scale of the input features.
• Here we are using Standard Scaler.
• This scales the data to have a mean of 0 and a standard deviation of 1. The formula is given by:
X_scaled = (X - X_mean) / X_std
Milestone 4: Model Building

Activity 1: Training the model in multiple algorithms


Now our data is cleaned and it’s time to build the model. We can train our data on different
algorithms. For this project we are applying three classification algorithms. The best model
is saved based on its performance.

Activity 1.1: Decision tree model


First Decision Tree is imported from sklearn Library then DecisionTreeClassifier
algorithm is initialised and training data is passed to the model with the .fit() function.
Test data is predicted with .predict() function and saved in a new variable. We can find
the Train and Test accuracy by X_train and X_test.

Activity 1.2: Random forest model


First Random Forest Model is imported from sklearn Library then RandomForestClassifier
algorithm is initialised and training data is passed to the model with .fit() function. Test
data is predicted with .predict() function and saved in a new variable. We can find the
Train and Test accuracy by X_train and X_test.

[Link] Page 13 of 22
Activity 1.3: KNN model
KNN Model is imported from sklearn Library then KNeighborsClassifier algorithm is
initialised and training data is passed to the model with .fit() function. Test data is
predicted with .predict() function and saved in new variable. For evaluating the model,
confusion matrix and classification report is done.

Activity 1.4: Logistic Regression model

Logistic Regression Model is imported from sklearn Library then Logistic Regression
algorithm is initialised and training data is passed to the model with .fit() function. Test
data is predicted with .predict() function and saved in new variable. For evaluating the
model, confusion matrix is done.

[Link] Page 14 of 22
Activity 1.5: Naïve Bayes model

Naïve Bayes Model is imported from sklearn Library then Naïve Bayes algorithm is initialised
and training data is passed to the model with .fit() function. Test data is predicted with
.predict() function and saved in new variable. We can find the Train and Test accuracy by
X_train and X_test.

Activity 1.6: SVM model

SVM Model is imported from sklearn Library then SVM algorithm is initialized and
training data is passed to the model with .fit() function. Test data is predicted with
.predict() function and saved in new variable. For evaluating the model, confusion
matrix and classification report is done.

Activity 2: Testing the model

Here we have tested with Decision Tree algorithm. You can test with all algorithm. With
the help of predict() function.

[Link] Page 15 of 22
Milestone 5: Performance Testing & Hyperparameter Tuning

Activity 1: Testing model with multiple evaluation metrics


Multiple evaluation metrics means evaluating the model's performance on a test set using
different performance measures. This can provide a more comprehensive understanding
of the model's strengths and weaknesses. We are using evaluation metrics for
classification tasks including accuracy, precision, recall, support and F1-score.

Activity 1.1: Compare the model

For comparing the above four models, the compareModel function is defined.

[Link] Page 16 of 22
After calling the function, the results of models are displayed as output. From the
above models Decision Tree is performing well.

Activity 2: Comparing model accuracy before & after applying


hyperparameter tuning (Hyperparameter tuning is optional. For this project
it is not required.)

Evaluating performance of the model From sklearn, cross_val_score is used to evaluate


the score of the model. On the parameters, we have given rf (model name), x, y, cv (as 5
folds). Our model is performing well.

Note: To understand cross validation, refer to this link

[Link] Page 17 of 22
Milestone 6: Model Deployment

Activity 1: Save the best model

Saving the best model after comparing its performance using different evaluation metrics
means selecting the model with the highest [Link] can be useful in avoiding
the need to retrain the model every time it is needed and also to be able to use it in the
future.

Activity 2: Integrate with Web Framework

In this section, we will be building a web application that is integrated to the model we
built. A UI is provided for the uses where he has to enter the values for predictions. The
enter values are given to the saved model and prediction is showcased on the UI.

This section has the following tasks

● Building HTML Pages


● Building server-side script
● Run the web application

Activity 2.1: Building Html Page:

For this project create HTML file namely


∙ [Link]

and save them in the templates folder. Refer this link for templates.

Activity 2.2: Build Python code:

Import the libraries

Load the saved model. Importing the flask module in the project is mandatory. An object of
Flask class is our WSGI application. Flask constructor takes the name of the current
module ( name ) as argument.

[Link] Page 18 of 22
Render HTML page:

Here we will be using a declared constructor to route to the HTML page which we have
created earlier.

In the above example, ‘/’ URL is bound with the [Link] function. Hence, when the
home page of the web server is opened in the browser, the html page will be rendered.
Whenever you enter the values from the html page the values can be retrieved using
POST Method.

Retrieves the value from UI:

[Link] Page 19 of 22
Here we are routing our app to predict() function. This function retrieves all the values from
the HTML page using Post request. That is stored in an array. This array is passed to the
[Link]() function. This function returns the prediction. And this prediction value will
be rendered to the text that we have mentioned in the [Link] page earlier.

Main Function:

Activity 2.3: Run the web application

● Open anaconda prompt from the start menu


● Navigate to the folder where your python script is.
● Now type “python [Link]” command
● Navigate to the localhost where you can view your web page.

● Click on the predict button from the top left corner, enter the inputs, click on
the submit button, and see the result/prediction on the web.

Now,Go the web browser and write the localhost url ([Link] to get the
below result

[Link] Page 20 of 22
[Link] Page 21 of 22
Milestone 7: Project Demonstration & Documentation

Below mentioned deliverables to be submitted along with other deliverables

Activity 1:- Record explanation Video for project end to end solution

Activity 2:- Project Documentation-Step by step project development


procedure

Create document as per the template provided

[Link] Page 22 of 22

Common questions

Powered by AI

EDA provides insights into dataset characteristics, identifying patterns, trends, and anomalies that inform data cleaning and transformation processes. This enhances data quality, ensuring that features contribute effectively to model training and reducing the risk of erroneous interpretations .

The business requirements for a drug classification project include using the most recent and reliable data for accuracy, flexibility to adapt to new drugs and information, compliance with laws and guidelines like FDA regulations, and a user-friendly interface. These requirements aim to improve patient care by aiding healthcare professionals in making informed treatment decisions and support new drug development by understanding drug properties and interactions .

Univariate analysis examines data distributions for a single feature, bivariate analysis explores relationships between two features, and multivariate analysis studies the interactions among multiple features. Each provides different levels of understanding about data patterns and correlations .

Feature encoding transforms categorical data into numerical form, allowing machine learning models to process these features effectively. Without encoding, models could misinterpret categorical data, leading to inaccurate predictions. Common techniques include one-hot encoding and label encoding .

Handling missing values ensures that the dataset does not have gaps that could lead to incorrect model predictions, while addressing outliers prevents skewed results that can affect the model's understanding of data patterns. Together, these preprocessing steps improve the model's accuracy by providing a cleaner and more representative dataset for training .

Imbalanced datasets can lead to biased models that favor majority classes, decreasing prediction reliability for minority classes. Techniques like SMOTE generate synthetic examples to balance class distributions, improving model performance and ability to predict minority class instances accurately .

Cross-validation evaluates a model's performance by testing its ability to generalize to independent data samples, reducing overfitting. It splits the data into training and testing sets multiple times and averages results to provide a robust assessment of model reliability .

Hyperparameter tuning optimizes a model's performance by adjusting its parameters, such as learning rates or number of trees in a random forest. This process can significantly improve model accuracy and efficiency, although it's not always required depending on initial model performance .

Visual analysis uses charts, plots, and graphs to explore data, quickly identifying patterns, trends, and outliers. It complements statistical methods by providing a more intuitive understanding of data, enabling quicker insights and more informed decisions without solely relying on numerical summaries .

Deploying a machine learning model with Flask involves saving the trained model, creating a web interface with HTML, and writing server-side scripts in Python to handle input and prediction processes. Finally, the application is run on a local server to enable interaction through a web browser .

You might also like