∇Neural Math LabUNDERSTAND THE LEARNING BROWSER LEARNING LAB

LAB 02 / Moons / MANUAL NUMPY

See a network
learn the shape.

Follow the boundary as it changes. Inspect each neuron. Then ask the important question: does it work on examples it never trained on?

Held-out test accuracy96.7%120 unseen examples · selected model
Class 1 · F1 score0.967Combines precision and recall
Against linear baseline+4.2 ppBaseline accuracy: 92.5%
Selected epoch777Lowest validation BCE · stopped at 877

The model was selected using validation loss. The held-out test set was evaluated afterward. These synthetic results describe this split and seed; repeated tuning against the test score would invalidate that separation.

01 / REPLAY & EXPLORE

A boundary built from simple operations.

Selected checkpoint
Use the input fields below to inspect a point.
Class 0 · square Class 1 · circle× Incorrect classp = 0p = 1

The map displays the selected model. Final metric cards above stay fixed while you replay training.

02 / LOOK FOR GENERALIZATION

Training improves. Validation keeps it honest.

Stopped at epoch 877
Training BCE Validation BCEDashed line: selected epoch

Read this curve.

The plotted loss excludes the L2 penalty, so the training and validation curves measure the same quantity. Training updates include the penalty on weights.

The lowest observed validation loss selects the saved weights. Patience stops training after too many epochs without a meaningful improvement; those can be different epochs.

This run stopped because: validation patience. The saved model restores epoch 777. The selected checkpoint is included in the replay.

View the exportable static figures
image/svg+xml Matplotlib v3.9.4, https://matplotlib.org/ 0 200 400 600 800 Epoch 0.0 0.2 0.4 0.6 0.8 Mean binary cross-entropy Model selection uses validation loss Training BCE Validation BCE Selected epoch

03 / CHECK THE EVIDENCE

More than one accuracy number.

Threshold p ≥ 0.5

Same held-out examples. Two models.

ModelAccuracyPrecisionRecallF1Brier ↓
Neural network96.7%0.9520.9830.9670.0180
Linear baseline92.5%0.9180.9330.9260.0596

The baseline has one affine score and a sigmoid, with no hidden layer. It uses the same split and training-only standardizer. Its own validation loss selects its weights.

Neural network confusion matrix

Actual ↓ / predicted →
Class 0Class 1
Class 0573
Class 1159

Rows are actual classes; columns are predicted classes. Precision and recall refer to class 1. Undefined ratios are reported as 0.

Inspect each data split
SplitExamplesAccuracyBCERole
Training36099.2%0.03680Gradient updates + scaler
Validation12098.3%0.05477Choose weights and stop
Test12096.7%0.07208Final evaluation only

The split is stratified: each class is divided approximately 60/20/20. Every example ID belongs to exactly one split.

Show misclassified test examples
Row IDx1x2TargetOutput pPredicted
3780.46790.259410.4786650
320-0.14160.617900.6116371
2591.3847-0.106300.9562491
315-0.01290.677800.5954171

Error analysis describes this completed run. Use fresh evaluation data for future model-selection decisions.

04 / DECIDE WITH DIFFERENT COSTS

A probability becomes a decision.

Validation exploration only

A false alarm and a missed positive need not cost the same. Python selected the threshold with the lowest validation cost for each model. Explore that trade-off below without changing its saved weights or final test evaluation.

Controls require JavaScript. Saved values remain readable below.

False positives—
False negatives—
Recall · class 1—
Precision · class 1—
Cost per example—

Mean cost = (cFP × FP + cFN × FN) / N

Prediction is class 1 when p ≥ τ. Equal scores move together. The no-positive option sets τ just above 1. Undefined precision or recall is displayed as 0, matching the original metrics.

Ranking · ROC

See the numeric ROC table below.

Retrieval · precision–recall

See the numeric precision-recall table below.

Probability · reliability

See the reliability-bin table below.

These curves use the selected model’s validation scores and stay fixed during threshold exploration and checkpoint replay. The dot on ROC and precision–recall marks the explored decision. A good ranking does not imply calibrated probabilities. Empty calibration bins are omitted; small bins are noisy.

FINAL TEST EVALUATION · FIXED

Evaluate the selected rules once.

These values use each model’s validation-selected threshold. The controls above never recalculate this table on test data.

ModelSelected τFPFNMean costAccuracyROC AUCAPBrier
Neural network0.6830711918697014110.01670.98330.99750.99750.0180
Linear baseline0.5540.07500.92500.97640.97530.0596

The earlier accuracy cards use threshold 0.5. This table uses the cost-selected rules, so their counts may differ. Test scores are descriptive for this synthetic split.

Read saved validation results and all curve points

Neural network · saved validation diagnostics

Selected thresholdFP costFN costValidation mean costCandidates
0.68307119186970141.01.00.0083122

ROC AUC: 0.9992 · Average precision: 0.9992 · Brier: 0.0130 · ECE: 0.0401. Curves below use validation scores.

Reliability bins

Bin (left inclusive)CountMean pPositive fractionAbsolute gap
[0.0, 0.1)540.01570.00000.0157
[0.1, 0.2)20.12100.00000.1210
[0.2, 0.3)20.23940.50000.2606
[0.3, 0.4)10.30650.00000.3065
[0.4, 0.5)10.48060.00000.4806
[0.5, 0.6)10.53040.00000.5304
[0.6, 0.7)10.68311.00000.3169
[0.7, 0.8)10.70581.00000.2942
[0.8, 0.9)40.86491.00000.1351
[0.9, 1.0]530.98621.00000.0138

Empty bins have undefined means and are omitted from the plot. ECE is the count-weighted absolute bin gap.

ROC points
ThresholdFalse-positive rateTrue-positive rateTPFP
Above 1 (all negative)0.00000.000000
0.99985709901556350.00000.016710
0.99949120324975040.00000.033320
0.9991984757762450.00000.050030
0.99870675963748860.00000.066740
0.99827621427248810.00000.083350
0.99823916774807640.00000.100060
0.99805095343615960.00000.116770
0.99760792194665780.00000.133380
0.99752599350469230.00000.150090
0.9972152352565370.00000.1667100
0.99698143136508010.00000.1833110
0.99684386987705160.00000.2000120
0.9967392777327540.00000.2167130
0.99629908389558520.00000.2333140
0.99591058216303610.00000.2500150
0.99503925732630980.00000.2667160
0.99429472937359980.00000.2833170
0.99415680856341860.00000.3000180
0.9941064454991550.00000.3167190
0.99381135643167340.00000.3333200
0.99367550902527350.00000.3500210
0.99308047991967310.00000.3667220
0.99219028281424230.00000.3833230
0.99189365460091350.00000.4000240
0.99186671767629110.00000.4167250
0.99183578839752530.00000.4333260
0.99171267738873730.00000.4500270
0.99089203055340590.00000.4667280
0.98999910535367840.00000.4833290
0.98999221362717220.00000.5000300
0.98992094786880840.00000.5167310
0.98963478589521670.00000.5333320
0.98840626087781070.00000.5500330
0.9882900207760040.00000.5667340
0.98734331483951710.00000.5833350
0.98688015595920730.00000.6000360
0.98475496836297340.00000.6167370
0.98432653290345740.00000.6333380
0.98411548064667240.00000.6500390
0.98329191133281490.00000.6667400
0.98305796332308050.00000.6833410
0.98221714635176790.00000.7000420
0.98041979111738490.00000.7167430
0.97826731196704930.00000.7333440
0.97716976629177320.00000.7500450
0.9740128997674830.00000.7667460
0.97299769848569660.00000.7833470
0.96883419389841240.00000.8000480
0.95837677225151810.00000.8167490
0.95281716059613970.00000.8333500
0.95146994399725910.00000.8500510
0.94736570741040960.00000.8667520
0.91764915361333090.00000.8833530
0.89988327346309430.00000.9000540
0.88049874508506310.00000.9167550
0.8744085651654380.00000.9333560
0.80469540140139810.00000.9500570
0.70578053114037420.00000.9667580
0.68307119186970140.00000.9833590
0.53040505352983340.01670.9833591
0.48062684355734590.03330.9833592
0.306488083384044930.05000.9833593
0.25576564901180170.05001.0000603
0.222952765516529150.06671.0000604
0.13946950185527160.08331.0000605
0.102475244999158030.10001.0000606
0.075803069618713370.11671.0000607
0.073398324585738170.13331.0000608
0.0600155034326755460.15001.0000609
0.052418081723329780.16671.00006010
0.045549370830398380.18331.00006011
0.038884323726165960.20001.00006012
0.0333498127117424350.21671.00006013
0.026101656686668780.23331.00006014
0.0224257082360709330.25001.00006015
0.02219563082562290.26671.00006016
0.0219058410920166670.28331.00006017
0.0217177160487522920.30001.00006018
0.021082639790055440.31671.00006019
0.0210663939396374330.33331.00006020
0.0195747377783404980.35001.00006021
0.018149169672442250.36671.00006022
0.0170103311224313080.38331.00006023
0.0168356909192819080.40001.00006024
0.016378939900427150.41671.00006025
0.015729949348667390.43331.00006026
0.015548604829560170.45001.00006027
0.0154113509789368140.46671.00006028
0.0136181869662895770.48331.00006029
0.011575903494829140.50001.00006030
0.0114891661652487330.51671.00006031
0.010297652947859290.53331.00006032
0.0099440878920083380.55001.00006033
0.0095432931178952630.56671.00006034
0.0086442161810284820.58331.00006035
0.0071240939765832780.60001.00006036
0.0067209245018367270.61671.00006037
0.0067092535546624970.63331.00006038
0.0064917542983482890.65001.00006039
0.0062453545999964320.66671.00006040
0.0058408261622319640.68331.00006041
0.0051529861223679930.70001.00006042
0.0048473944921044860.71671.00006043
0.0045224426132957630.73331.00006044
0.0043024359096029140.75001.00006045
0.0041763790287963750.76671.00006046
0.0039856763441051120.78331.00006047
0.00382265727868595250.80001.00006048
0.00370289465231446540.81671.00006049
0.00351744091213812430.83331.00006050
0.0034309468188254080.85001.00006051
0.00331026905029640570.86671.00006052
0.00310566367019872230.88331.00006053
0.00293623723520520730.90001.00006054
0.0029263378381998490.91671.00006055
0.00288891642918629770.93331.00006056
0.00280572594240771160.95001.00006057
0.0022994497204736280.96671.00006058
0.00058923589182673160.98331.00006059
0.00034142433666681331.00001.00006060
Precision–recall points
ThresholdRecallPrecisionTPFP
Above 1 (all negative)0.00001.000000
0.99985709901556350.01671.000010
0.99949120324975040.03331.000020
0.9991984757762450.05001.000030
0.99870675963748860.06671.000040
0.99827621427248810.08331.000050
0.99823916774807640.10001.000060
0.99805095343615960.11671.000070
0.99760792194665780.13331.000080
0.99752599350469230.15001.000090
0.9972152352565370.16671.0000100
0.99698143136508010.18331.0000110
0.99684386987705160.20001.0000120
0.9967392777327540.21671.0000130
0.99629908389558520.23331.0000140
0.99591058216303610.25001.0000150
0.99503925732630980.26671.0000160
0.99429472937359980.28331.0000170
0.99415680856341860.30001.0000180
0.9941064454991550.31671.0000190
0.99381135643167340.33331.0000200
0.99367550902527350.35001.0000210
0.99308047991967310.36671.0000220
0.99219028281424230.38331.0000230
0.99189365460091350.40001.0000240
0.99186671767629110.41671.0000250
0.99183578839752530.43331.0000260
0.99171267738873730.45001.0000270
0.99089203055340590.46671.0000280
0.98999910535367840.48331.0000290
0.98999221362717220.50001.0000300
0.98992094786880840.51671.0000310
0.98963478589521670.53331.0000320
0.98840626087781070.55001.0000330
0.9882900207760040.56671.0000340
0.98734331483951710.58331.0000350
0.98688015595920730.60001.0000360
0.98475496836297340.61671.0000370
0.98432653290345740.63331.0000380
0.98411548064667240.65001.0000390
0.98329191133281490.66671.0000400
0.98305796332308050.68331.0000410
0.98221714635176790.70001.0000420
0.98041979111738490.71671.0000430
0.97826731196704930.73331.0000440
0.97716976629177320.75001.0000450
0.9740128997674830.76671.0000460
0.97299769848569660.78331.0000470
0.96883419389841240.80001.0000480
0.95837677225151810.81671.0000490
0.95281716059613970.83331.0000500
0.95146994399725910.85001.0000510
0.94736570741040960.86671.0000520
0.91764915361333090.88331.0000530
0.89988327346309430.90001.0000540
0.88049874508506310.91671.0000550
0.8744085651654380.93331.0000560
0.80469540140139810.95001.0000570
0.70578053114037420.96671.0000580
0.68307119186970140.98331.0000590
0.53040505352983340.98330.9833591
0.48062684355734590.98330.9672592
0.306488083384044930.98330.9516593
0.25576564901180171.00000.9524603
0.222952765516529151.00000.9375604
0.13946950185527161.00000.9231605
0.102475244999158031.00000.9091606
0.075803069618713371.00000.8955607
0.073398324585738171.00000.8824608
0.0600155034326755461.00000.8696609
0.052418081723329781.00000.85716010
0.045549370830398381.00000.84516011
0.038884323726165961.00000.83336012
0.0333498127117424351.00000.82196013
0.026101656686668781.00000.81086014
0.0224257082360709331.00000.80006015
0.02219563082562291.00000.78956016
0.0219058410920166671.00000.77926017
0.0217177160487522921.00000.76926018
0.021082639790055441.00000.75956019
0.0210663939396374331.00000.75006020
0.0195747377783404981.00000.74076021
0.018149169672442251.00000.73176022
0.0170103311224313081.00000.72296023
0.0168356909192819081.00000.71436024
0.016378939900427151.00000.70596025
0.015729949348667391.00000.69776026
0.015548604829560171.00000.68976027
0.0154113509789368141.00000.68186028
0.0136181869662895771.00000.67426029
0.011575903494829141.00000.66676030
0.0114891661652487331.00000.65936031
0.010297652947859291.00000.65226032
0.0099440878920083381.00000.64526033
0.0095432931178952631.00000.63836034
0.0086442161810284821.00000.63166035
0.0071240939765832781.00000.62506036
0.0067209245018367271.00000.61866037
0.0067092535546624971.00000.61226038
0.0064917542983482891.00000.60616039
0.0062453545999964321.00000.60006040
0.0058408261622319641.00000.59416041
0.0051529861223679931.00000.58826042
0.0048473944921044861.00000.58256043
0.0045224426132957631.00000.57696044
0.0043024359096029141.00000.57146045
0.0041763790287963751.00000.56606046
0.0039856763441051121.00000.56076047
0.00382265727868595251.00000.55566048
0.00370289465231446541.00000.55056049
0.00351744091213812431.00000.54556050
0.0034309468188254081.00000.54056051
0.00331026905029640571.00000.53576052
0.00310566367019872231.00000.53106053
0.00293623723520520731.00000.52636054
0.0029263378381998491.00000.52176055
0.00288891642918629771.00000.51726056
0.00280572594240771161.00000.51286057
0.0022994497204736281.00000.50856058
0.00058923589182673161.00000.50426059
0.00034142433666681331.00000.50006060

Linear baseline · saved validation diagnostics

Selected thresholdFP costFN costValidation mean costCandidates
0.51.01.00.1333122

ROC AUC: 0.9419 · Average precision: 0.9475 · Brier: 0.0992 · ECE: 0.0778. Curves below use validation scores.

Reliability bins

Bin (left inclusive)CountMean pPositive fractionAbsolute gap
[0.0, 0.1)350.03250.02860.0039
[0.1, 0.2)90.15020.22220.0720
[0.2, 0.3)50.25430.00000.2543
[0.3, 0.4)70.35770.71430.3566
[0.4, 0.5)40.45760.00000.4576
[0.5, 0.6)40.58910.75000.1609
[0.6, 0.7)60.64260.66670.0240
[0.7, 0.8)70.74520.57140.1738
[0.8, 0.9)30.87420.66670.2075
[0.9, 1.0]400.96690.97500.0081

Empty bins have undefined means and are omitted from the plot. ECE is the count-weighted absolute bin gap.

ROC points
ThresholdFalse-positive rateTrue-positive rateTPFP
Above 1 (all negative)0.00000.000000
0.99708937780223780.00000.016710
0.99689877788376270.00000.033320
0.99621791639481890.00000.050030
0.99524480983156360.00000.066740
0.99460463744830110.00000.083350
0.99358557382853880.00000.100060
0.99264937868587060.00000.116770
0.98999933099721640.00000.133380
0.98928751572337640.00000.150090
0.98721817345200950.00000.1667100
0.98287532234621440.00000.1833110
0.98068496757263430.00000.2000120
0.98056581057059330.00000.2167130
0.98012475722549040.00000.2333140
0.97961733470372350.00000.2500150
0.97883087598552730.00000.2667160
0.97725599219865990.00000.2833170
0.97525221848413210.00000.3000180
0.97257447374061080.00000.3167190
0.9723175329261280.00000.3333200
0.9712204255716670.00000.3500210
0.97041621109293530.00000.3667220
0.97034682752266230.00000.3833230
0.96894020856308050.00000.4000240
0.96832467347166520.00000.4167250
0.96575125452444490.00000.4333260
0.9601306949209360.00000.4500270
0.95894638807962370.00000.4667280
0.95323175689085160.00000.4833290
0.95293885961011620.00000.5000300
0.94731411045331850.00000.5167310
0.94496349112515890.00000.5333320
0.94229244905017640.00000.5500330
0.94067647735099620.00000.5667340
0.94015456349933720.00000.5833350
0.93643478386245890.00000.6000360
0.92697623163052280.00000.6167370
0.92666569661589180.01670.6167371
0.91422821546685110.01670.6333381
0.90244976795431430.01670.6500391
0.88465964859212310.03330.6500392
0.88271603925681020.03330.6667402
0.85509432193636680.03330.6833412
0.79754958383659650.05000.6833413
0.78753357794271420.05000.7000423
0.74259661057055690.06670.7000424
0.73967115949276510.06670.7167434
0.73068994352431070.06670.7333444
0.71333754113605310.06670.7500454
0.705163948330720.08330.7500455
0.68921301085146390.08330.7667465
0.67640601195233940.10000.7667466
0.63714141847955410.11670.7667467
0.63039973884391260.11670.7833477
0.62067972149495540.11670.8000487
0.60204271857734360.11670.8167497
0.59251071286524730.11670.8333507
0.58936154982119430.13330.8333508
0.58766290179335230.13330.8500518
0.58686536851184530.13330.8667528
0.4999482740225670.15000.8667529
0.4540478893629150.16670.86675210
0.44887335127938220.18330.86675211
0.4276410639101660.20000.86675212
0.385510632219774440.20000.88335312
0.369193183398466350.20000.90005412
0.36396084270903420.20000.91675512
0.363660448730526330.20000.93335612
0.35957900626468770.21670.93335613
0.33464818620254130.23330.93335614
0.327434363427941850.23330.95005714
0.295087493664102750.25000.95005715
0.28404986297619750.26670.95005716
0.249320907317122340.28330.95005717
0.23458621780119570.30000.95005718
0.208296572103986720.31670.95005719
0.198196178626806390.33330.95005720
0.191320715553282920.35000.95005721
0.181374581552621070.35000.96675821
0.164173631296833630.36670.96675822
0.15309978542386310.36670.98335922
0.131492656415206350.38330.98335923
0.115551766885949550.40000.98335924
0.110682966882582780.41670.98335925
0.105876822120199510.43330.98335926
0.091947442791941930.45000.98335927
0.090096979789797640.46670.98335928
0.080181910430333280.48330.98335929
0.067908611553434110.50000.98335930
0.0619664561635202350.51670.98335931
0.0587116681801100470.53330.98335932
0.0531988629476825360.55000.98335933
0.04636432404380530.56670.98335934
0.0462443226072109460.56671.00006034
0.04434544082353940.58331.00006035
0.044268035158153820.60001.00006036
0.044182465284523640.61671.00006037
0.043026832507850250.63331.00006038
0.041672613935667960.65001.00006039
0.0406838739843914460.66671.00006040
0.038606767772392550.68331.00006041
0.028664913072732120.70001.00006042
0.0241665775609298150.71671.00006043
0.0196046272658272280.73331.00006044
0.0180553533763821960.75001.00006045
0.016684938913270120.76671.00006046
0.0145901098968844370.78331.00006047
0.0144454271300758650.80001.00006048
0.0137177551299148060.81671.00006049
0.0136911586852637710.83331.00006050
0.0136450362968933060.85001.00006051
0.0134405839862782920.86671.00006052
0.012693906334733830.88331.00006053
0.0112302524262447680.90001.00006054
0.0074217125588814440.91671.00006055
0.007093682308809050.93331.00006056
0.0054307730149758370.95001.00006057
0.0048629171030916280.96671.00006058
0.0028057749608929930.98331.00006059
0.00253511421019125961.00001.00006060
Precision–recall points
ThresholdRecallPrecisionTPFP
Above 1 (all negative)0.00001.000000
0.99708937780223780.01671.000010
0.99689877788376270.03331.000020
0.99621791639481890.05001.000030
0.99524480983156360.06671.000040
0.99460463744830110.08331.000050
0.99358557382853880.10001.000060
0.99264937868587060.11671.000070
0.98999933099721640.13331.000080
0.98928751572337640.15001.000090
0.98721817345200950.16671.0000100
0.98287532234621440.18331.0000110
0.98068496757263430.20001.0000120
0.98056581057059330.21671.0000130
0.98012475722549040.23331.0000140
0.97961733470372350.25001.0000150
0.97883087598552730.26671.0000160
0.97725599219865990.28331.0000170
0.97525221848413210.30001.0000180
0.97257447374061080.31671.0000190
0.9723175329261280.33331.0000200
0.9712204255716670.35001.0000210
0.97041621109293530.36671.0000220
0.97034682752266230.38331.0000230
0.96894020856308050.40001.0000240
0.96832467347166520.41671.0000250
0.96575125452444490.43331.0000260
0.9601306949209360.45001.0000270
0.95894638807962370.46671.0000280
0.95323175689085160.48331.0000290
0.95293885961011620.50001.0000300
0.94731411045331850.51671.0000310
0.94496349112515890.53331.0000320
0.94229244905017640.55001.0000330
0.94067647735099620.56671.0000340
0.94015456349933720.58331.0000350
0.93643478386245890.60001.0000360
0.92697623163052280.61671.0000370
0.92666569661589180.61670.9737371
0.91422821546685110.63330.9744381
0.90244976795431430.65000.9750391
0.88465964859212310.65000.9512392
0.88271603925681020.66670.9524402
0.85509432193636680.68330.9535412
0.79754958383659650.68330.9318413
0.78753357794271420.70000.9333423
0.74259661057055690.70000.9130424
0.73967115949276510.71670.9149434
0.73068994352431070.73330.9167444
0.71333754113605310.75000.9184454
0.705163948330720.75000.9000455
0.68921301085146390.76670.9020465
0.67640601195233940.76670.8846466
0.63714141847955410.76670.8679467
0.63039973884391260.78330.8704477
0.62067972149495540.80000.8727487
0.60204271857734360.81670.8750497
0.59251071286524730.83330.8772507
0.58936154982119430.83330.8621508
0.58766290179335230.85000.8644518
0.58686536851184530.86670.8667528
0.4999482740225670.86670.8525529
0.4540478893629150.86670.83875210
0.44887335127938220.86670.82545211
0.4276410639101660.86670.81255212
0.385510632219774440.88330.81545312
0.369193183398466350.90000.81825412
0.36396084270903420.91670.82095512
0.363660448730526330.93330.82355612
0.35957900626468770.93330.81165613
0.33464818620254130.93330.80005614
0.327434363427941850.95000.80285714
0.295087493664102750.95000.79175715
0.28404986297619750.95000.78085716
0.249320907317122340.95000.77035717
0.23458621780119570.95000.76005718
0.208296572103986720.95000.75005719
0.198196178626806390.95000.74035720
0.191320715553282920.95000.73085721
0.181374581552621070.96670.73425821
0.164173631296833630.96670.72505822
0.15309978542386310.98330.72845922
0.131492656415206350.98330.71955923
0.115551766885949550.98330.71085924
0.110682966882582780.98330.70245925
0.105876822120199510.98330.69415926
0.091947442791941930.98330.68605927
0.090096979789797640.98330.67825928
0.080181910430333280.98330.67055929
0.067908611553434110.98330.66295930
0.0619664561635202350.98330.65565931
0.0587116681801100470.98330.64845932
0.0531988629476825360.98330.64135933
0.04636432404380530.98330.63445934
0.0462443226072109461.00000.63836034
0.04434544082353941.00000.63166035
0.044268035158153821.00000.62506036
0.044182465284523641.00000.61866037
0.043026832507850251.00000.61226038
0.041672613935667961.00000.60616039
0.0406838739843914461.00000.60006040
0.038606767772392551.00000.59416041
0.028664913072732121.00000.58826042
0.0241665775609298151.00000.58256043
0.0196046272658272281.00000.57696044
0.0180553533763821961.00000.57146045
0.016684938913270121.00000.56606046
0.0145901098968844371.00000.56076047
0.0144454271300758651.00000.55566048
0.0137177551299148061.00000.55056049
0.0136911586852637711.00000.54556050
0.0136450362968933061.00000.54056051
0.0134405839862782921.00000.53576052
0.012693906334733831.00000.53106053
0.0112302524262447681.00000.52636054
0.0074217125588814441.00000.52176055
0.007093682308809051.00000.51726056
0.0054307730149758371.00000.51286057
0.0048629171030916281.00000.50856058
0.0028057749608929931.00000.50426059
0.00253511421019125961.00000.50006060
Work through one threshold

Suppose targets are [0, 1, 0, 1] and outputs are [0.1, 0.4, 0.4, 0.9]. At τ = 0.5: TP = 1, FP = 0, FN = 1, TN = 2. If a missed positive costs 3 and a false alarm costs 1, mean cost is (0 + 3) / 4 = 0.75.

At τ = 0.4, both tied 0.4 scores enter class 1: TP = 2, FP = 1, FN = 0, TN = 1. Mean cost falls to 1 / 4 = 0.25. Moving a threshold changes decisions; probabilities and weights stay fixed.

There are four positive–negative score pairs: three wins and one tie, so ROC AUC = (3 + ½) / 4 = 7/8. Recall rises by ½ at precision 1, then by ½ at precision 2/3, giving AP = ½ + ⅓ = 5/6.

Brier = (0.1² + 0.6² + 0.4² + 0.1²) / 4 = 0.135. With two bins [0, 0.5) and [0.5, 1], ECE = (3/4) × |0.3 − 1/3| + (1/4) × |0.9 − 1| = 0.05. The recorded report uses ten bins; ECE changes with the binning choice.

Why use validation for the threshold?

The threshold is another selected setting. Choosing it to minimize test mistakes uses the test labels for model selection. This report chooses among the validation scores, 0.5 and an all-negative rule. Ties prefer the threshold closest to 0.5, then the higher threshold.

How to read calibration

In a bin with mean output 0.7 and an observed positive fraction of 0.5, the absolute calibration gap is 0.2. ECE averages these gaps weighted by bin count. Brier is the mean of (p − y)². Neither measure makes a small synthetic test into a guarantee about future data.

05 / GRADIENT LAB

Take a step. Understand why it works.

Temporary sandbox · 0 steps

Choose a weight or bias. Compare its exact backpropagation derivative with a numerical estimate, then see a proposed descent step before applying it. These calculations use only a small, fixed batch of training examples.

This sandbox changes a temporary copy in this tab. The recorded model, replay, validation-selected threshold and held-out results stay fixed. Reloading discards sandbox steps. This is plain gradient descent, even when the original run used Adam.

Changing the starting model, batch or λ resets the sandbox. No test or validation rows enter these calculations.

Use the numerical slice table below.
Actual objective J Tangent J + g·δAll other parameters fixed

Read numerical slice values
Parameter change δActual JTangent J + g·δ
Analytic derivative g—
Central difference—
Absolute difference—

Numerical derivative = [J(θ + ε) − J(θ − ε)] / (2ε). Smaller ε is not always more accurate: rounding competes with approximation error.

Inspect the sandbox step history
StepMean BCEL2 penaltyObjective JActual change

Each row uses the same batch and λ. This is a training objective, not a new estimate of held-out performance.

Follow the derivative through the network

Standardize each raw input using the saved training mean and scale. For B training rows, the output derivative is dZ₂ = (P − Y) / B. Then dW₂ = HᵀdZ₂ + λW₂, dZ₁ = (dZ₂W₂ᵀ) ⊙ (1 − H²), and dW₁ = X̃ᵀdZ₁ + λW₁. Bias derivatives sum over rows and have no L2 penalty.

The objective is mean BCE plus ½λ(‖W₁‖² + ‖W₂‖²). Computing BCE from logits avoids taking log(0) when sigmoid rounds to 0 or 1.

Why can a descent step increase loss?

The tangent predicts ΔJ ≈ −ηg² for one parameter, or −η‖∇J‖² for all parameters. This prediction is local. Curvature matters for a finite step, so a large learning rate can overshoot.

The chart varies only the selected coordinate; an all-parameter step follows another direction. Neither a flat slice nor a small gradient proves a global minimum. Compare the predicted and actual changes, then use Undo to try a smaller η.

Work one update by hand

Take one standardized input [0, 0] with target 1, one hidden neuron, W₁ = [1, −1]ᵀ, b₁ = 0, W₂ = 2, b₂ = 0 and λ = 0.1. Then h = 0, p = 0.5, BCE = log(2), penalty = 0.3 and J ≈ 0.993147.

For b₂, the derivative is p − y = −0.5. A coordinate step with η = 0.2 makes b₂ = 0.1. The predicted change is −0.05. The actual objective becomes log(1 + exp(−0.1)) + 0.3 ≈ 0.944397: a change of −0.048751.

More derivations and exercises: Gradients & optimization and Optimization · exercises.

06 / CONNECT CODE TO MATHEMATICS

The whole model, in four lines.

01X̃ = (X − μtrain) / σtrain

02H = tanh(X̃W₁ + b₁)

03P = sigmoid(HW₂ + b₂)

04J = mean BCE + ½λ(‖W₁‖² + ‖W₂‖²)

What makes this a learning experiment?

Mini-batches estimate a gradient from a subset of training rows. Adam tracks first and second gradient moments and corrects their initial bias. L2 penalizes large weights. Early stopping chooses when to stop using validation behavior.

Python training uses explicit NumPy derivatives and optimizer updates. The gradient sandbox mirrors the network calculations in JavaScript. Neither uses an automatic differentiation framework.

Why divide by the batch size?

The data loss is a mean. Its derivative begins with dZ₂ = (P − Y) / B, where B is the current batch size. The last, shorter batch uses its own size. The L2 derivative is λW; biases receive no L2 penalty.

Why not fit the scaler on every point?

Using validation or test values to calculate the mean and standard deviation lets evaluation data influence training. This lab fits μ and σ on training inputs only, then applies those same numbers everywhere.

Why compare with a linear model?

A network can fit curved boundaries, but a more complex model is not automatically better. The baseline makes the added hidden layer's effect measurable for this experiment.

07 / YOUR NEXT EXPERIMENT

Change one idea. Explain the result.

Try SGD, a different hidden width, or stronger regularization. Choose settings using validation results. Treat the test set as the final audit, rather than a scoreboard to optimize.

python -m neural_math_lab experiment --dataset moons --samples 600 --noise 0.15 --hidden 16 --seed 7 --epochs 1200 --learning-rate 0.01 --optimizer adam --batch-size 32 --l2 0.001 --patience 100 --min-delta 1e-05 --fp-cost 1.0 --fn-cost 1.0 --output runs/new-experiment

The command runs locally in Python. Choose a new output directory each time.