Problem 4: Drop One of Two Highly Correlated Features
Easypython
Problem Description
Write a Python program that checks the correlation between two specific numeric columns, and if their correlation is above 0.9, drops one of them (your choice which), printing a message explaining the action taken.
Input
A DataFrame with two numeric columns to compare.
Output
A message indicating whether one column was dropped due to high correlation, and the resulting DataFrame.
Constraints
- Correlation threshold is fixed at 0.9.
Example Input
text{"square_footage": [1000,1500,2000], "num_rooms": [2,3,4]}
Example Output
textCorrelation between square_footage and num_rooms: 0.99 Dropping 'num_rooms' due to high correlation with 'square_footage'.
Concepts Covered
df.corr(), conditional logic, df.drop(columns=[...]).