ACCT 350 · Data Analytics for Accountants

Classification and Clustering in Plain English

Two machine-learning ideas explained without jargon: sorting records into known labels, and letting the data reveal its own groups.

Key takeaways

  • Classification predicts a known label (late or on time, fraud or not) from past examples that already carry the answer.
  • Clustering finds groups in data that has no labels, so a person has to name and judge the groups afterward.
  • Always compare a model to the dumbest possible guess; high accuracy can be meaningless when one outcome is rare.
  • Precision and recall measure two different kinds of error, and which one matters depends on the cost of each mistake.
  • A model learns from the past, so it can repeat old mistakes and old biases; a person must stay in charge of what it is used for.

Every month Maya sends out invoices from her smoothie business, and every month a few customers pay late. Her bookkeeper, Dev, wishes he could know in advance which ones. If he did, he could send a friendly reminder early, or ask for a deposit. He has three years of invoices, and for each one he knows whether it was paid on time.

That is a classification problem: sort each new record into one of a few labels that you already know, using what past records taught you. Now suppose a different question. Maya has 600 customers and wonders whether they fall into natural groups she has never noticed. Nobody has labeled them. That is a clustering problem: find the groups that the data itself suggests.

These two ideas power a lot of what people call "machine learning." This lesson explains both in plain words, works out the arithmetic by hand, and shows where each can mislead you.

Two kinds of learning

Think about how you learned to tell dogs from cats as a small child. Someone pointed and said "dog" or "cat" again and again. After enough examples, you could label a new animal you had never seen. That is supervised learning: examples come with the right answers, like a teacher marking homework. Classification belongs here.

Now imagine you were dropped into a market full of fruit you had never seen and nobody spoke your language. You would still sort the fruit, perhaps by color and size, into piles that feel natural. Nobody gave you labels. That is unsupervised learning, and clustering belongs here.

Classification and clustering side by side
Classification You already know the labels, such as late or on time Learns from past records that carry the answer Output: a label for each new record Example: will this invoice be paid late? Judged by how often it is right Clustering No labels exist yet Looks only at how similar the records are Output: groups that a person must name Example: what kinds of customers do we have? Judged by whether the groups are useful VS Classification You already know the labels, such as late or on time Learns from past records that carry the answer Output: a label for each new record Example: will this invoice be paid late? Judged by how often it is right Clustering No labels exist yet Looks only at how similar the records are Output: groups that a person must name Example: what kinds of customers do we have? Judged by whether the groups are useful

The big difference is whether the right answers are known before you start.

Neither idea is magic. Both are ways to turn many rows of past data into a rule or a grouping that you can apply to the next row. The earlier lesson Regression and Forecasting in Accounting predicted a number, such as next quarter's sales. Classification predicts a category instead.

How a simple classifier thinks

The easiest classifier to picture is a decision tree, which is a series of yes-or-no questions. Dev looks at his past invoices and notices that late payers tend to share a few traits. A tree asks about those traits one at a time.

A tiny tree for predicting late payment
High risk Remind early Low risk Normal terms Over $2,000 $2,000 or less New customer Ask for a deposit Medium risk Remind before due date Low risk Normal terms Paid late before Always on time Known customer Check payment history First order Repeat order New invoice arrives Will it be paid late? New invoice arrives Will it be paid late? First order: New customer Ask for a deposit Over $2,000: High risk Remind early $2,000 or less: Low risk Normal terms Repeat order: Known customer Check payment history Paid late before: Medium risk Remind before due date Always on time: Low risk Normal terms

Made-up rules for illustration. A real tree would be built from Dev's own data.

Software finds the questions and the cut-offs by trying many and keeping the ones that separate the late invoices from the on-time ones best. Other methods draw their lines in different ways, but the goal is the same: use what the record looks like to guess its label. In accounting, typical labels are paid late or on time, likely to default or not, an expense that is business or personal, a transaction that needs review or not, and a customer segment.

Computers also need numbers. A trait such as "paid late before" is turned into a 1 or a 0. A plain-text description such as "taxi" is turned into a code. Getting data into a clean, usable shape is the work you saw in Getting and Cleaning Accounting Data, and it usually takes longer than building the model.

Worked example: is the model any good?

Dev builds a classifier and tests it on 100 invoices that the model has never seen. He knows the real outcomes, so he can score it. For each invoice there are four possibilities:

The four possible results of each guess
Caught: 20 Said late, was late. A true positive. False alarm: 10 Said late, was on time. A false positive. Missed: 5 Said on time, was late. A false negative. Correct pass: 65 Said on time, was on time. A true negative. Caught: 20 Said late, was late. A true positive. False alarm: 10 Said late, was on time. A false positive. Missed: 5 Said on time, was late. A false negative. Correct pass: 65 Said on time, was on time. A true negative.

Called a confusion matrix. Counts from Dev's test of 100 invoices.

Check the total: 20 + 10 + 5 + 65 = 100. Now three scores.

Accuracy  = right guesses / all guesses
          = (20 + 65) / 100 = 85%

Precision = of the ones flagged late, how many truly were?
          = 20 / (20 + 10) = 20 / 30 = about 66.7%

Recall    = of all the late ones, how many did we catch?
          = 20 / (20 + 5)  = 20 / 25 = 80%

Eighty-five percent sounds impressive. But look at how many invoices were really late: 20 + 5 = 25 of 100. A lazy "model" that says "everyone pays on time" would be right 75 times out of 100, which is 75% accuracy, with no skill at all and zero late invoices caught. Our model beat 75%, but only by 10 points. That is why you always compare to the dumbest guess. When one outcome is rare, accuracy hides a lot.

Precision and recall tell you different things. Precision answers: when the model raises its hand, how often is it right? Low precision means wasted work chasing false alarms. Recall answers: of all the real problems, how many did the model find? Low recall means problems slip through. The right balance depends on cost. Sending a reminder email to a good customer costs almost nothing, so a collections team may accept low precision to get high recall. An auditor who must investigate each flag by hand may want higher precision so the team's time is not wasted.

How clustering works

The most popular clustering method is called k-means. The letter k is just how many groups you ask for. The idea fits in four steps: pick k starting centers, assign each record to its nearest center, move each center to the average of its records, and repeat until nothing moves.

Let's cluster six of Maya's customers by how much each spends in a year, measured in hundreds of dollars: A spends 2 ($200), B spends 3, C spends 4, D spends 20, E spends 22 and F spends 24. Ask for two groups. As starting centers, pick the amounts of A (2) and C (4).

Round 1 (centers 2 and 4)
A: 2   distance to 2 is 0, to 4 is 2   -> group 1
B: 3   distance 1 and 1, a tie         -> group 1 (rule: ties go to group 1)
C: 4   distance 2 and 0                -> group 2
D: 20  distance 18 and 16              -> group 2
E: 22  distance 20 and 18              -> group 2
F: 24  distance 22 and 20              -> group 2
New centers: group 1 = (2 + 3) / 2 = 2.5
             group 2 = (4 + 20 + 22 + 24) / 4 = 70 / 4 = 17.5

Round 2 (centers 2.5 and 17.5)
A: 2   distance 0.5 and 15.5  -> group 1
B: 3   distance 0.5 and 14.5  -> group 1
C: 4   distance 1.5 and 13.5  -> group 1
D: 20  distance 17.5 and 2.5  -> group 2
E: 22  distance 19.5 and 4.5  -> group 2
F: 24  distance 21.5 and 6.5  -> group 2
New centers: group 1 = (2 + 3 + 4) / 3 = 3
             group 2 = (20 + 22 + 24) / 3 = 22

In round 3, no customer would switch, so the method stops. The small spenders A, B and C form one cluster centered on $300. The big spenders D, E and F form another centered on $2,200. Notice that the starting guess was poor, since C began in the wrong group, yet the method corrected itself.

Two clusters of customers
Yearly spend ($100s) Small-spender center Big-spender center A B C D E F Group 1 Group 2 Customer number Yearly spend ($100s) Small-spender center Big-spender center A B C D E F Group 1 Group 2 Customer number

Real clustering uses many traits at once, such as how much a customer buys, how often, how recently, and how fast they pay. The method is the same, only the distance is measured across several traits. If one trait is in dollars and another in days, the big numbers dominate, so analysts first put traits on a similar scale.

The hard part comes after. The computer says "group 1" and "group 2." A person must look at them and decide what they mean: "occasional small buyers" and "regular wholesale accounts." If you ask for three groups instead of two you will get a different answer, and the data will not tell you which is right. Judgment decides whether the grouping is useful. Clustering in accounting is also used to group similar vendors, spot expense claims that behave like no others, and segment customers for a pricing review, which connects directly to Analytics in Management Accounting.

A common mistake: trusting the model blindly

The most common mistakes are worth naming plainly.

Testing on the same data you learned from. A student who memorizes last year's exam will ace last year's exam and fail a new one. Always score the model on records it has never seen, as Dev did with his 100 invoices.

Ignoring how rare the thing is. Fraud, errors and defaults are rare. A model that never flags anything can have 99% accuracy. Look at precision and recall, not only accuracy.

Letting the past decide the future unfairly. A model learns from old decisions. If past loan or credit decisions were unfair to some group, a model trained on them can copy the unfairness while looking objective. Review what traits go in, and have a person check outcomes.

Treating a score as an explanation. "The model says high risk" is not a reason a customer or an auditor can accept. Prefer methods you can explain, and keep a note of what each model was built to do and when it was last checked.

Forgetting that behavior changes. A model built in a quiet year may not fit a recession. Recheck it on fresh data on a schedule.

None of this is a reason to avoid these tools. It is a reason to treat them like a smart but inexperienced new hire: useful, fast, and in need of supervision. Rules for who may use data and how are covered in Data Types, Quality and Governance.

Where accountants meet these tools

You will rarely build a model from scratch. More often you will use one that is built into your software, so your job is to ask good questions about it. What data was it trained on, and how recent is it? What does it get wrong, and how often? Who reviews its flags? Many expense systems already sort receipts into categories with classification. Many audit tools already cluster journal entries to show which ones look unlike the rest. In each case the model proposes and a person disposes.

A good habit is to keep a short written note for every model you rely on: its purpose, its inputs, its test scores, the date you last checked it, and the person who owns it. When an auditor, a manager or a customer asks "why did the system do that?", the note is your answer. Models are tools for focusing human attention, and the best use of one is to make sure the right person looks at the right record sooner.

Words to know

Classification sorting each record into one of several known labels, using what earlier labeled records showed.

Clustering grouping records by similarity when no labels exist, then asking a person to name the groups.

Supervised learning learning from examples that come with the right answers.

Decision tree a set of yes-or-no questions that leads each record to a predicted label.

Precision of the records the model flagged, the share that truly belonged in that group.

Recall of all the records that truly belonged in the group, the share the model found.

k-means a clustering method that moves group centers to the average of their records until nothing changes.

Check yourself

  1. What is the main difference between classification and clustering?
  2. In Dev's test, 20 late invoices were caught, 10 were false alarms, 5 were missed and 65 were correctly passed. Compute accuracy.
  3. Using the same counts, compute precision and recall.
  4. Why is 85% accuracy less impressive here than it first sounds?
  5. In the cluster example, why does customer C start in group 2 but end up in group 1?
  6. Explain why a model should be tested on records it has never seen.
Show the answers
  1. Classification uses known labels learned from past examples; clustering finds groups when no labels exist, and a person names them.
  2. Accuracy = (20 + 65) ÷ 100 = 85%.
  3. Precision = 20 ÷ (20 + 10) = 20 ÷ 30, about 66.7%; recall = 20 ÷ (20 + 5) = 20 ÷ 25 = 80%.
  4. Only 25 of 100 invoices were late, so a model that says "everyone pays on time" would score 75% with no skill; 85% beats that by just 10 points.
  5. C began as a center, so it was alone in group 2; once the group 1 average moved to 2.5 and group 2 moved to 17.5, C at 4 was 1.5 from group 1 but 13.5 from group 2, so it switched.
  6. A model can memorize its training records and look perfect on them, so only fresh records show whether it learned a real pattern that will hold for future invoices.

A free self-study program written for 4Accounting with AI writing tools and not reviewed line by line by a person. It is not an accredited degree and awards no credit. Check anything you rely on against a textbook or primary source. Report an error.

In this unit: Methods

  1. Descriptive Analysis of LedgersUse totals, averages, medians, groupings and trends to describe what a ledger says, and learn when each summary misleads.10 min
  2. Visualizing Financial DataChoose charts that show financial patterns honestly, avoid tricks like cut-off axes, and make each picture answer one clear question.11 min
  3. Regression and Forecasting in AccountingFit a straight line to past data, use it to forecast, and learn how to judge when a prediction can be trusted.10 min
  4. Finding Anomalies and Benford's LawLearn how auditors spot odd transactions, from simple outlier checks to the surprising pattern in first digits called Benford's Law.12 min
  5. Classification and Clustering in Plain EnglishTwo machine-learning ideas explained without jargon: sorting records into known labels, and letting the data reveal its own groups.12 min

In the news