practicepython.in
python exercises
171 exercises

Data without the library

The arithmetic underneath machine learning, written out by hand. Not because you should ship your own f1_score — you should not — but because sklearn.metrics.f1_score does not tell you why it is undefined when the model predicts nothing, and pandas will happily scale your test set using statistics it should never have seen. No imports here: the concepts are the difficult part, and they are difficult in plain Python.

14 exercisesdifficulty 2–4~308 min in total
The last batch is smaller generators, the ragged final batch ~18 min Four numbers that describe a classifier true and false, positive and negative, counting in one pass ~18 min The average, and the other average mean versus median, the even-length middle ~18 min Squeezing a column into nought and one rescaling, the zero-range column ~18 min Ninety-nine per cent accurate and completely uselessdebug accuracy on rare events, the majority-class baseline ~20 min Perfect in validation, useless in productiondebug data leakage, fit on train, apply to test ~24 min Categories a model can actually add up categories are not numbers, a fixed vocabulary ~24 min Two numbers that disagree, and the one that combines them precision versus recall, undefined metrics ~24 min Holding some data back shuffling with a seed, reproducibility ~24 min Dividing by n, or by n minus one Bessel’s correction, sample versus population ~22 min How unusual is this number standardising, units of standard deviation ~20 min The same patient on both sides of the splitdebug group leakage, the unit of independence ~26 min Every row gets a turn at being the test set cross-validation, distributing a remainder ~26 min Turning scores into probabilities without overflowing numerical stability, exp overflow ~26 min