Homework

Homework — the accuracy curve as text

The accuracy curve — as a text chart.

Write a new file curve.py that trains a LinearClassifier for 10 epochs (seed 42, 10 000 images, batch 64, lr=0.1, as in train.py) and after each epoch prints one line: the epoch number, the accuracy, and as many # characters as make 100 % = 50 characters.

Do not change fit. A hint: you can call fit(model, loader, epochs=1, lr=0.1) ten times in a row — SGD keeps no memory of its own, so it is the same as a single epochs=10 call. fit prints its own lines; you can silence them with contextlib.redirect_stdout(io.StringIO()).

My machine:

epoch  1   74.4%  #####################################
epoch  2   75.2%  ######################################
epoch  3   81.3%  #########################################
epoch  4   82.4%  #########################################
epoch  5   77.2%  #######################################
epoch  6   79.7%  ########################################
epoch  7   84.0%  ##########################################
epoch  8   84.2%  ##########################################
epoch  9   79.5%  ########################################
epoch 10   84.1%  ##########################################

Why are the numbers not the same as train.py showed (74.0 … 85.1)? Because there is no evaluate before training here — that extra call changed the shuffle order.

Why it matters. Look at the curve and answer in one sentence: could you say with confidence that epoch 9 is "worse" than epoch 8? If you think so — re-read the remarks on noise in step 5. In lesson 7 the same question comes back with a different weapon: not "does accuracy climb", but "does it climb where it matters".