-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
686 lines (645 loc) · 35.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="./js/jquery-3.1.1.slim.min.js.download"></script>
<script type="text/javascript" src="./js/d3.min.js.download"></script>
<script type="text/javascript" src="./js/d3-selection-multi.v0.4.min.js.download"></script>
<script type="text/javascript" src="./js/d3-jetpack.js.download"></script>
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="./css/bootstrap-theme.min.css">
<script src="./js/bootstrap.min.js.download"></script>
<link rel="stylesheet" type="text/css" href="./css/gifplayer.css">
<script type="text/javascript" src="./css/jquery.gifplayer.js.download"></script>
<link rel="stylesheet" href="./css/katex.min.css" integrity="sha384-wE+lCONuEo/QSfLb4AfrSk7HjWJtc4Xc1OiB2/aDBzHzjnlBP4SX7vjErTcwlA8C" crossorigin="anonymous">
<script src="./css/katex.min.js.download" integrity="sha384-tdtuPw3yx/rnUGmnLNWXtfjb9fpmwexsd+lr6HUYnUY4B7JhB5Ty7a1mYd+kto/s" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>A Visual and Interactive Guide to the Basics of Neural Networks</title>
<link rel="stylesheet" href="./style.css">
<link rel="icon" href="./favicon.ico" type="image/x-icon">
</head>
<body>
<main>
<h1>A Visual and Interactive Guide to the Basics of Neural Networks!</h1>
<h2 style="align-content:center">Start here</h2>
<div class="center_no_black" style="max-width:max-content">
Let's start with a simple example. Say you're helping a friend who wants to buy a house. She was quoted $400,000 for a 2000 sq ft house (185 meters). Is this a good price or not?
It's not easy to tell without a frame of reference. So you ask your friends who have bought houses in that same neighborhoods, and you end up with three data points:
</div>
<div class="one_variable">
<table>
<thead>
<tr>
<th>Area (x)</th>
<th>Price (y) </th>
</tr>
</thead>
<tbody>
<tr>
<td>2,104</td>
<td>399,900</td>
</tr>
<tr>
<td>2,104</td>
<td>329,900</td>
</tr>
<tr>
<td>2,400</td>
<td>369,000</td>
</tr>
</tbody>
</table>
</div>
<div class="center_no_black" style="max-width:max-content">
Personally, my first instinct would be to get the average price per sq ft. That comes to $180 per sq ft.
Welcome to your first neural network! Now it's not quite at Siri level yet, but now you know the fundamental building block. And it looks like this:
</div>
<div class="img-div" >
<img src="./images/1_simple_NN_1.png" width="384" height="140" class="center_image">
</div>
<div class="center_no_black" style="max-width:max-content">
Diagrams like this show you the structure of the network and how it calculates a prediction. The calculation starts from the input node at the left. The input value flows to the right. It gets multiplied by the weight and the result becomes our output.
Multiplying 2,000 sq ft by 180 gives us $360,000. That's all there is to it at this level. Calculating the prediction is simple multiplication. But before that, we needed to think about the weight we'll be multiplying by. Here we started with an average, later we'll look at better algorithms that can scale as we get more inputs and more complicated models. Finding the weight is our "training" stage. So whenever you hear of someone "training" a neural network, it just means finding the weights we use to calculate the prediction.
</div>
<div class="img-div" >
<img src="./images/2_NNs_formula_no_bias.png" width="384" height="106" class="center_image">
</div>
<div class="center_no_black" style="max-width:max-content">
This is a form of prediction.
This is a simple predictive model that takes an input, does a calculation, and gives an output (since the output can be of continuous values, the technical name for what we have would be a "regression model")
Let us visualize this process (for simplicity, let's switch our price unit from $1 to $1000. Now our weight is 0.180 rather than 180):
</div>
<p class="gif-space" />
<img src="./images/2a_data_points_graph_animated.gif" width="840" height="459" class="center_image">
<p class="gif-space" />
<p class="gif-space" />
<h3 style="align-content:center;max-width:max-content"> Harder, Better, Faster, Stronger</h3>
<div class="center_no_black" style="max-width:max-content">
Can we do better than estimate the price based on the average of our data points? Let's try. Let's first define what it means to be better in this scenario. If we apply our model to the three data points we have, how good of a job would it do?
</div>
<p class="gif-space" />
<img src="./images/3_data_points_error_animated.gif" width="840" height="459" class="center_image">
<p class="gif-space" />
<div class="center_no_black" style="max-width:max-content">
That's quite a bit of yellow. Yellow is bad. Yellow is error. We want to shrink yellow as much as we can.
</div>
<div class="one_variable" style="align-content:center">
<table>
<thead>
<tr>
<th>Area (x)</th>
<th>Price ($1000) (<span class="y_">y_</span>)</th>
<th>Prediction (<span class="y">y</span>)</th>
<th><span class="mdc-text-yellow">y_</span>-<span class="mdc-text-red">y</span></th>
<th>(<span class="mdc-text-yellow">y_</span>-<span class="mdc-text-red">y</span>)²</th>
</tr>
</thead>
<tbody>
<tr>
<td>2,104</td>
<td>399.9</td>
<td>379</td>
<td>21</td>
<td>449</td>
</tr>
<tr>
<td>1,600</td>
<td>329.9</td>
<td>288</td>
<td>42</td>
<td>1756</td>
</tr>
<tr>
<td>2,400</td>
<td>369</td>
<td>432</td>
<td>-63</td>
<td>3969</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2" align="right"><span class="total"> Average:</span></td>
<td><b>2,058</b></td>
</tr>
</tbody>
</table>
</div>
<div class="center_no_black" style="max-width:max-content">
Here we can see the <span class="y_">actual price value</span>, the <span class="y">predicted price value</span>, and the <span class="error-value">difference between them</span>. Then we'll need to average these differences so we have a number that tells us how much error there is in this prediction model. The problem is, the 3rd row has -63 as its value. We have to deal with this negative value if we want to use the difference between the prediction and price as our error measuring stick. That's one reason why we introduce an additional column that shows the error squared, thus getting rid of the negative value.
This is now our definition of doing better -- a better model is one that has less error. Error is measured as the average of the errors for each point in our data set. For each point, the error is measured by the difference between the actual value and the predicted value, raised to the power of 2. This is called [Mean Square Error](http://mste.illinois.edu/patel/amar430/meansquare.html). Using it as a guide to train our model makes it our **loss function** (also, **cost function**).
Now that we defined our measuring stick for what makes a better model, let's experiment with a couple more weight values and compare them with our average pick:
</div>
<p class="gif-space" />
<img src="./images/4_lines_and_errors_animated.gif" width="840" height="459" style="border:2px solid black">
<div class="center_no_black" style="max-width:max-content">
We can't improve much on the model by varying the weight any more. But if we add a bias we can find values that improve the model.
</div>
<div class="center_no_black" style="max-width:max-content">
Our lines can better approximate our values now that we have this b value added to the line formula. In this context, we call it a "bias". This makes our neural network look like this:
</div>
<div class="img-div" markdown="0">
<img src="./images/5_NNs_bias.png" width="384" height="106" style="border:2px solid black">
</div>
<div class="center_no_black" style="max-width:max-content">
We can generalize it by saying that a neural network with one input and one output (*spoiler warning:* and no hidden layers) looks like this:
</div>
<div class="img-div" markdown="0">
<img src="./images/6_NNs_bias_2.png" width="384" height="106" style="border:2px solid black">
</div>
<div class="center_no_black" style="max-width:max-content">
In this graph, W and b are values we find during the training process. X is the input we plug into the formula (area in sq ft in our example). Y is the predicted price.
Calculating a prediction now uses this formula:
</div>
<div class="img-div" markdown="0">
<img src="./images/7_NNs_formula.png" width="384" height="106" class="center_image">
</div>
<div class="center_no_black" style="max-width:max-content">
So our current model calculates predictions by plugging in the area of house as x in this formula:
</div>
<div class="img-div" markdown="0">
<img src="./images/8_NNs_formula_ex.png" width="384" height="106" class="center_image">
</div>
<h2> Train Your Predict House Price (NN) <a name="train_your_dragon" href="#train_your_nn"></a></h2>
<div class="center_no_black" style="max-width:max-content">
How about you take a crack at training our toy neural network? Minimize the loss function by tweaking the weight and bias dials. Can you get an error value below 799?
</div>
<div id="training-one-chart" class="training-chart" />
<table id="training-one" class="training-table">
<tr>
<td>
Error
</td>
<td colspan="2">
<span id="error-value"></span>
</td>
</tr>
<tr>
<td class="error-cell" colspan="3">
<span id="error-value-message"></span>
</td>
</tr>
<tr>
<td>
Weight
</td>
<td>
<input id="weightSlider" type="range" class="weight" min="0" max="0.4" step="0.001">
</td>
<td class="slider-value">
<span id="weight" class="weight">0</span>
</td>
</tr>
<tr>
<td>
Bias
</td>
<td>
<input id="biasSlider" type="range" class="bias" min="0" max="460" step="1">
</td>
<td class="slider-value">
<span id="bias" class="bias">0</span>
</td>
</tr>
</table>
<div id="neural-network-graph" class="nn-graph-area"></div>
<h2> Automation <a name="automation" href="#automation"></a></h2>
<div class="center_no_black" style="max-width:max-content">
Congratulations on manually training your first neural network! Let's look at how to automate this training process. Below is another example with an additional autopilot-like functionality. These are the GD Step buttons. They use an algorithm called "Gradient Descent" to try to step towards the correct weight and bias values that minimize the loss function.
</div>
<div class="container" style="align-content:center">
<div class="row">
<div class="col-sm-6 graphs">
<div id="training-one-gd-chart" class="training-chart"></div>
<div class="row training-chart mini-charts">
<div id="training-one-gd-error-chart" class="error-chart col-xs-6"></div>
<div id="training-one-gd-heatmap" class="error-chart col-xs-6"></div>
</div>
</div>
<div class="col-sm-6">
<table id="training-one-gd" class="training-table">
<tr>
<td colspan="3" class="gd-buttons">
<input type="button" value="GD Step" id="gradient-descent-button" class="btn btn-primary" />
<input type="button" value="10 GD Steps " id="gradient-descent-10-button" class="btn btn-primary" />
<input type="button" value="100 GD Steps " id="gradient-descent-100-button" class="btn btn-primary" />
</td>
</tr>
<tr>
<td>
Error
</td>
<td colspan="2">
<span id="error-value"></span>
</td>
</tr>
<tr>
<td class="error-cell" colspan="3">
<span id="error-value-message"></span>
</td>
</tr>
<tr>
<td>
Weight
</td>
<td>
<input id="weightSlider" type="range" class="weight" min="0" max="0.4" step="0.0001">
</td>
<td class="slider-value">
<span id="weight" class="weight">0</span>
</td>
</tr>
<tr>
<td>
Bias
</td>
<td>
<input id="biasSlider" type="range" class="bias" min="0" max="460" step="0.1">
</td>
<td class="slider-value">
<span id="bias" class="bias">0</span>
</td>
</tr>
</table>
<div id="neural-network-gd-graph" class="nn-graph-area"></div>
</div>
</div>
</div>
<div class="center_no_black" style="max-width:max-content">
The two new graphs are to help you track the error values as you fiddle with the parameters (weight and bias) of the model. It's important to keep track of the error as the training process is all about reducing this error as much possible.
How does gradient descent know where its next step should be? Calculus. You see, knowing the function we're minimizing (our loss function, the average of (y_ - y)² for all our data points), and knowing the current inputs into it (the current weight and bias), the derivatives of the loss function tell us which direction to nudge W and b in order to minimize the error.
Learn more about gradient descent and how to use it to calculate the new weights & bias in the first lectures of Coursera's [Machine Learning](https://www.coursera.org/learn/machine-learning) course.
<h2> And Then There Were Two <a name="two" href="#two">#</a></h2>
Is the size of the house the only variable that goes into how much it costs? Obviously there are many other factors. Let's add another variable and see how we can adjust our neural network to it.
Say your friend does a bit more research and finds a bunch more data points. She also finds out how many bathrooms each house has:
</div>
<div class="two_variables" style="align-content:center">
<table>
<thead>
<tr>
<th>Area (x)</th>
<th>Bathrooms (x2)</th>
<th>Price ($1000)</th>
</tr>
</thead>
<tbody>
<tr>
<td>2,104</td>
<td>3</td>
<td>399.9</td>
</tr>
<tr>
<td>1,600</td>
<td>3</td>
<td> 329.9</td>
</tr>
<tr>
<td>2,400</td>
<td>3</td>
<td>369.000</td>
</tr>
<tr>
<td>1,416</td>
<td>2</td>
<td>232.000</td>
</tr>
<tr>
<td>3,000</td>
<td>4</td>
<td>539.900</td>
</tr>
<tr>
<td>1,985</td>
<td>4</td>
<td>299.900</td>
</tr>
<tr>
<td>1,534 </td>
<td>3</td>
<td>314.900</td>
</tr>
<tr>
<td>1,427 </td>
<td>3</td>
<td>198.999</td>
</tr>
<tr>
<td>1,380 </td>
<td>3</td>
<td>212.000</td>
</tr>
<tr>
<td>1,494 </td>
<td>3</td>
<td>242,500</td>
</tr>
</tbody>
</table>
</div>
<div class="center_no_black" style="max-width:max-content">
Our neural network with two variables looks like this:
</div>
<div class="img-div" markdown="0">
<img src="/images/8a_NNs_2_variables.png" width="384" height="106" class="center_image">
</div>
<div class="center_no_black" style="max-width:max-content">
We now have to find two weights (one for each input) and one bias to create our new model.
Calculating Y looks like this:
</div>
<div class="img-div" markdown="0">
<img src="/images/9_NNs_formula_two_variables.png" width="384" height="106" class="center_image">
</div>
<div class="center_no_black" style="max-width:max-content">
But how do we find w1 and w2? This is a little trickier than when we only had to worry about one weight value. How much does having an extra bathroom change how we predict the value of a home?
Take a stab at finding the right weights and bias. You will start here to see the complexity we start getting into as the number of our inputs increase. We start losing the ability to create simple 2d shapes that allow us to visualize the model at a glance. Instead, we'll have to mainly rely on how the error value is evolving as we tweak our model parameters.
</div>
<div class="container" style="align-content:center">
<div class="row">
<div class="col-sm-6 graphs">
<div id="training-two-chart" class="error-chart"></div>
</div>
<div class="col-sm-6">
<table id="training-two-table" class="training-table">
<tr>
<td colspan="3" class="gd-buttons">
<input type="button" value="GD Step" id="gradient-descent-button" class="btn btn-primary" />
<input type="button" value="10 GD Steps " id="gradient-descent-10-button" class="btn btn-primary" />
<input type="button" value="100 GD Steps " id="gradient-descent-100-button" class="btn btn-primary" />
</td>
</tr>
<tr>
<td>
Error
</td>
<td colspan="2">
<span id="error-value"></span>
</td>
</tr>
<tr>
<td class="error-cell" colspan="3">
<span id="error-value-message"></span>
</td>
</tr>
<tr>
<td>
Weight #1
</td>
<td>
<input id="weight0Slider" type="range" class="weight" min="-0.4" max="0.4" step="0.0001">
</td>
<td class="slider-value">
<span id="weight0" class="weight">0</span>
</td>
</tr>
<tr>
<td>
Weight #2
</td>
<td>
<input id="weight1Slider" type="range" class="weight" min="-100" max="200" step="0.0001">
</td>
<td class="slider-value">
<span id="weight1" class="weight">0</span>
</td>
</tr>
<tr>
<td>
Bias
</td>
<td>
<input id="biasSlider" type="range" class="bias" min="-100" max="300" step="0.1">
</td>
<td class="slider-value">
<span id="bias" class="bias">0</span>
</td>
</tr>
</table>
<div id="neural-network-two-graph" class="nn-graph-area"></div>
</div>
</div>
</div>
<div class="center_no_black" style="max-width:max-content">
Our trusty gradient descent is here to help once again. It still is valuable in helping us find the right weights and bias.
</div>
<h2 style="align-content:center"> Features </h2>
<div class="center_no_black" style="max-width:max-content">
Now that you've seen neural networks with one and two features, you can sort of figure out how to add additional features and use them to calculate your predictions. The number of weights will continue to grow, and our implementation of gradient descent will have to be tweaked as we add each feature so that it can update the new weights associated with the new feature.
It's important to note here that we don't blindly feed the network everything we know about our examples. We have to be selective about which features we feed the model. Feature selection/processing is an entire discipline with its own set of best practices and considerations. If you want to see an example of the process of examining a dataset to choose which features to feed a prediction model, check out [A Journey Through Titanic](https://www.kaggle.com/omarelgabry/titanic/a-journey-through-titanic). It's a notebook where [Omar EL Gabry](https://twitter.com/Omar_ElGabry) narrates his process for solving Kaggle's Titanic challenge. Kaggle makes available the passenger's manifest of the Titanic including data like name, sex, age, cabin, and whether the person survived or not. The challenge is to build a model that predicts whether a person survived or not given their other information.
</div>
<h2 style="align-content:center"> Classification </h2>
<div class="center_no_black" style="max-width:max-content">
Let's continue to tweak our example. Assume your friend gives you a list of houses. This time, she has labeled which ones she thinks have a good size and number of bathrooms:
</div>
<div class="two_variables">
<table>
<thead>
<tr>
<th>
Area (sq ft) (x)
</th>
<th>Bathrooms (x2)</th>
<th>Label (y) </th>
</tr>
</thead>
<tbody>
<tr>
<td>
2,104
</td>
<td>
3
</td>
<td>
Good
<td>
</tr>
<tr>
<td>
1,600
</td>
<td>
3
</td>
<td>
Good
<td>
</tr>
<tr>
<td>
2,400
</td>
<td>
3
</td>
<td>
Good
<td>
</tr>
<tr>
<td>
1,416
</td>
<td>
2
</td>
<td>
Bad
<td>
</tr>
<tr>
<td>
1,416
</td>
<td>
2
</td>
<td>
Bad
<td>
</tr>
<tr>
<td>
3,000
</td>
<td>
4
</td>
<td>
Bad
<td>
</tr>
<tr>
<td>
1,985
</td>
<td>
4
</td>
<td>
Good
<td>
</tr>
<tr>
<td>
1,534
</td>
<td>
3
</td>
<td>
bad
<td>
</tr>
<tr>
<td>
1,427
</td>
<td>
3
</td>
<td>
good
<td>
</tr>
<tr>
<td>
1,380
</td>
<td>
3
</td>
<td>
good
<td>
</tr>
<tr>
<td>
1,494
</td>
<td>
3
</td>
<td>
good
<td>
</tr>
</tbody>
</table>
</div>
<div class="center_no_black" style="max-width:max-content">
She needs you to use this to create a model to predict whether she would like a house or not given its size and number of bathrooms. You will use this list above to build the model, then she will use the model to classify many other houses. One additional change in the process, is that she has another list of 10 houses she has labeled, but she's keeping it from you. That other list would be used to evaluate your model after you've trained it -- thus trying to ensure your model grasps the conditions that actually make her like the features of the house.
The neural networks we've been toying around with until now are all doing "regression" -- they calculate and output a "continuous" value (the output can be 4, or 100.6, or 2143.342343). In practice, however, neural networks are more often used in "classification" type problems. In these problems, the neural network's output has to be from a set of discrete values (or "classes") like "Good" or "Bad". How this works out in practice, is that we'll have a model that will say that it's 75% sure that a house is "Good" rather than just spit out "good" or "bad".
One way we can transform the network we've seen into a classification network is to have it output two values -- one for each class (our classes now being "good" and "bad"). We then pass these values through an operation called "[softmax](https://rasbt.github.io/mlxtend/user_guide/classifier/SoftmaxRegression/)". The output of softmax is the probability of each class. For example, say that layer of the network outputs 2 for "good" and 4 for "bad", if we feed [2, 4] to softmax, it will return [0.11, 0.88] as the output. Which translates the values to say the network is 88% sure that the inputted value is "bad" and our friend would not like that house.
Softmax takes an array and outputs an array of the same length. Notice that its outputs are all positive and sum up to 1 -- which is useful when we're outputting a probability value. Also notice that even though 4 is double 2, its probability is not only double, but is eight times that of 2. This is a useful property that exaggerates the difference in output thus improving our training process.
</div>
<table>
<thead><tr><td> </td><td> output </td></tr></thead>
<tbody>
<tr><td> softmax([ 1 ]) </td><td> [ 1 ] </td></tr>
<tr><td> softmax([ 1, 1 ]) </td><td> [ 0.5, 0.5 ] </td></tr>
<tr><td> softmax([ 0, 1 ]) </td><td> [ 0.26, 0.73 ] </td></tr>
<tr><td> softmax([ 2, 4 ]) </td><td> [ 0.11, 0.88 ] </td></tr>
<tr><td> softmax([ 5, 10 ]) </td><td> [ 0.007, 0.993 ] </td></tr>
<tr><td> softmax([ -1, 0, 1 ]) </td><td> [ 0.09, 0.24, 0.66 ] </td></tr>
<tr><td> softmax([ 1, 2, 4 ]) </td><td> [ 0.04, 0.11, 0.84 ] </td></tr>
</tbody>
</table>
<div class="center_no_black" style="max-width:max-content">
As you can see in the last two rows, softmax extends to any number of inputs. So now if our friend adds a third label (say "Good, but I'll have to airbnb one room"), softmax scales to accomedate that change.
Take a second to explore the shape of the network as you vary the number of features (x1, x2, x3...etc) (which can be area, number of bathrooms, price, proximity to school/work...etc) and vary the number of classes (y1, y2, y3...etc) (which can be "too expensive", "good deal", "good if I airbnb", "too small"):
</div>
<table style="align-content:center">
<tr>
<td>
Features (x):
</td>
<td>
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="minus" data-field="quant[1]">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" name="quant[1]" class="form-control input-number" value="2">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant[1]">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</td>
</tr>
<tr>
<td>
Classes (y):
</td>
<td>
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="minus" data-field="quant[2]">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" name="quant[2]" class="form-control input-number" value="2">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant[2]">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</td>
</tr>
</table>
</main>
<script type="text/javascript" src="/js/nnVizUtils.js"></script>
<!-- Visualizations 1 Weight & bias, and 2 Gradient Descent -->
<script type="text/javascript" src="/js/simple_nn.js"></script>
<!-- Visualization 3 - Two variables -->
<script type="text/javascript" src="/js/two_variable_nn.js"></script>
<!-- Visualization 4 - Features & classes -->
<script type="text/javascript" src="/js/shallow_nn_grapher.js"></script>
</body>
</html>