Artificial Intelligence 8 min read

Turning Metrics into Music: A Sensitivity & Specificity Song Explained

This article showcases an AI‑generated song that teaches the four core classification metrics—sensitivity, specificity, precision, and recall—by presenting lyrical explanations, a confusion‑matrix overview, Python code for MIDI creation, and a step‑by‑step guide to producing the final video.

Model Perspective
Model Perspective
Model Perspective
Turning Metrics into Music: A Sensitivity & Specificity Song Explained

Four Key Metrics Overview

The four essential evaluation metrics— Sensitivity , Specificity , Precision , and Recall —originate from the confusion matrix, which compares model predictions with actual outcomes.

Sensitivity (also called Recall) measures the proportion of true positives correctly identified: TP / (TP + FN) . Specificity measures the proportion of true negatives correctly identified: TN / (TN + FP) . Precision measures the proportion of predicted positives that are truly positive: TP / (TP + FP) . Recall is identical to Sensitivity.

A concise table summarises each metric:

Sensitivity : numerator TP, denominator TP + FN – “how many actual positives you got right”.

Specificity : numerator TN, denominator TN + FP – “how many actual negatives you got right”.

Precision : numerator TP, denominator TP + FP – “how many predicted positives are truly positive”.

Recall : numerator TP, denominator TP + FN – same as Sensitivity.

Song Lyrics (Chinese and English)

Chinese version: 灵敏度,是一个比例,指实际阳性被正确预测。特异度,是另一个比例,指实际阴性被准确识别。精确率,它有些不同,是预测阳性中被命中的比例。而召回率,把我们带回起点——其实就是……灵敏度!

English version: Sensitivity is the percentage of actual positives correctly predicted. Specificity is the percentage of actual negatives correctly predicted. Precision is something different – it’s the percentage of predicted positives that are correctly predicted. And recall gets us back to the start — it’s the same as sensitivity!

AI Creation Process

The author used the book “StatQuest图解机器学习” as inspiration, then generated a melody with Python’s midiutil library. The full script is shown below.

<code>from midiutil import MIDIFile

# Create a MIDI file
midi = MIDIFile(1)
track = 0
time = 0
tempo = 120
channel = 0
volume = 100

midi.addTrackName(track, time, "Recall Song")
midi.addTempo(track, time, tempo)

# Notes (G major, simplified rhythm)
notes = [
    ("G4", 1), ("G4", 1), ("A4", 1), ("G4", 1),
    ("F#4", 1), ("G4", 1), ("A4", 2), ("A4", 1), ("B4", 1), ("A4", 1),
    ("G4", 1), ("A4", 1), ("B4", 2),
    ("G4", 1), ("G4", 1), ("A4", 1), ("G4", 1),
    ("F#4", 1), ("G4", 1), ("A4", 2), ("A4", 1), ("B4", 1), ("A4", 1),
    ("G4", 1), ("A4", 1), ("B4", 2), ("G4", 1), ("A4", 1), ("B4", 2),
    ("G4", 2), ("G4", 2), ("A4", 1), ("A4", 1), ("B4", 1), ("A4", 1),
    ("G4", 1), ("A4", 1), ("B4", 2), ("A4", 1), ("G4", 1), ("A4", 1)
]

note_mapping = {
    "C4": 60, "C#4": 61, "D4": 62, "D#4": 63, "E4": 64, "F4": 65, "F#4": 66,
    "G4": 67, "G#4": 68, "A4": 69, "A#4": 70, "B4": 71,
    "C5": 72, "C#5": 73, "D5": 74, "D#5": 75, "E5": 76, "F5": 77, "F#5": 78,
    "G5": 79, "G#5": 80, "A5": 81, "A#5": 82, "B5": 83
}

current_time = 0
for note_name, duration in notes:
    pitch = note_mapping[note_name]
    midi.addNote(track, channel, pitch, current_time, duration, volume)
    current_time += duration

with open("recall_song_accompaniment.mid", "wb") as output_file:
    midi.writeFile(output_file)
</code>

Because the author could not sing, an AI voice platform called “即梦” was used. The platform accepts lyrics + style to generate a short video with a digital avatar singing. The free tier limits each clip to 15 seconds, so the 50‑second song was split into four parts and later spliced together using a video editor.

AI avatar generation
AI avatar generation

Recommended Tools and References

Free audio‑cutting tool: https://cdkm.com/cn/cut-audio

Books that inspired the project:

StatQuest图解机器学习 (the primary source of the song)

漫画机器学习小抄 (a visual, card‑style introduction to ML)

巧用ChatGPT进行数学建模 (the author’s own book on using AI for mathematical modeling)

Anyone interested in using AI to create educational content can start by reproducing this song.

machine learningPythonevaluation metricsspecificityMIDIAI musicsensitivity
Model Perspective
Written by

Model Perspective

Insights, knowledge, and enjoyment from a mathematical modeling researcher and educator. Hosted by Haihua Wang, a modeling instructor and author of "Clever Use of Chat for Mathematical Modeling", "Modeling: The Mathematics of Thinking", "Mathematical Modeling Practice: A Hands‑On Guide to Competitions", and co‑author of "Mathematical Modeling: Teaching Design and Cases".

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.