CHAPTER 4
PROBLEM DEFINITION & PROPOSED METHOD
4.1 Prediction Models
In order to find our goal, our methodology contains a number of stages which we are
explaining below:
A. Datasets & Properties
B. Data Preprocessing
C. Apply Different Machine Learning Techniques
D. Finding Performance Measures
For better understanding we are explaining it in form of process flow diagram which is
given below:
Real Time Problem
Relevant Data Collection Health Data Storage
Data Preprocessing
Training Dataset Testing Dataset
Apply ML Model
Performance Result
Figure 4.1: Proposed Process Flow
1
Dataset & Properties
Table 4.1 Properties Description
S.N0: Properties Remark
1 Age Age of Individuals
2 Sex Sex Categories of Individuals.
3 BMI Body Mass Index
4 Children Number of Children out of Total (Numbers)
5 Smokers Behaviours of General People
6 Region Region categorization Based upon Geographical
location.
7 Expenses Expenditure Amounts.
Data Processing
As a researcher we all know that we have two types of data Numerical Data and Nominal
Data. Both data has specific work in their field sometimes we have to convert one form to
another form. Here we are converting from Numerical Data to Nominal Data.
The patient’s age is classified into three categories
Table 4.2 Data Conversion
S. No Classification Numerical Value
1 Young 10-25 years
2 Adult 26- 50 years
3 Old (Above 50 years)
Apply Machine Learning
When our Data is ready for using by any ML Techniques to create Model. Here we are
Applying Number of Machine Learning Algorithms for finding better Results.
2
Apply Performance Measure
By using following equations, we can find many Evaluation Parameters some of them is
given below:
TP
Precision: Precision=
TP+ FP
TP
Recall: Recall=
TP+ FN
2∗recall∗precision
F-measure F−measures=
precision+recall
TP+TN
Accuracy: Accuracy=
TP+TN + FP+ FN
3
4.2 Algorithms
Step 01: Store Data from Kaggle Repository
Step 02: Import Prior Libraries:
# For mathematical operations
import numpy as np
# For dataframe manipulations
import pandas as pd
# For data visualizations
import seaborn as sns
import [Link] as plt
import [Link] as px
Step03: Now Import our Required Dataset
# Let’s read the data set
data = pd.read_csv('[Link]')
data. shape
Step04: Apply Feature Extraction
a) Bivariate Analysis
# Let’s understand the impact of age on Medical Expenses
px. scatter (data, y = 'expenses',
x = 'age',
marginal_y = 'violin',
trendline = 'ols')
b) Multivariate Analysis
# As we 4 and 5 children are having similar impact on expenses
# So, let's cap these values
data['children'] = data['children']. replace ((4, 5), (3, 3))
4
data['children'].value_counts ()
Step 05: Visualize Data for better understanding
a) Descriptive Features
# let’s check the descriptive summary
data. Describe (). style. background gradient (cmap = 'Greens')
b) Distribution of Different Features
[Link](1, 3, 1)
[Link](data['age'], color = 'black')
[Link]('Age')
[Link]()
Step06: Applying Machine Learning Algorithms
Step07: Apply Different Model
a) Linear Regression
# Let’s create the Model
# Let’s create a simple Linear Regression Model
from sklearn.linear_model import LinearRegression
model1 = LinearRegression()
b) Random Forest
# lets create a Random Forest Model
from [Link] import RandomForestRegressor
model2 = RandomForestRegressor()
[Link](x_train, y_train)
c) Gradient Boosting
# Let’s create a Gradient Boosting Model
from [Link] import GradientBoostingRegressor
model3 = GradientBoostingRegressor()
[Link](x_train, y_train)
Step08: Repeat Step07 for many times with different Algorithms
Step09: Finally Compare Results with performance parameters like RMSE Score & R2
Score.
5
4.3 Flow Diagram of proposed methodology
Input Dataset
Preprocessing Numerical to nominal
Desired Data
Training Data Applied
Repeat
No
Repeat for
next Data
Yes
App. Different Algo 1. Linear Regression
2. Random Forest
3. Gradient Boosting with Weighted Average va
Performance Parameter
RMSE Score & R2 Score
Evaluate Final Comparison
6
Figure 4.2: Flow of Operation
In figure 4.2 At first step, we need to fetched Data from any external source or we can
collect Data from Local Market but for better Analysis we are Fetching our Data from
Kaggle. That is very reliable Data Source through Word Wide. In Next Step we need to
Fetched Different Libraries for processing our Data. At very next Step that is Third Step
we need to process our Data for next step Here we have many processing Mechanism.
We are using Numerical to Nominal Data Conversion or also using Uni-Variant and
Multi-Variant Data Processing. At Next Step i.e., Fourth Step we need to repeat it for
different Data split. Then after we will reach at step 5 where we will apply Different
Machine Learning Algorithms and Finally, we will apply our own Proposed Methods i.e.,
Gradient Boosting with Weighted Average values. Here we will adding average values of
previous implemented mechanism. At Final Step i.e., Sith step we will have to find
Performance Measures i.e., RMSE Score & R2 Score will give clear views of proposed
method and Existing one. At Final Step we will compare these given Results. We can say
that Our Proposed Methods gives better Result.
7
8