Skip to content
Edition NigeriaGlobal
Country

You are in the Nigeria edition. Type your country to switch.

Set up your profile

Financial Data Lab · Lesson 6 of 8

Lab 6: a sentiment classifier on sample headlines

This lab builds the simplest possible sentiment classifier, a word list that scores invented headlines as positive or negative, and measures it honestly with a confusion matrix, accuracy and precision. It then shows where word counting fails: negation, finance-specific meanings and headlines that are neutral.

Advanced10 min read5 steps

This lesson is complete in writing. A video for it is on its way.

What you will learn

  • By the end you can build a word-list sentiment classifier for headlines in a few lines of Python.
  • You can measure it honestly on headlines labelled by people, using accuracy and a confusion matrix.
  • You can work out precision and recall for one class from a confusion matrix.
  • You can explain why negation, finance-specific words and tuning on the test headlines lead to misleading results.

Key terms in this lesson

Sentiment analysis
Scoring text as positive, negative or neutral in tone. In finance it is applied to news, filings and call transcripts, and it often misreads context and negation.
Label
The answer a supervised model is trained to predict, such as whether a loan was repaid or next month's return. Choosing the label is a design decision that shapes everything the model learns.
Classification accuracy
The share of cases a classifier labels correctly. It can mislead when one class is much more common than another.
Confusion matrix
A table that compares a classifier's answers with the true labels, counting correct and incorrect results for each class. It shows which mistakes a model makes, which accuracy alone hides.
Overfitting
Tuning a model or strategy so closely to past data that it captures noise and fails on new data.
Test set
Data kept aside and not used to build or tune a model, so it gives an honest check of performance on unseen cases. It loses its value if it is used again and again.

Step 1 of 5

The simplest classifier there is

Opening this step…

Step 2 of 5

The labelled headlines and the code

This step opens when you finish the one above.

Step 3 of 5

Measuring it honestly

This step opens when you finish the one above.

Step 4 of 5

Where word counting fails

This step opens when you finish the one above.

Step 5 of 5

The tuning trap

This step opens when you finish the one above.

Key takeaways

The key takeaways open when you finish every step.

Lesson quiz

6 questions. You need 85% to pass.

The quiz opens when you finish every step.

Read first

Stockertim Learn is education. It explains how investing works and never recommends buying or selling anything.

Up next

Financial data & analyticsLab 7: watching a model overfitRead nowLab 7: watching a model overfitFinancial data & analytics · Advanced · 15 minFinancial data & analyticsLab 8: writing the model card an…Read nowLab 8: writing the model card and a reproducible notebookFinancial data & analytics · Advanced · 15 minFinancial data & analyticsBuilding a three-statement modelRead nowBuilding a three-statement modelFinancial data & analytics · Advanced · 15 minFinancial data & analyticsBuilding a DCF in a modelRead nowBuilding a DCF in a modelFinancial data & analytics · Advanced · 15 minGold, commodities & real assetsInflation hedges: what the evide…Read nowInflation hedges: what the evidence showsGold, commodities & real assets · Intermediate · 15 minBrand & marketingPaid, owned and earned mediaRead nowPaid, owned and earned mediaBrand & marketing · Beginner · 5 minFunds & ETFsMutual funds in Nigeria explainedRead nowMutual funds in Nigeria explainedFunds & ETFs · Beginner · 15 minTrading: risk, costs and processFX scams: fake platforms, accoun…Read nowFX scams: fake platforms, account managers and signal sellersTrading: risk, costs and process · Advanced · 15 minProjects, consulting & analysisDocumenting and prioritising req…Read nowDocumenting and prioritising requirementsProjects, consulting & analysis · Intermediate · 15 minAI & securityWhat AI and large language model…Read nowWhat AI and large language models are, and are notAI & security · Beginner · 15 minNGX & AfricaPensions in Nigeria: what is an …Read nowPensions in Nigeria: what is an RSA?NGX & Africa · Beginner · 15 minBonds & fixed incomeHigh-yield and emerging-market d…Read nowHigh-yield and emerging-market debt: default, recovery and currencyBonds & fixed income · Advanced · 15 min
English