Skip to content

Commit 1a94a16

Browse files
committed
Ch5: Fix python code in Priceline showdown example
Name the "sp3" plot so it may be referenced in the label. Fix indexing assignment error in showdown_loss() by creating a "close_mask" intermediate boolean indexing variable. Fix risk assignment -- values over by less than $250 were not being assigned the risk value. Ensure this happens by assigning loss[ix] = risk last. Outputs and plots are not changed.
1 parent 7850143 commit 1a94a16

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Chapter5_LossFunctions/LossFunctions.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
"\n",
209209
"subplot(313)\n",
210210
"x = np.linspace(0, 25000, 200)\n",
211-
"plt.fill_between(x , 0, norm_pdf( x, 12000, 3000), \n",
211+
"sp3 = plt.fill_between(x , 0, norm_pdf( x, 12000, 3000), \n",
212212
" color = \"#7A68A6\", lw = 3, alpha = 0.6,\n",
213213
" label = \"Trip price guess\")\n",
214214
"plt.autoscale( tight=True)\n",
@@ -357,9 +357,10 @@
357357
"def showdown_loss( guess, true_price, risk = 80000):\n",
358358
" loss = np.zeros_like( true_price )\n",
359359
" ix = true_price < guess\n",
360-
" loss[ix] = risk\n",
361360
" loss[~ix] = np.abs( guess - true_price[~ix] )\n",
362-
" loss[ abs( true_price - guess) <= 250 ] = -2*true_price\n",
361+
" close_mask = [ abs( true_price - guess) <= 250 ]\n",
362+
" loss[close_mask] = -2*true_price[close_mask]\n",
363+
" loss[ix] = risk\n",
363364
" return loss\n",
364365
"\n",
365366
"\n",

0 commit comments

Comments
 (0)