Can someone please explain what this code from Lesson 1 means?

I understand everything in Lesson 1 up to the Analyzing results: looking at pictures part.

Can someone please help me understand what is this code doing?

# this gives prediction for validation set. Predictions are in log scale
log_preds = learn.predict()
log_preds.shape
// (2000, 2)

log_preds[:10]
// array([[ -0.00002, -11.07446],
       [ -0.00138,  -6.58385],
       [ -0.00083,  -7.09025],
       [ -0.00029,  -8.13645],
       [ -0.00035,  -7.9663 ],
       [ -0.00029,  -8.15125],
       [ -0.00002, -10.82139],
       [ -0.00003, -10.33846],
       [ -0.00323,  -5.73731],
       [ -0.0001 ,  -9.21326]], dtype=float32)

What are these predictions? How do you read them?
(PS if it’s ok, could you also please explain all the code that comes after this, in the same Analyzing results: looking at pictures section?)

you have here array, with 2 columns. Those are prediction for cats and dogs.

preds = np.argmax(log_preds, axis=1)
we are changing those odd looking numbers into 0 or 1. This is done based on which of two column has higher value- in your example that means all of them will be 0 (cats).

probs = np.exp(log_preds[:,1])
since our predictions are in log, we are using exp to “convert” them into “normal” number. The closer to 1 would mean “dog”, closer to zero would mean “cat”

2 Likes

Oh I get it now! Thanks!