Skip to content
CampusEduX

Problem 4: Check Class Balance with a Count Plot

Easypython
Learn the Concept: Seaborn

Problem Description

Write a Python program that uses sns.countplot() to visualize the class distribution of a binary target column, to check for imbalance.

Input

A DataFrame with a binary "target" column.

Output

A displayed bar chart showing the count of each class.

Constraints

  • At least 10 rows, with an imbalanced class distribution.

Example Input

text
{"target": [0,0,0,0,0,0,0,0,1,1]}

Example Output

text
(A bar chart showing 8 bars-worth of class 0 and 2 bars-worth of class 1, visually revealing the imbalance)

Concepts Covered

sns.countplot(), class balance visualization.

Related Problems

  • Problem 1: Create a Boxplot Grouped by Category
    Easy · python
    Solve Problem
  • Problem 2: Visualize a Correlation Matrix as a Heatmap
    Easy · python
    Solve Problem
  • Problem 3: Create a Scatter Plot with Categorical Coloring
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...