Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub
As expected, probabilities that add up to 100% (like 75% and 25%) correspond tolog odds ratios that are the same in absolute value. Let’s plot it:Figure 3.3 - Log odds ratio and probabilityOn the left, each probability maps into a log odds ratio. The red dots correspond toprobabilities of 25%, 50%, and 75%, the same as before.If we flip the horizontal and vertical axes (right plot), we are inverting the function,thus mapping each log odds ratio into a probability. That’s the function we werelooking for!Does its shape look familiar? Wait for it…From Logits to ProbabilitiesIn the previous section, we were trying to map logit values into probabilities, andwe’ve just found out, graphically, a function that maps log odds ratios intoprobabilities.Clearly, our logits are log odds ratios :-) Sure, drawing conclusions like this is notvery scientific, but the purpose of this exercise is to illustrate how the results of aregression, represented by the logits (z), get to be mapped into probabilities.Model | 215
So, here’s what we arrived at:Equation 3.7 - Regression, logits, and log odds ratiosLet’s work this equation out a bit, inverting, rearranging, and simplifying someterms to isolate p:Equation 3.8 - From logits (z) to probabilities (p)Does it look familiar? That’s a sigmoid function! It is the inverse of the log oddsratio.Equation 3.9 - Sigmoid function216 | Chapter 3: A Simple Classification Problem
- Page 190 and 191: The procedure is exactly the same,
- Page 192 and 193: soon, so please bear with me for no
- Page 194 and 195: After recovering our model’s stat
- Page 196 and 197: Run - Model Configuration V31 # %lo
- Page 198 and 199: This is the general structure you
- Page 200 and 201: Chapter 2.1Going ClassySpoilersIn t
- Page 202 and 203: # A completely empty (and useless)
- Page 204 and 205: # These attributes are defined here
- Page 206 and 207: # Creates the train_step function f
- Page 208 and 209: # Builds function that performs a s
- Page 210 and 211: setattrThe setattr function sets th
- Page 212 and 213: See? We effectively modified the un
- Page 214 and 215: the random seed as arguments.This s
- Page 216 and 217: The current state of development of
- Page 218 and 219: Lossesdef plot_losses(self):fig = p
- Page 220 and 221: Run - Data Preparation V21 # %load
- Page 222 and 223: Model TrainingWe start by instantia
- Page 224 and 225: Making PredictionsLet’s make up s
- Page 226 and 227: OutputOrderedDict([('0.weight', ten
- Page 228 and 229: Run - Data Preparation V21 # %load
- Page 230 and 231: • defining our StepByStep class
- Page 232 and 233: import numpy as npimport torchimpor
- Page 234 and 235: Next, we’ll standardize the featu
- Page 236 and 237: Equation 3.1 - A linear regression
- Page 238 and 239: The odds ratio is given by the rati
- Page 242 and 243: Sigmoid Functiondef sigmoid(z):retu
- Page 244 and 245: A picture is worth a thousand words
- Page 246 and 247: OutputOrderedDict([('linear.weight'
- Page 248 and 249: The first summation adds up the err
- Page 250 and 251: IMPORTANT: Make sure to pass the pr
- Page 252 and 253: To make it clear: In this chapter,
- Page 254 and 255: argument of nn.BCEWithLogitsLoss().
- Page 256 and 257: It is not that hard, to be honest.
- Page 258 and 259: Figure 3.6 - Training and validatio
- Page 260 and 261: Outputarray([[0.5504593 ],[0.949995
- Page 262 and 263: decision boundary.Look at the expre
- Page 264 and 265: Are my data points separable?That
- Page 266 and 267: model = nn.Sequential()model.add_mo
- Page 268 and 269: It looks like this:Figure 3.10 - Sp
- Page 270 and 271: True and False Positives and Negati
- Page 272 and 273: tpr_fpr(cm_thresh50)Output(0.909090
- Page 274 and 275: The trade-off between precision and
- Page 276 and 277: Figure 3.13 - Using a low threshold
- Page 278 and 279: Figure 3.16 - Trade-offs for two di
- Page 280 and 281: thresholds do not necessarily inclu
- Page 282 and 283: actual data, it is as bad as it can
- Page 284 and 285: If you want to learn more about bot
- Page 286 and 287: Model Training1 n_epochs = 10023 sb
- Page 288 and 289: step in your journey! What’s next
As expected, probabilities that add up to 100% (like 75% and 25%) correspond to
log odds ratios that are the same in absolute value. Let’s plot it:
Figure 3.3 - Log odds ratio and probability
On the left, each probability maps into a log odds ratio. The red dots correspond to
probabilities of 25%, 50%, and 75%, the same as before.
If we flip the horizontal and vertical axes (right plot), we are inverting the function,
thus mapping each log odds ratio into a probability. That’s the function we were
looking for!
Does its shape look familiar? Wait for it…
From Logits to Probabilities
In the previous section, we were trying to map logit values into probabilities, and
we’ve just found out, graphically, a function that maps log odds ratios into
probabilities.
Clearly, our logits are log odds ratios :-) Sure, drawing conclusions like this is not
very scientific, but the purpose of this exercise is to illustrate how the results of a
regression, represented by the logits (z), get to be mapped into probabilities.
Model | 215