Python for Data Science: Chapter 3: Foundations of Data Science

Data science process: 5. Build the Model

Importance, three main steps in the model building process

Questions: 1. What is model building in the data science process? Explain its purpose. 2. List and explain the three main steps in the model‒building process.

Data science process is a series of activities that help us move from a business problem to a useful solution based on data. 1. Define research goals 2. Data retrieval 3. Data preparation 4. Data exploration 5. Model building 6. Presenting results and automation


 

5. Build the Model

•  After cleaning, transforming and exploring the data the next step in data science process is to build a model.

•  Model building means using machine learning techniques. The machine learning techniques are required to ‒

(1) Make the predictions: For instance ‒ predicting prices of houses.

(2) Classify the objects: For instance ‒ Predicting if email is a spam or not.

(3) Understand the relationships: For instance ‒ how increase in the temperature affect the sale of ice‒creams.

 

Importance of model building

•  Following are some important reasons why we need to build the model in data science process ‒

1) To find patterns and relationship in data.

2) To predict future outcomes based on past data.

3) To make data driven decisions in business, health, finance, agriculture and other fields.

•  For example ‒ If we have data on student's study hours and exam scores then we can build the model and predict new student's score based on his number of hours of study.

•  Model building process is based on following three steps and these are ‒

1) Model and variable selection

2) Model execution

3) Model diagnostic and Comparison

•  Let us discuss them in detail

 

1. Model and Variable Selection

•  Before building the model we must choose –

i) Which variables need to be included and

ii) and which type of model is suitable to solve our problem.

1) Choosing variables

■  It is also called as feature selection. Note that not every column in the dataset is useful.

■  We should select variables that have a strong relationship with the output variable.

■  For example ‒ consider the dataset of "housing prices in Pune". This dataset we will use for predicting housing prices. There are variables such as house_ID, Photo, area(in sq.ft.), number of bedrooms, location. But the variables like house_ID and Photo are not useful. For predicting house price we must choose, the variables like area, number of bedrooms and location of that house.

■  We can find identify the important variables from the dataset from the Exploratory Data Aanalysis (EDA).

2) Choosing right model

■  There are several machine learning models. Each model has specific purpose.

■  For example: Linear regression model is used to predict the numeric values. For predicting categories(yes/no) the logistic regression model or decision tree model is used. For finding the patterns or clusters we use K‒means clustering model.

■ Before choosing the model we must think about ‒

a. Deployment: Can the model easily be implemented in production?

b. Maintenance: Will it still work overtime ?

c. Interpretability: Does the model need to be easy to explain to a non‒technical user?

 

2. Model Execution

• Once we have selected the model and variables, it's time to run or execute the model using the software.

• Normally the programming languages like Python, R are used to build the models.

• Python provides the libraries such as

Scikit‒learn: For regression, classification and clustering.

StatsModels: For statistical modeling.

• These models make it easy to build the models using pre‒written functions. For example ‒ In Python we can use Linear Regression model. The code fragment for this can be as follows ‒

from sklearn.linear_model import LinearRegression

model = LinearRegression()

model.fit(X,y)

 

3. Model Diagnostic and Comparison

• Once we build one or more models, we must check how well they perform and which model is best.

To check the reliability of the model, split your data into two parts:

Train Set: This set is used to build the model.

Test Set: This set is used to evaluate the performance.

For example ‒ We build a model and 70 % of the data is used as a train set and remaining 30% of the data is used for testing. If the model performs well on both, the model is considered to be reliable.

Evaluating model performance: We use error measures to check how far the model's predictions are from actual results. For instance ‒ Mean Squared Error(MSE) is average of squared prediction errors. Suppose our model predicts  ₹52,000 and the actual value is  ₹50,000. Then Error (52000 ‒ 50000)2 4,000,000. Smaller MSE means better performance.

 Model diagnostic: Models make assumptions, we must check if they are valid. For example ‒ Linear regression assumes independence of variables.

Model comparison: We often build multiple models and compare them. Then choose the one that:

■ Has the lowest error,

■ Fits unseen data well and

■ Meets your project's requirements such as accuracy, interpretability.

 

Review Questions

1. What is model building in the data science process? Explain its purpose.

2. List and explain the three main steps in the model‒building process.


 

Python for Data Science: Chapter 3: Foundations of Data Science : Tag: Computer Programming, Python, Data Science : Importance, three main steps in the model building process - Data science process: 5. Build the Model


Python for Data Science: Chapter 3: Foundations of Data Science



Under Subject


Python for Data Science

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Applied Physics (CSIE) II

PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Digital Principles and Computer Organization

CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electrical and Electronics Engineering

EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Python for Data Science

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Python for Data Science - Laboratory

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation