TP9 - Logistic Regression

Course: INF-604: Data Analysis I
Lecturer: Sothea HAS, PhD


Objective: In this lab, you will reproduce the result we have done in linear and logistic regression. Moreover, you will explore beyond what we have done including using multiple inputs variables, compare their performances and feature engineering to further elevate the model performance.


I. Logistic Regression

Cardiovascular diseases (CVDs) are the leading cause of death globally, taking an estimated 17.9 million lives each year (WHO). CVDs are a group of disorders of the heart and blood vessels and include coronary heart disease, cerebrovascular disease, rheumatic heart disease and other conditions. More than four out of five CVD deaths are due to heart attacks and strokes, and one third of these deaths occur prematurely in people under 70 years of age. This research intends to pinpoint the most relevant/risk factors of heart disease as well as predict the overall risk using logistic regression.

We will explore Kaggle Heart Disease Dataset. Load the dataset into the environment.

# To do

1. Data Preprocessing and EDA

A. Univariate Analysis

  • Check and modify if there is any column with wrong data type.
  • Are there any missing values in this dataset? If so, compute percentage of missing values within each column containing such values and properly handle them.
  • Compute descriptive statistics of the data and visualize their distribution.
  • Pick a few columns and describe their distribution.
# Todo

B. Bivariate Analysis

  • Compute correlation matrix among numerical columns.
  • Visualize relationship between each column to the target TenYearCHD.
  • Draft a list of columns that you think is most related to the target.
# To do

2. Build logistic regression models

A. Simple Logistic Regression Model

  • Split the data into \(80\%-20\%\) of training and testing data using train_test_split from sklearn.preprocessing module.
  • Should you standardize the data? Why?
  • Build a logistic regression model called lg0 using only one selected input to predict the target TenYearCHD.
  • Evaluate performance of the model built in the previous step using metrics such as accuracy, precision, recall and f1_score (from sklearn.metrics module).
  • Write down explicit formula of your model.
# To do

B. Multiple Logistic Regression Model

  • Build a logistic regression model (called lg1) to predict the target using just the columns drafted in part 1.B of bivariate analysis.
  • Measure its performance on the test data using all metrics.
  • Build another logistic regression model using all the columns (called lg2).
  • Compute its performance on the test data using all the metrics.
  • Given that the inputs are standardized, what column seems to impact the target the most? Interpret the value of its coefficient.
  • Conclude.

Further readings