Skip to content
CampusEduX

Problem 2: Identify Features Most Correlated with the Target

Easypython
Learn the Concept: Feature Selection

Problem Description

Write a Python program that computes the correlation of all features with a target column ("price"), and prints them sorted from highest to lowest correlation.

Input

A DataFrame with several numeric feature columns and one target column.

Output

A sorted list of correlations with the target.

Constraints

  • The target column must be named "price".

Example Input

text
{"size": [1000,1500,2000], "rooms": [2,3,4], "price": [200000,280000,350000]}

Example Output

text
price 1.000000 size 0.998... rooms 0.995...

Concepts Covered

df.corr(), sort_values().

Related Problems

  • Problem 1: Compute and Display a Correlation Matrix
    Easy · python
    Solve Problem
  • Problem 3: Remove Low-Variance Features
    Easy · python
    Solve Problem
  • Problem 4: Drop One of Two Highly Correlated Features
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...