Mctaba Labs logo
BootcampData ScienceThe WhiteboardProjectsEventsMasterclassesWebinarsLearn
Book CallApply

500+ developers already in the community

Get answers, find accountability partners, and stay ahead

Join Discord →
Mctaba Labs logo

Educating 1 million students in tech by 2030.

Programs

  • Coding Bootcamp in Nairobi
  • Data Science to AI Engineering
  • HighSchool Graduates Launchpad
  • AI & Business Automation
  • Corporate Training
  • Kids & Teens
  • McTaba Story & Mission
  • Full-Stack Curriculum
  • Course Pricing & Plans
  • Frequently Asked Questions

Resources

  • Join Discord Community
  • Tech Events in Nairobi
  • Masterclasses
  • Free Resources
  • Learn
  • Data Science Guides
  • African Payments Reference
  • Campus
  • Africa Tech Talent Report
  • Partner With Us
  • Start a Project
  • Software & AI Studio
  • Our Work
  • Outcomes

Contact Us

  • 124 Manyani East Road, Lavington, Nairobi
  • +254727795603
  • Book a Discovery Call

Office Hours:

Mon-Fri: 9am - 2pm EAT

Sat: 10am - 12pm EAT

© 2026 Mctaba Labs - A product of Edtech Industries. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy
  1. Learn
  2. Data Science in Kenya
  3. Build a Credit Score for a Chama from Contribution Records
Bonaventure OgetoBy Bonaventure Ogeto|Updated November 3, 2026

Last checked 3 November 2026

Build a Credit Score for a Chama from Contribution Records

Group the ledger by member to get three features: share of months paid, average days late and misses in the last three months. Combine them into a points score you can explain, then fit a logistic regression and compare. Get members' consent first and never let the score decide alone.

In this article

  1. 1. Start from the ledger the treasurer keeps
  2. 2. Features: three numbers per member
  3. 3. A transparent points score first
  4. 4. Then logistic regression
  5. 5. Fairness and consent

Start from the ledger the treasurer keeps

McTaba runs coding and data bootcamps in Kenya. This guide is written to be useful whether or not you ever join one.

A chama treasurer already holds a credit file: a notebook or a sheet showing who paid how much, in which month and how many days after the deadline. Before a loan from the pot, the group asks "will she repay?" This tutorial turns that gut feeling into numbers. It is one of the projects on our data science career map.

Credit scoring is also a capstone option in our Data Science to AI Engineering programme, so the method is worth learning properly.

Imagine a ledger for 60 pretend members over 12 months at KES 2,000 a month. Code generates it, so it is made up, and so is the loan outcome later. Real chama data needs the members' agreement, which we cover at the end.

import numpy as np
import pandas as pd

rng = np.random.default_rng(7)
rows = []
for i in range(1, 61):
    m = f"M{i:02d}"
    reliability = rng.uniform(0.3, 1.0)
    for month in range(1, 13):
        if rng.random() < reliability:
            late = int(rng.poisson((1 - reliability) * 8))
            rows.append((m, month, 2000, late))
        else:
            rows.append((m, month, 0, 0))
pay = pd.DataFrame(
    rows, columns=["member", "month", "paid", "days_late"])

Features: three numbers per member

FeatureWhat it shows
paid_shareShare of months with a payment
avg_days_lateHow late she is when she does pay
missed_last3Misses in the last three months, a sign of trouble now

Our Data Science to AI Engineering programme teaches this feature-building step in its machine learning phase.

g = pay.groupby("member")
feat = pd.DataFrame({
    "paid_share": g["paid"].apply(lambda s: (s > 0).mean()),
    "avg_days_late": pay[pay.paid > 0]
        .groupby("member")["days_late"].mean(),
    "missed_last3": pay[pay.month > 9]
        .groupby("member")["paid"].apply(lambda s: (s == 0).sum()),
}).fillna(0)

The fillna(0) handles a member who never paid and so has no lateness average. That choice flatters her on lateness, so the points score below leans mostly on paid_share.

Get weekly developer tips

Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.

No spam. Unsubscribe anytime.

A transparent points score first

feat["score"] = (
    60 * feat["paid_share"]
    + 25 * (1 - feat["avg_days_late"].clip(0, 10) / 10)
    + 15 * (1 - feat["missed_last3"] / 3)
).round()
print(feat.sort_values("score").head())

The score runs from 0 to 100. Sixty points reward paying on most months, 25 reward being on time, and 15 reward a clean last quarter. The weights are our judgement, not a law. Change them and see who moves.

Its strength is that a member can read it. "You lost 12 points because you missed two of the last three months" is an answer you can say aloud at a meeting. Start every scoring project here, because a model has to beat this baseline to earn its place.

Then logistic regression

A model needs a past outcome to learn from: did the member later fail to repay a loan? Here we make that outcome up, tied loosely to paid_share, so you can run the code. With a real chama you would take it from loan records.

from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score

p = 1 / (1 + np.exp(6 * (feat["paid_share"] - 0.55)))
feat["defaulted"] = (rng.random(len(feat)) < p).astype(int)

X = feat[["paid_share", "avg_days_late", "missed_last3"]]
y = feat["defaulted"]
Xtr, Xte, ytr, yte = train_test_split(
    X, y, test_size=0.3, random_state=1, stratify=y)
model = LogisticRegression(max_iter=1000).fit(Xtr, ytr)
print(model.coef_[0].round(2).tolist())
print(roc_auc_score(yte, model.predict_proba(Xte)[:, 1]))

A negative coefficient on paid_share says more months paid means lower default risk. roc_auc_score says how well the model ranks risky members above safe ones: 0.5 is a coin toss, 1.0 is perfect.

Sixty members is a tiny sample, so the test score swings with the random split. Treat it as a way to learn the steps. A real chama with a few dozen members cannot support a confident model, which is a finding too. For the metrics side of imbalance, see catching mobile money fraud with machine learning.

Fairness and consent

A score about a person is personal data. Kenya's Data Protection Act 2019 is enforced by the Office of the Data Protection Commissioner (checked on 3 November 2026). Before you score real members, do these five things.

  • Tell members what you will compute and why, and get their agreement.
  • Use the minimum: contribution history, not phone contacts or location.
  • Check the score for unfair patterns. A member who missed a month after a bereavement is not a bad borrower.
  • Keep a person in the loop. The score informs the committee and never decides alone.
  • Remove names before sharing the file. See how to anonymise personal data in Kenya.

To go further, try the same steps on your own records from your M-Pesa statement. If your chama or SACCO wants a scoring tool built, or you want to learn this with mentors, see our Data Science to AI Engineering programme, starting 11 January 2027.

Key Takeaways

  • ✓A contribution ledger gives three strong features: months paid, lateness and recent misses.
  • ✓Build the readable points score first. It is your baseline and your explanation.
  • ✓Small groups cannot support a confident model. Say so.
  • ✓Consent, minimum data and a human decision come before any score is used.

Frequently Asked Questions

Can a chama really use a credit score?
Yes, as one input to the committee. Contribution history is the data the group already trusts. Keep it explainable and keep people in the decision.
Why start with a points score instead of a model?
A points score can be read aloud to a member. It also sets a baseline: a model must beat it to be worth the extra complexity.
How many members do I need for logistic regression?
More than a typical chama has. With a few dozen people the result swings with each split of the data. Use the points score, and keep the model for larger groups or SACCOs.
Do I need consent to score members?
Treat it as required. A score about a person is personal data under the Data Protection Act 2019. Tell members what you compute and why, and record their agreement.

Learn data science on African data

KES 140,000

Data Science to AI Engineering: 5 months full time or 8 months part time, hybrid in Nairobi. Fraud, credit and M-Pesa data from Week 1, and every model deployed. Starts 11 January 2027.

See the Data Science programme

Need it live by next month? Our studio builds it

Related guides

  • Data Engineering Basics: Build a Pipeline with Airflow and Docker
  • Forecast a Shop's Stock from Till Data
  • Python for Data Science: Your First 30 Days

Keep reading

Analyse Your M-Pesa Statement in Python

Turn the PDF Safaricom emails you into a clean table, a spending breakdown and a chart, with code you can run on your own laptop.

Read more

Catching Mobile Money Fraud with Machine Learning

A fraud model on the public PaySim dataset, judged in shillings lost and wasted alarms rather than a single accuracy score.

Read more

Kenya's Data Protection Act for Data Scientists

The Act in plain words for people who handle customer data, then a pandas walk-through: salted hashes for phone numbers, generalised fields and a k-anonymity check.

Read more

The Statistics You Actually Need for Data Science

Five statistics ideas do most of the work in data jobs. Each one comes with a small worked example you can check on paper.

Read more

Explore related topics

Breaking Into Tech

Practical, no-nonsense guides for anyone looking to start or change their career in tech. From choosing your first language to acing interviews.

Tech Salary Data

Transparent salary data for tech roles in Africa and worldwide, updated regularly with real market research.

AI Skills & Tools

Practical AI knowledge for developers. Build your first agent, get good at RAG, and pick the right AI coding tools for real work.

Bonaventure Ogeto

Bonaventure Ogeto

Founder and CEO, Mctaba Labs

Software engineer for 8+ years. He runs a Nairobi studio that ships products on M-Pesa, WhatsApp and AI, and teaches what the studio ships. He holds a BSc in Mathematics and Computer Science.

More about the author