Skip to content

Instantly share code, notes, and snippets.

View jspoelstra's full-sized avatar

Jacob Spoelstra jspoelstra

View GitHub Profile
@jspoelstra
jspoelstra / titanic.ipynb
Created April 28, 2017 05:59
Titanic data exploration and age imputation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jspoelstra
jspoelstra / fraudperf.R
Last active May 21, 2019 19:50
Transaction Fraud Detection Performance Evaluation
# Utility function to use within AzureML for calculating useful account-level performance metrics
# for transaction fraud detection models. Each metric is calculated as a function of the score-cutoff
# used. These include:
#
# Account Detection Rate (ADR): what fraction of the fraud accounts received a score above the
# threshold at some point after the fraud started
# Value Detection Rate (VDR): From the point in time that the fist transaction scored above
# the threshold, what fraction of the losses could have been prevented.
#
# This code specifically calculates the effect of delayed action: it will calculate VDR for various scenarios,
@jspoelstra
jspoelstra / waking-every-server.md
Last active October 1, 2026 23:28
Coupon Collector

How many pings to wake every server?

By Jacob Spoelstra
Research and drafting assistance by Grok.

Several years ago a colleague asked me a question that looked like a five-minute calculation and was not.

We have 100 servers behind a load balancer. An incoming ping is sent to a server chosen uniformly at random. The servers sleep until pinged. If they are all asleep, how many pings do we need to send to have a 95% chance of having woken every one of them?

The naive answers are wrong in instructive ways. A hundred pings is nowhere near enough: the chance of covering all 100 servers in 100 pings is about $10^{-42}$. The expected number of pings is only about 519, but the mean is not a 95% guarantee. The distribution is skewed — the last few servers take most of the time — so the 95th percentile sits well above the mean.