Menu
CoddyTech

Clinic Survey

Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 64 of 64.

A clinic asked 48 patients about their visit: age, visit type, minutes waited and satisfaction, from poor to excellent. It is all in clinic.csv.

What drives satisfaction? Two columns are text, so encode them first. Satisfaction has an order; visit types do not:

One patient's row before and after encoding: age 58, visit follow-up, wait 30, satisfaction good becomes age 58, wait 30, satisfaction 3, then 0, 1, 0 in three visit columns for checkup, follow-up and urgent

Then every column is a number, and one heatmap shows how everything relates. The manager also wants a report per visit type and the least satisfied age group.

challenge icon

Challenge

Hard

The program reads a visit type. Round to 2 decimals.

  1. Map satisfaction to 1 to 4, one-hot visit into encoded (dtype=int), keep its correlations.
  2. For the visit type: its visits, mean wait and satisfaction, and the share unhappy (2 or less) among them and overall.
  3. Bin ages at 17, 34, 54, 85 as 18-34, 35-54, 55-85; print the least satisfied.
  4. Draw the matrix: coolwarm from -1 to 1, a color bar, column names on both axes, title Clinic Survey.

For another clinic and urgent:

urgent: 16 visits, mean wait 30.44, mean satisfaction 2.44
Unhappy after urgent: 0.56 (overall 0.33)
Least satisfied: 35-54 (2.6)

A heatmap titled Clinic Survey with a color bar from -1 to 1 and the six column names on both axes: age, wait_min, satisfaction, visit_checkup, visit_follow-up, visit_urgent; red diagonal, wait_min and satisfaction a deep blue pair

After your lines, Coddy describes your heatmap.

Try it yourself

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

visit = input()
df = pd.read_csv("clinic.csv")

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Statistics for ML

Practice on your own: Online Python compiler