Coding portfolio / Responsible AI
Model monitoring baseline
I demonstrate a reproducible population stability index (PSI) calculation with explicit distribution checks and smoothing.
Educational reference implementation · synthetic example
Source code
"""Educational population stability index for aligned histogram counts."""
from math import log
def psi(expected, observed, epsilon=1e-6):
if len(expected) != len(observed) or not expected or epsilon <= 0:
raise ValueError("Use matching, non-empty histogram bins and positive epsilon")
if min(expected) < 0 or min(observed) < 0 or not sum(expected) or not sum(observed):
raise ValueError("Counts must be nonnegative with positive totals")
def smooth(values):
total = sum(values) + epsilon * len(values)
return [(v + epsilon) / total for v in values]
a, b = smooth(expected), smooth(observed)
return sum((q - p) * log(q / p) for p, q in zip(a, b))
if __name__ == "__main__":
assert psi([50, 50], [50, 50]) == 0
print(round(psi([50, 50], [70, 30]), 4))
How I approach the implementation
I keep the core logic reproducible, separate test data from implementation and document assumptions before using the approach in production.
Run this example
python model_monitoring.py
These are illustrative educational samples created for this portfolio, not employer-owned code or production-ready security controls.
LET'S CONNECT
Let’s build something with AI.
I welcome conversations about enterprise AI, strategic advisory, executive leadership and research collaboration.
puneett.bhatnagr@gmail.com- AI engineering and enterprise architecture
- Responsible AI and model risk
- Executive opportunities and consulting
- Research and technical collaboration
TRUSTED AI BY DESIGN