TP10 - Model Refinement

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


Objective: In this lab, you will learn how to improve your model beyond linearity. Feature engineering such as Polynomial features, interaction terms, and regularization techniques can help you build more accurate models. These are what we will explore in this lab.


We will work with email spam dataset available at UCI Repository. The dataset contains proportions of various character features extracted from the email body and the target variable is whether the email is spam or not. Begin by importing the data.

# To do

1. Simple Logistic Regression

  • Check the distribution of the target variable. Inspect for missing, dupplicated data.
  • Verify that most input columns contain outliers.
  • Split the data into 80% training and 20% testing sets.
  • Standardize the input data. Build a logistic regression model called lg0 and fit it to the training data. Evaluate the model on the test data using accuracy score, recall, precision and f1 score. Explain what do these quantity mean.
# TODO

2. Feature Transformation for Logistic Regression

  • You saw from the previous section that the input columns are full of outliers. Let’s try to perform \(\sqrt{x}\) and \(\log(x)\) transformation to reduce the impact of those outliers.
  • Build two other models called lg_sqrt and lg_log using input columns with square root and log transformations respectively.
  • Evaluate the models on the test data using all the metrics above and compare them to the first model. Which model performs better?
# TODO

3. Feature Selection for Logistic Regression

  • From all the features you have build so far, compute the \(\eta^2\) correlation between those features both for original and the transformed features.
  • Select the features with \(\eta^2\) larger than some threshold value (you should try to find a good threshold using cross-validation on the training set) and build a new model called lg_select using only those selected features.
  • Evaluate the model on the test data using all the metrics above and compare them.
  • Which model performs better?
# TODO

Further readings