Bayesian Knowledge Tracing, Explained with Code
How EduVision estimates what a student knows from noisy answers - four parameters, two equations and a dozen lines of Python.
A tutor has to answer one question over and over: does this student know this skill yet? We cannot observe knowledge directly - only answers, and answers are noisy. Students guess correctly and slip on things they know.
Bayesian Knowledge Tracing (BKT) treats mastery as a hidden variable and updates a probability after every answer. It is the Learner Engine in EduVision.
Four parameters
| Parameter | Meaning | EduVision default |
|---|---|---|
| Probability the skill is known before practice | 0.1 | |
| Probability of learning during one attempt | 0.1 | |
| Guess: correct answer without knowing | 0.2 | |
| Slip: wrong answer despite knowing | 0.1 |
Step 1 - update on evidence
After a correct answer, Bayes' rule gives:
After an incorrect answer:
Step 2 - account for learning
The attempt itself is a learning opportunity, so some probability mass moves from "not known" to "known":
The implementation
L_prev = skill.p_mastery
if is_correct:
numerator = L_prev * (1 - skill.p_slip)
denominator = numerator + (1 - L_prev) * skill.p_guess
else:
numerator = L_prev * skill.p_slip
denominator = numerator + (1 - L_prev) * (1 - skill.p_guess)
L_given_evidence = numerator / (denominator + 1e-10)
L_new = L_given_evidence + (1 - L_given_evidence) * skill.p_learn
skill.p_mastery = min(0.99, max(0.01, L_new))The final clamp to [0.01, 0.99] matters: a probability of exactly 0 or 1 can never move again, no matter what the student does next.
Why BKT and not a neural model?
Deep knowledge tracing models can be more accurate on large datasets, but BKT has properties that matter inside a tutor:
- Interpretable - four numbers per skill that a teacher can reason about.
- Cheap - one constant-time update per answer, no GPU.
- Data-efficient - sensible from the very first answer.
In EduVision the mastery estimate feeds the reinforcement-learning agent that decides whether the next problem should be easier, the same, or harder.