[{"data":1,"prerenderedAt":2807},["ShallowReactive",2],{"lang-switch-post-\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab04-logistic-loss":3,"post-en-machine-learning-specialization-w3-lab04-logistic-loss":4},"\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab04-logistic-loss",{"id":5,"title":6,"body":7,"cover":2790,"date":2791,"description":2792,"extension":2793,"meta":2794,"navigation":2795,"order":2796,"path":2797,"playlist":2798,"seo":2799,"status":2800,"stem":2801,"tags":2802,"__hash__":2806},"posts\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab04-logistic-loss.md","Squared Error Doesn't Work Here: the Logistic Loss",{"type":8,"value":9,"toc":2783},"minimark",[10,20,25,863,877,987,1020,1027,1037,1040,1044,1053,1954,1961,1990,1994,2016,2559,2583,2587,2639,2643,2658,2692,2769,2779],[11,12,13,14,19],"p",{},"Every bit of linear regression so far used squared error as the cost function, ",[15,16,18],"a",{"href":17},"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Flab03-cost-function","a smooth, well-behaved bowl"," where gradient descent always finds the bottom. The obvious temptation is to reuse the same idea for logistic regression: take the sigmoid's output and measure its squared error against the label. This lab shows, with real numbers, why that temptation is a trap.",[21,22,24],"h2",{"id":23},"reusing-squared-error-and-a-hint-that-its-going-to-go-wrong","Reusing squared error (and a hint that it's going to go wrong)",[11,26,27],{},[28,29,32,236],"span",{"className":30},[31],"katex",[28,33,36],{"className":34},[35],"katex-mathml",[37,38,40],"math",{"xmlns":39},"http:\u002F\u002Fwww.w3.org\u002F1998\u002FMath\u002FMathML",[41,42,43,231],"semantics",{},[44,45,46,50,55,58,62,65,68,71,86,111,168,170,174,186,188,200,202,204,208,210,212,224,227,229],"mrow",{},[47,48,49],"mi",{},"J",[51,52,54],"mo",{"stretchy":53},"false","(",[47,56,57],{},"w",[51,59,61],{"separator":60},"true",",",[47,63,64],{},"b",[51,66,67],{"stretchy":53},")",[51,69,70],{},"=",[72,73,74,78],"mfrac",{},[75,76,77],"mn",{},"1",[44,79,80,83],{},[75,81,82],{},"2",[47,84,85],{},"m",[87,88,89,92,102],"msubsup",{},[51,90,91],{},"∑",[44,93,94,97,99],{},[47,95,96],{},"i",[51,98,70],{},[75,100,101],{},"0",[44,103,104,106,109],{},[47,105,85],{},[51,107,108],{},"−",[75,110,77],{},[112,113,114,166],"msup",{},[44,115,116,118,132,134,147,149,151,164],{},[51,117,54],{"fence":60},[119,120,121,124],"msub",{},[47,122,123],{},"f",[44,125,126,128,130],{},[47,127,57],{},[51,129,61],{"separator":60},[47,131,64],{},[51,133,54],{"stretchy":53},[112,135,136,139],{},[47,137,138],{},"x",[44,140,141,143,145],{},[51,142,54],{"stretchy":53},[47,144,96],{},[51,146,67],{"stretchy":53},[51,148,67],{"stretchy":53},[51,150,108],{},[112,152,153,156],{},[47,154,155],{},"y",[44,157,158,160,162],{},[51,159,54],{"stretchy":53},[47,161,96],{},[51,163,67],{"stretchy":53},[51,165,67],{"fence":60},[75,167,82],{},[51,169,61],{"separator":60},[171,172],"mspace",{"width":173},"1em",[119,175,176,178],{},[47,177,123],{},[44,179,180,182,184],{},[47,181,57],{},[51,183,61],{"separator":60},[47,185,64],{},[51,187,54],{"stretchy":53},[112,189,190,192],{},[47,191,138],{},[44,193,194,196,198],{},[51,195,54],{"stretchy":53},[47,197,96],{},[51,199,67],{"stretchy":53},[51,201,67],{"stretchy":53},[51,203,70],{},[205,206,207],"mtext",{},"sigmoid",[51,209,54],{"stretchy":53},[47,211,57],{},[112,213,214,216],{},[47,215,138],{},[44,217,218,220,222],{},[51,219,54],{"stretchy":53},[47,221,96],{},[51,223,67],{"stretchy":53},[51,225,226],{},"+",[47,228,64],{},[51,230,67],{"stretchy":53},[232,233,235],"annotation",{"encoding":234},"application\u002Fx-tex","J(w,b) = \\frac{1}{2m}\\sum_{i=0}^{m-1}\\left(f_{w,b}(x^{(i)})-y^{(i)}\\right)^2, \\quad f_{w,b}(x^{(i)}) = \\text{sigmoid}(wx^{(i)}+b)",[28,237,240,289,784,851],{"className":238,"ariaHidden":60},[239],"katex-html",[28,241,244,249,255,259,263,267,271,274,278,282,286],{"className":242},[243],"base",[28,245],{"className":246,"style":248},[247],"strut","height:1em;vertical-align:-0.25em;",[28,250,49],{"className":251,"style":254},[252,253],"mord","mathnormal","margin-right:0.0962em;",[28,256,54],{"className":257},[258],"mopen",[28,260,57],{"className":261,"style":262},[252,253],"margin-right:0.0269em;",[28,264,61],{"className":265},[266],"mpunct",[28,268],{"className":269,"style":270},[171],"margin-right:0.1667em;",[28,272,64],{"className":273},[252,253],[28,275,67],{"className":276},[277],"mclose",[28,279],{"className":280,"style":281},[171],"margin-right:0.2778em;",[28,283,70],{"className":284},[285],"mrel",[28,287],{"className":288,"style":281},[171],[28,290,292,296,387,390,470,473,669,672,675,679,682,731,734,772,775,778,781],{"className":291},[243],[28,293],{"className":294,"style":295},[247],"height:1.442em;vertical-align:-0.35em;",[28,297,299,303,384],{"className":298},[252],[28,300],{"className":301},[258,302],"nulldelimiter",[28,304,306],{"className":305},[72],[28,307,311,375],{"className":308},[309,310],"vlist-t","vlist-t2",[28,312,315,370],{"className":313},[314],"vlist-r",[28,316,320,344,355],{"className":317,"style":319},[318],"vlist","height:0.8451em;",[28,321,323,328],{"style":322},"top:-2.655em;",[28,324],{"className":325,"style":327},[326],"pstrut","height:3em;",[28,329,335],{"className":330},[331,332,333,334],"sizing","reset-size6","size3","mtight",[28,336,338,341],{"className":337},[252,334],[28,339,82],{"className":340},[252,334],[28,342,85],{"className":343},[252,253,334],[28,345,347,350],{"style":346},"top:-3.23em;",[28,348],{"className":349,"style":327},[326],[28,351],{"className":352,"style":354},[353],"frac-line","border-bottom-width:0.04em;",[28,356,358,361],{"style":357},"top:-3.394em;",[28,359],{"className":360,"style":327},[326],[28,362,364],{"className":363},[331,332,333,334],[28,365,367],{"className":366},[252,334],[28,368,77],{"className":369},[252,334],[28,371,374],{"className":372},[373],"vlist-s","​",[28,376,378],{"className":377},[314],[28,379,382],{"className":380,"style":381},[318],"height:0.345em;",[28,383],{},[28,385],{"className":386},[277,302],[28,388],{"className":389,"style":270},[171],[28,391,394,400],{"className":392},[393],"mop",[28,395,91],{"className":396,"style":399},[393,397,398],"op-symbol","small-op","position:relative;top:0em;",[28,401,404],{"className":402},[403],"msupsub",[28,405,407,461],{"className":406},[309,310],[28,408,410,458],{"className":409},[314],[28,411,414,436],{"className":412,"style":413},[318],"height:0.954em;",[28,415,417,421],{"style":416},"top:-2.4003em;margin-left:0em;margin-right:0.05em;",[28,418],{"className":419,"style":420},[326],"height:2.7em;",[28,422,424],{"className":423},[331,332,333,334],[28,425,427,430,433],{"className":426},[252,334],[28,428,96],{"className":429},[252,253,334],[28,431,70],{"className":432},[285,334],[28,434,101],{"className":435},[252,334],[28,437,439,442],{"style":438},"top:-3.2029em;margin-right:0.05em;",[28,440],{"className":441,"style":420},[326],[28,443,445],{"className":444},[331,332,333,334],[28,446,448,451,455],{"className":447},[252,334],[28,449,85],{"className":450},[252,253,334],[28,452,108],{"className":453},[454,334],"mbin",[28,456,77],{"className":457},[252,334],[28,459,374],{"className":460},[373],[28,462,464],{"className":463},[314],[28,465,468],{"className":466,"style":467},[318],"height:0.2997em;",[28,469],{},[28,471],{"className":472,"style":270},[171],[28,474,477,644],{"className":475},[476],"minner",[28,478,480,490,543,546,586,589,593,596,599,638],{"className":479},[476],[28,481,485],{"className":482,"style":484},[258,483],"delimcenter","top:0em;",[28,486,54],{"className":487},[488,489],"delimsizing","size1",[28,491,493,497],{"className":492},[252],[28,494,123],{"className":495,"style":496},[252,253],"margin-right:0.1076em;",[28,498,500],{"className":499},[403],[28,501,503,534],{"className":502},[309,310],[28,504,506,531],{"className":505},[314],[28,507,510],{"className":508,"style":509},[318],"height:0.3361em;",[28,511,513,516],{"style":512},"top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;",[28,514],{"className":515,"style":420},[326],[28,517,519],{"className":518},[331,332,333,334],[28,520,522,525,528],{"className":521},[252,334],[28,523,57],{"className":524,"style":262},[252,253,334],[28,526,61],{"className":527},[266,334],[28,529,64],{"className":530},[252,253,334],[28,532,374],{"className":533},[373],[28,535,537],{"className":536},[314],[28,538,541],{"className":539,"style":540},[318],"height:0.2861em;",[28,542],{},[28,544,54],{"className":545},[258],[28,547,549,552],{"className":548},[252],[28,550,138],{"className":551},[252,253],[28,553,555],{"className":554},[403],[28,556,558],{"className":557},[309],[28,559,561],{"className":560},[314],[28,562,565],{"className":563,"style":564},[318],"height:0.888em;",[28,566,568,571],{"style":567},"top:-3.063em;margin-right:0.05em;",[28,569],{"className":570,"style":420},[326],[28,572,574],{"className":573},[331,332,333,334],[28,575,577,580,583],{"className":576},[252,334],[28,578,54],{"className":579},[258,334],[28,581,96],{"className":582},[252,253,334],[28,584,67],{"className":585},[277,334],[28,587,67],{"className":588},[277],[28,590],{"className":591,"style":592},[171],"margin-right:0.2222em;",[28,594,108],{"className":595},[454],[28,597],{"className":598,"style":592},[171],[28,600,602,606],{"className":601},[252],[28,603,155],{"className":604,"style":605},[252,253],"margin-right:0.0359em;",[28,607,609],{"className":608},[403],[28,610,612],{"className":611},[309],[28,613,615],{"className":614},[314],[28,616,618],{"className":617,"style":564},[318],[28,619,620,623],{"style":567},[28,621],{"className":622,"style":420},[326],[28,624,626],{"className":625},[331,332,333,334],[28,627,629,632,635],{"className":628},[252,334],[28,630,54],{"className":631},[258,334],[28,633,96],{"className":634},[252,253,334],[28,636,67],{"className":637},[277,334],[28,639,641],{"className":640,"style":484},[277,483],[28,642,67],{"className":643},[488,489],[28,645,647],{"className":646},[403],[28,648,650],{"className":649},[309],[28,651,653],{"className":652},[314],[28,654,657],{"className":655,"style":656},[318],"height:1.092em;",[28,658,660,663],{"style":659},"top:-3.3409em;margin-right:0.05em;",[28,661],{"className":662,"style":420},[326],[28,664,666],{"className":665},[331,332,333,334],[28,667,82],{"className":668},[252,334],[28,670],{"className":671,"style":270},[171],[28,673,61],{"className":674},[266],[28,676],{"className":677,"style":678},[171],"margin-right:1em;",[28,680],{"className":681,"style":270},[171],[28,683,685,688],{"className":684},[252],[28,686,123],{"className":687,"style":496},[252,253],[28,689,691],{"className":690},[403],[28,692,694,723],{"className":693},[309,310],[28,695,697,720],{"className":696},[314],[28,698,700],{"className":699,"style":509},[318],[28,701,702,705],{"style":512},[28,703],{"className":704,"style":420},[326],[28,706,708],{"className":707},[331,332,333,334],[28,709,711,714,717],{"className":710},[252,334],[28,712,57],{"className":713,"style":262},[252,253,334],[28,715,61],{"className":716},[266,334],[28,718,64],{"className":719},[252,253,334],[28,721,374],{"className":722},[373],[28,724,726],{"className":725},[314],[28,727,729],{"className":728,"style":540},[318],[28,730],{},[28,732,54],{"className":733},[258],[28,735,737,740],{"className":736},[252],[28,738,138],{"className":739},[252,253],[28,741,743],{"className":742},[403],[28,744,746],{"className":745},[309],[28,747,749],{"className":748},[314],[28,750,752],{"className":751,"style":564},[318],[28,753,754,757],{"style":567},[28,755],{"className":756,"style":420},[326],[28,758,760],{"className":759},[331,332,333,334],[28,761,763,766,769],{"className":762},[252,334],[28,764,54],{"className":765},[258,334],[28,767,96],{"className":768},[252,253,334],[28,770,67],{"className":771},[277,334],[28,773,67],{"className":774},[277],[28,776],{"className":777,"style":281},[171],[28,779,70],{"className":780},[285],[28,782],{"className":783,"style":281},[171],[28,785,787,791,798,801,804,842,845,848],{"className":786},[243],[28,788],{"className":789,"style":790},[247],"height:1.138em;vertical-align:-0.25em;",[28,792,795],{"className":793},[252,794],"text",[28,796,207],{"className":797},[252],[28,799,54],{"className":800},[258],[28,802,57],{"className":803,"style":262},[252,253],[28,805,807,810],{"className":806},[252],[28,808,138],{"className":809},[252,253],[28,811,813],{"className":812},[403],[28,814,816],{"className":815},[309],[28,817,819],{"className":818},[314],[28,820,822],{"className":821,"style":564},[318],[28,823,824,827],{"style":567},[28,825],{"className":826,"style":420},[326],[28,828,830],{"className":829},[331,332,333,334],[28,831,833,836,839],{"className":832},[252,334],[28,834,54],{"className":835},[258,334],[28,837,96],{"className":838},[252,253,334],[28,840,67],{"className":841},[277,334],[28,843],{"className":844,"style":592},[171],[28,846,226],{"className":847},[454],[28,849],{"className":850,"style":592},[171],[28,852,854,857,860],{"className":853},[243],[28,855],{"className":856,"style":248},[247],[28,858,64],{"className":859},[252,253],[28,861,67],{"className":862},[277],[11,864,865,866,869,870,873,874,876],{},"Same formula as always, except ",[867,868,123],"code",{}," now already went through the sigmoid before entering the math. I fixed ",[867,871,872],{},"b=-3"," (close to where a decent fit for this data ends up) and varied ",[867,875,57],{},":",[878,879,880,893],"table",{},[881,882,883],"thead",{},[884,885,886,890],"tr",{},[887,888,57],"th",{"align":889},"right",[887,891,892],{"align":889},"cost (squared error + sigmoid)",[894,895,896,905,913,921,932,940,948,956,964,972,980],"tbody",{},[884,897,898,902],{},[899,900,901],"td",{"align":889},"1.0",[899,903,904],{"align":889},"0.0354",[884,906,907,910],{},[899,908,909],{"align":889},"1.1",[899,911,912],{"align":889},"0.0284",[884,914,915,918],{},[899,916,917],{"align":889},"1.2",[899,919,920],{"align":889},"0.0247",[884,922,923,926],{},[899,924,925],{"align":889},"1.3",[899,927,928],{"align":889},[929,930,931],"strong",{},"0.0235",[884,933,934,937],{},[899,935,936],{"align":889},"1.4",[899,938,939],{"align":889},"0.0243",[884,941,942,945],{},[899,943,944],{"align":889},"1.6",[899,946,947],{"align":889},"0.0304",[884,949,950,953],{},[899,951,952],{"align":889},"2.0",[899,954,955],{"align":889},"0.0509",[884,957,958,961],{},[899,959,960],{"align":889},"5.0",[899,962,963],{"align":889},"0.1480",[884,965,966,969],{},[899,967,968],{"align":889},"10.0",[899,970,971],{"align":889},"0.1667",[884,973,974,977],{},[899,975,976],{"align":889},"15.0",[899,978,979],{"align":889},"0.1669",[884,981,982,985],{},[899,983,984],{"align":889},"20.0",[899,986,979],{"align":889},[11,988,989,990,993,994,997,998,1000,1001,1003,1004,1006,1007,1010,1011,1013,1014,1016,1017,1019],{},"Look at the last rows: from ",[867,991,992],{},"w=10"," to ",[867,995,996],{},"w=20",", the cost barely moves at all (",[867,999,971],{}," → ",[867,1002,979],{},"). That's not a coincidence, it's the sigmoid saturating: for large ",[867,1005,57],{},", ",[867,1008,1009],{},"sigmoid(wx+b)"," is already so close to ",[867,1012,101],{}," or ",[867,1015,77],{}," that pushing ",[867,1018,57],{}," even higher barely moves the output, and by extension barely moves the cost. The gradient in that region is tiny. If gradient descent lands there, it barely budges.",[11,1021,1022,1023,1026],{},"Rotate the chart below and compare it to ",[15,1024,1025],{"href":17},"linear regression's smooth bowl",": it's no longer a symmetric surface with one clean, well-defined bottom, it's got folds and a long plateau where the slope nearly vanishes.",[1028,1029],"cost-surface3d",{":b-max":82,":b-min":1030,":w-max":1031,":w-min":1032,":x-train":1033,":y-train":1034,"fn":1035,"height":1036},"-8","3","-2","[0,1,2,3,4,5]","[0,0,0,1,1,1]","sigmoid-squared-error","380px",[11,1038,1039],{},"Squared error isn't a bad idea by itself, it just implicitly assumes the noise in the data is well-behaved (gaussian), which makes sense for predicting a continuous number. Glued to a sigmoid, that assumption breaks, and the cost surface loses its guarantee of being a single clean bowl. Classification needs a loss function actually designed for it.",[21,1041,1043],{"id":1042},"the-logistic-loss-punishes-confident-mistakes-hard","The logistic loss: punishes confident mistakes hard",[11,1045,1046,1047,1049,1050,1052],{},"The idea behind the logistic loss is simple to explain with no formula at all first: if the correct label is ",[867,1048,77],{},", I want to punish hard when the model said \"almost certainly 0\", and barely punish at all when it said \"almost certainly 1\". And the mirror image for label ",[867,1051,101],{},". The formula, in two parts:",[28,1054,1057],{"className":1055},[1056],"katex-display",[28,1058,1060,1296],{"className":1059},[31],[28,1061,1063],{"className":1062},[35],[37,1064,1066],{"xmlns":39,"display":1065},"block",[41,1067,1068,1293],{},[44,1069,1070,1073,1076,1079,1081,1083,1095,1097,1109,1111,1113,1125,1127,1129],{},[47,1071,1072],{},"l",[47,1074,1075],{},"o",[47,1077,1078],{},"s",[47,1080,1078],{},[51,1082,54],{"stretchy":53},[119,1084,1085,1087],{},[47,1086,123],{},[44,1088,1089,1091,1093],{},[47,1090,57],{},[51,1092,61],{"separator":60},[47,1094,64],{},[51,1096,54],{"stretchy":53},[112,1098,1099,1101],{},[47,1100,138],{},[44,1102,1103,1105,1107],{},[51,1104,54],{"stretchy":53},[47,1106,96],{},[51,1108,67],{"stretchy":53},[51,1110,67],{"stretchy":53},[51,1112,61],{"separator":60},[112,1114,1115,1117],{},[47,1116,155],{},[44,1118,1119,1121,1123],{},[51,1120,54],{"stretchy":53},[47,1122,96],{},[51,1124,67],{"stretchy":53},[51,1126,67],{"stretchy":53},[51,1128,70],{},[44,1130,1131,1134],{},[51,1132,1133],{"fence":60},"{",[1135,1136,1139,1217],"mtable",{"rowspacing":1137,"columnalign":1138,"columnspacing":173},"0.36em","left left",[1140,1141,1142,1192],"mtr",{},[1143,1144,1145],"mtd",{},[1146,1147,1148],"mstyle",{"scriptlevel":101,"displaystyle":53},[44,1149,1150,1152,1155,1158],{},[51,1151,108],{},[47,1153,1154],{},"log",[51,1156,1157],{},"⁡",[44,1159,1160,1162,1174,1176,1188,1190],{},[51,1161,54],{"fence":60},[119,1163,1164,1166],{},[47,1165,123],{},[44,1167,1168,1170,1172],{},[47,1169,57],{},[51,1171,61],{"separator":60},[47,1173,64],{},[51,1175,54],{"stretchy":53},[112,1177,1178,1180],{},[47,1179,138],{},[44,1181,1182,1184,1186],{},[51,1183,54],{"stretchy":53},[47,1185,96],{},[51,1187,67],{"stretchy":53},[51,1189,67],{"stretchy":53},[51,1191,67],{"fence":60},[1143,1193,1194],{},[1146,1195,1196],{"scriptlevel":101,"displaystyle":53},[44,1197,1198,1201,1213,1215],{},[205,1199,1200],{},"if ",[112,1202,1203,1205],{},[47,1204,155],{},[44,1206,1207,1209,1211],{},[51,1208,54],{"stretchy":53},[47,1210,96],{},[51,1212,67],{"stretchy":53},[51,1214,70],{},[75,1216,77],{},[1140,1218,1219,1269],{},[1143,1220,1221],{},[1146,1222,1223],{"scriptlevel":101,"displaystyle":53},[44,1224,1225,1227,1229,1231],{},[51,1226,108],{},[47,1228,1154],{},[51,1230,1157],{},[44,1232,1233,1235,1237,1239,1251,1253,1265,1267],{},[51,1234,54],{"fence":60},[75,1236,77],{},[51,1238,108],{},[119,1240,1241,1243],{},[47,1242,123],{},[44,1244,1245,1247,1249],{},[47,1246,57],{},[51,1248,61],{"separator":60},[47,1250,64],{},[51,1252,54],{"stretchy":53},[112,1254,1255,1257],{},[47,1256,138],{},[44,1258,1259,1261,1263],{},[51,1260,54],{"stretchy":53},[47,1262,96],{},[51,1264,67],{"stretchy":53},[51,1266,67],{"stretchy":53},[51,1268,67],{"fence":60},[1143,1270,1271],{},[1146,1272,1273],{"scriptlevel":101,"displaystyle":53},[44,1274,1275,1277,1289,1291],{},[205,1276,1200],{},[112,1278,1279,1281],{},[47,1280,155],{},[44,1282,1283,1285,1287],{},[51,1284,54],{"stretchy":53},[47,1286,96],{},[51,1288,67],{"stretchy":53},[51,1290,70],{},[75,1292,101],{},[232,1294,1295],{"encoding":234},"loss(f_{w,b}(x^{(i)}), y^{(i)}) = \\begin{cases}\n-\\log\\left(f_{w,b}(x^{(i)})\\right) & \\text{if } y^{(i)}=1 \\\\\n-\\log\\left(1-f_{w,b}(x^{(i)})\\right) & \\text{if } y^{(i)}=0\n\\end{cases}",[28,1297,1299,1468],{"className":1298,"ariaHidden":60},[239],[28,1300,1302,1306,1310,1314,1317,1366,1369,1409,1412,1415,1418,1456,1459,1462,1465],{"className":1301},[243],[28,1303],{"className":1304,"style":1305},[247],"height:1.2241em;vertical-align:-0.2861em;",[28,1307,1072],{"className":1308,"style":1309},[252,253],"margin-right:0.0197em;",[28,1311,1313],{"className":1312},[252,253],"oss",[28,1315,54],{"className":1316},[258],[28,1318,1320,1323],{"className":1319},[252],[28,1321,123],{"className":1322,"style":496},[252,253],[28,1324,1326],{"className":1325},[403],[28,1327,1329,1358],{"className":1328},[309,310],[28,1330,1332,1355],{"className":1331},[314],[28,1333,1335],{"className":1334,"style":509},[318],[28,1336,1337,1340],{"style":512},[28,1338],{"className":1339,"style":420},[326],[28,1341,1343],{"className":1342},[331,332,333,334],[28,1344,1346,1349,1352],{"className":1345},[252,334],[28,1347,57],{"className":1348,"style":262},[252,253,334],[28,1350,61],{"className":1351},[266,334],[28,1353,64],{"className":1354},[252,253,334],[28,1356,374],{"className":1357},[373],[28,1359,1361],{"className":1360},[314],[28,1362,1364],{"className":1363,"style":540},[318],[28,1365],{},[28,1367,54],{"className":1368},[258],[28,1370,1372,1375],{"className":1371},[252],[28,1373,138],{"className":1374},[252,253],[28,1376,1378],{"className":1377},[403],[28,1379,1381],{"className":1380},[309],[28,1382,1384],{"className":1383},[314],[28,1385,1388],{"className":1386,"style":1387},[318],"height:0.938em;",[28,1389,1391,1394],{"style":1390},"top:-3.113em;margin-right:0.05em;",[28,1392],{"className":1393,"style":420},[326],[28,1395,1397],{"className":1396},[331,332,333,334],[28,1398,1400,1403,1406],{"className":1399},[252,334],[28,1401,54],{"className":1402},[258,334],[28,1404,96],{"className":1405},[252,253,334],[28,1407,67],{"className":1408},[277,334],[28,1410,67],{"className":1411},[277],[28,1413,61],{"className":1414},[266],[28,1416],{"className":1417,"style":270},[171],[28,1419,1421,1424],{"className":1420},[252],[28,1422,155],{"className":1423,"style":605},[252,253],[28,1425,1427],{"className":1426},[403],[28,1428,1430],{"className":1429},[309],[28,1431,1433],{"className":1432},[314],[28,1434,1436],{"className":1435,"style":1387},[318],[28,1437,1438,1441],{"style":1390},[28,1439],{"className":1440,"style":420},[326],[28,1442,1444],{"className":1443},[331,332,333,334],[28,1445,1447,1450,1453],{"className":1446},[252,334],[28,1448,54],{"className":1449},[258,334],[28,1451,96],{"className":1452},[252,253,334],[28,1454,67],{"className":1455},[277,334],[28,1457,67],{"className":1458},[277],[28,1460],{"className":1461,"style":281},[171],[28,1463,70],{"className":1464},[285],[28,1466],{"className":1467,"style":281},[171],[28,1469,1471,1475],{"className":1470},[243],[28,1472],{"className":1473,"style":1474},[247],"height:3em;vertical-align:-1.25em;",[28,1476,1478,1485,1951],{"className":1477},[476],[28,1479,1481],{"className":1480,"style":484},[258,483],[28,1482,1133],{"className":1483},[488,1484],"size4",[28,1486,1488],{"className":1487},[252],[28,1489,1491,1795,1800],{"className":1490},[1135],[28,1492,1495],{"className":1493},[1494],"col-align-l",[28,1496,1498,1786],{"className":1497},[309,310],[28,1499,1501,1783],{"className":1500},[314],[28,1502,1505,1640],{"className":1503,"style":1504},[318],"height:1.69em;",[28,1506,1508,1512],{"style":1507},"top:-3.69em;",[28,1509],{"className":1510,"style":1511},[326],"height:3.008em;",[28,1513,1515,1518,1521,1529,1532],{"className":1514},[252],[28,1516,108],{"className":1517},[252],[28,1519],{"className":1520,"style":270},[171],[28,1522,1524,1525],{"className":1523},[393],"lo",[28,1526,1528],{"style":1527},"margin-right:0.0139em;","g",[28,1530],{"className":1531,"style":270},[171],[28,1533,1535,1541,1590,1593,1631,1634],{"className":1534},[476],[28,1536,1538],{"className":1537,"style":484},[258,483],[28,1539,54],{"className":1540},[488,489],[28,1542,1544,1547],{"className":1543},[252],[28,1545,123],{"className":1546,"style":496},[252,253],[28,1548,1550],{"className":1549},[403],[28,1551,1553,1582],{"className":1552},[309,310],[28,1554,1556,1579],{"className":1555},[314],[28,1557,1559],{"className":1558,"style":509},[318],[28,1560,1561,1564],{"style":512},[28,1562],{"className":1563,"style":420},[326],[28,1565,1567],{"className":1566},[331,332,333,334],[28,1568,1570,1573,1576],{"className":1569},[252,334],[28,1571,57],{"className":1572,"style":262},[252,253,334],[28,1574,61],{"className":1575},[266,334],[28,1577,64],{"className":1578},[252,253,334],[28,1580,374],{"className":1581},[373],[28,1583,1585],{"className":1584},[314],[28,1586,1588],{"className":1587,"style":540},[318],[28,1589],{},[28,1591,54],{"className":1592},[258],[28,1594,1596,1599],{"className":1595},[252],[28,1597,138],{"className":1598},[252,253],[28,1600,1602],{"className":1601},[403],[28,1603,1605],{"className":1604},[309],[28,1606,1608],{"className":1607},[314],[28,1609,1611],{"className":1610,"style":564},[318],[28,1612,1613,1616],{"style":567},[28,1614],{"className":1615,"style":420},[326],[28,1617,1619],{"className":1618},[331,332,333,334],[28,1620,1622,1625,1628],{"className":1621},[252,334],[28,1623,54],{"className":1624},[258,334],[28,1626,96],{"className":1627},[252,253,334],[28,1629,67],{"className":1630},[277,334],[28,1632,67],{"className":1633},[277],[28,1635,1637],{"className":1636,"style":484},[277,483],[28,1638,67],{"className":1639},[488,489],[28,1641,1643,1646],{"style":1642},"top:-2.25em;",[28,1644],{"className":1645,"style":1511},[326],[28,1647,1649,1652,1655,1660,1663],{"className":1648},[252],[28,1650,108],{"className":1651},[252],[28,1653],{"className":1654,"style":270},[171],[28,1656,1524,1658],{"className":1657},[393],[28,1659,1528],{"style":1527},[28,1661],{"className":1662,"style":270},[171],[28,1664,1666,1672,1675,1678,1681,1684,1733,1736,1774,1777],{"className":1665},[476],[28,1667,1669],{"className":1668,"style":484},[258,483],[28,1670,54],{"className":1671},[488,489],[28,1673,77],{"className":1674},[252],[28,1676],{"className":1677,"style":592},[171],[28,1679,108],{"className":1680},[454],[28,1682],{"className":1683,"style":592},[171],[28,1685,1687,1690],{"className":1686},[252],[28,1688,123],{"className":1689,"style":496},[252,253],[28,1691,1693],{"className":1692},[403],[28,1694,1696,1725],{"className":1695},[309,310],[28,1697,1699,1722],{"className":1698},[314],[28,1700,1702],{"className":1701,"style":509},[318],[28,1703,1704,1707],{"style":512},[28,1705],{"className":1706,"style":420},[326],[28,1708,1710],{"className":1709},[331,332,333,334],[28,1711,1713,1716,1719],{"className":1712},[252,334],[28,1714,57],{"className":1715,"style":262},[252,253,334],[28,1717,61],{"className":1718},[266,334],[28,1720,64],{"className":1721},[252,253,334],[28,1723,374],{"className":1724},[373],[28,1726,1728],{"className":1727},[314],[28,1729,1731],{"className":1730,"style":540},[318],[28,1732],{},[28,1734,54],{"className":1735},[258],[28,1737,1739,1742],{"className":1738},[252],[28,1740,138],{"className":1741},[252,253],[28,1743,1745],{"className":1744},[403],[28,1746,1748],{"className":1747},[309],[28,1749,1751],{"className":1750},[314],[28,1752,1754],{"className":1753,"style":564},[318],[28,1755,1756,1759],{"style":567},[28,1757],{"className":1758,"style":420},[326],[28,1760,1762],{"className":1761},[331,332,333,334],[28,1763,1765,1768,1771],{"className":1764},[252,334],[28,1766,54],{"className":1767},[258,334],[28,1769,96],{"className":1770},[252,253,334],[28,1772,67],{"className":1773},[277,334],[28,1775,67],{"className":1776},[277],[28,1778,1780],{"className":1779,"style":484},[277,483],[28,1781,67],{"className":1782},[488,489],[28,1784,374],{"className":1785},[373],[28,1787,1789],{"className":1788},[314],[28,1790,1793],{"className":1791,"style":1792},[318],"height:1.19em;",[28,1794],{},[28,1796],{"className":1797,"style":1799},[1798],"arraycolsep","width:1em;",[28,1801,1803],{"className":1802},[1494],[28,1804,1806,1943],{"className":1805},[309,310],[28,1807,1809,1940],{"className":1808},[314],[28,1810,1812,1876],{"className":1811,"style":1504},[318],[28,1813,1814,1817],{"style":1507},[28,1815],{"className":1816,"style":1511},[326],[28,1818,1820,1826,1864,1867,1870,1873],{"className":1819},[252],[28,1821,1823],{"className":1822},[252,794],[28,1824,1200],{"className":1825},[252],[28,1827,1829,1832],{"className":1828},[252],[28,1830,155],{"className":1831,"style":605},[252,253],[28,1833,1835],{"className":1834},[403],[28,1836,1838],{"className":1837},[309],[28,1839,1841],{"className":1840},[314],[28,1842,1844],{"className":1843,"style":564},[318],[28,1845,1846,1849],{"style":567},[28,1847],{"className":1848,"style":420},[326],[28,1850,1852],{"className":1851},[331,332,333,334],[28,1853,1855,1858,1861],{"className":1854},[252,334],[28,1856,54],{"className":1857},[258,334],[28,1859,96],{"className":1860},[252,253,334],[28,1862,67],{"className":1863},[277,334],[28,1865],{"className":1866,"style":281},[171],[28,1868,70],{"className":1869},[285],[28,1871],{"className":1872,"style":281},[171],[28,1874,77],{"className":1875},[252],[28,1877,1878,1881],{"style":1642},[28,1879],{"className":1880,"style":1511},[326],[28,1882,1884,1890,1928,1931,1934,1937],{"className":1883},[252],[28,1885,1887],{"className":1886},[252,794],[28,1888,1200],{"className":1889},[252],[28,1891,1893,1896],{"className":1892},[252],[28,1894,155],{"className":1895,"style":605},[252,253],[28,1897,1899],{"className":1898},[403],[28,1900,1902],{"className":1901},[309],[28,1903,1905],{"className":1904},[314],[28,1906,1908],{"className":1907,"style":564},[318],[28,1909,1910,1913],{"style":567},[28,1911],{"className":1912,"style":420},[326],[28,1914,1916],{"className":1915},[331,332,333,334],[28,1917,1919,1922,1925],{"className":1918},[252,334],[28,1920,54],{"className":1921},[258,334],[28,1923,96],{"className":1924},[252,253,334],[28,1926,67],{"className":1927},[277,334],[28,1929],{"className":1930,"style":281},[171],[28,1932,70],{"className":1933},[285],[28,1935],{"className":1936,"style":281},[171],[28,1938,101],{"className":1939},[252],[28,1941,374],{"className":1942},[373],[28,1944,1946],{"className":1945},[314],[28,1947,1949],{"className":1948,"style":1792},[318],[28,1950],{},[28,1952],{"className":1953},[277,302],[1955,1956],"log-loss-curve-chart",{"x-label":1957,"y-label":1958,"y0-label":1959,"y1-label":1960},"f(x) (model's prediction)","loss","y=0 (−log(1−f))","y=1 (−log f)",[11,1962,1963,1964,1967,1968,1970,1971,1973,1974,1976,1977,1970,1979,1981,1982,1985,1986,1989],{},"Look at the blue curve (",[867,1965,1966],{},"y=1","): when ",[867,1969,123],{}," is close to ",[867,1972,77],{}," (the model got it right, confidently), the loss drops to nearly ",[867,1975,101],{},". When ",[867,1978,123],{},[867,1980,101],{}," (the model got it badly wrong, said \"almost certainly not\" for a case that was actually yes), the loss ",[929,1983,1984],{},"explodes",", heading toward infinity. The red curve (",[867,1987,1988],{},"y=0",") is the exact mirror, flipped around. Unlike squared error's parabola, these curves never flatten out: they always have slope, so gradient descent always has a clear direction to follow, no matter how bad the prediction is.",[21,1991,1993],{"id":1992},"one-single-line-ready-to-code","One single line, ready to code",[11,1995,1996,1997,2000,2001,2003,2004,1013,2006,2008,2009,2011,2012,2015],{},"Two formulas split by an ",[867,1998,1999],{},"if"," are annoying to program. Since ",[867,2002,155],{}," only ever takes ",[867,2005,101],{},[867,2007,77],{},", both can be combined into one line, using ",[867,2010,155],{}," and ",[867,2013,2014],{},"(1-y)"," as switches that turn each term on and off:",[11,2017,2018],{},[28,2019,2021,2159],{"className":2020},[31],[28,2022,2024],{"className":2023},[35],[37,2025,2026],{"xmlns":39},[41,2027,2028,2156],{},[44,2029,2030,2032,2034,2036,2038,2040,2042,2054,2056,2058,2092,2094,2096,2098,2100,2112,2114,2116,2118],{},[47,2031,1072],{},[47,2033,1075],{},[47,2035,1078],{},[47,2037,1078],{},[51,2039,70],{},[51,2041,108],{},[112,2043,2044,2046],{},[47,2045,155],{},[44,2047,2048,2050,2052],{},[51,2049,54],{"stretchy":53},[47,2051,96],{},[51,2053,67],{"stretchy":53},[47,2055,1154],{},[51,2057,1157],{},[44,2059,2060,2062,2074,2076,2088,2090],{},[51,2061,54],{"fence":60},[119,2063,2064,2066],{},[47,2065,123],{},[44,2067,2068,2070,2072],{},[47,2069,57],{},[51,2071,61],{"separator":60},[47,2073,64],{},[51,2075,54],{"stretchy":53},[112,2077,2078,2080],{},[47,2079,138],{},[44,2081,2082,2084,2086],{},[51,2083,54],{"stretchy":53},[47,2085,96],{},[51,2087,67],{"stretchy":53},[51,2089,67],{"stretchy":53},[51,2091,67],{"fence":60},[51,2093,108],{},[51,2095,54],{"stretchy":53},[75,2097,77],{},[51,2099,108],{},[112,2101,2102,2104],{},[47,2103,155],{},[44,2105,2106,2108,2110],{},[51,2107,54],{"stretchy":53},[47,2109,96],{},[51,2111,67],{"stretchy":53},[51,2113,67],{"stretchy":53},[47,2115,1154],{},[51,2117,1157],{},[44,2119,2120,2122,2124,2126,2138,2140,2152,2154],{},[51,2121,54],{"fence":60},[75,2123,77],{},[51,2125,108],{},[119,2127,2128,2130],{},[47,2129,123],{},[44,2131,2132,2134,2136],{},[47,2133,57],{},[51,2135,61],{"separator":60},[47,2137,64],{},[51,2139,54],{"stretchy":53},[112,2141,2142,2144],{},[47,2143,138],{},[44,2145,2146,2148,2150],{},[51,2147,54],{"stretchy":53},[47,2149,96],{},[51,2151,67],{"stretchy":53},[51,2153,67],{"stretchy":53},[51,2155,67],{"fence":60},[232,2157,2158],{"encoding":234},"loss = -y^{(i)}\\log\\left(f_{w,b}(x^{(i)})\\right) - (1-y^{(i)})\\log\\left(1-f_{w,b}(x^{(i)})\\right)",[28,2160,2162,2184,2360,2381],{"className":2161,"ariaHidden":60},[239],[28,2163,2165,2169,2172,2175,2178,2181],{"className":2164},[243],[28,2166],{"className":2167,"style":2168},[247],"height:0.6944em;",[28,2170,1072],{"className":2171,"style":1309},[252,253],[28,2173,1313],{"className":2174},[252,253],[28,2176],{"className":2177,"style":281},[171],[28,2179,70],{"className":2180},[285],[28,2182],{"className":2183,"style":281},[171],[28,2185,2187,2191,2194,2232,2235,2240,2243,2351,2354,2357],{"className":2186},[243],[28,2188],{"className":2189,"style":2190},[247],"height:1.238em;vertical-align:-0.35em;",[28,2192,108],{"className":2193},[252],[28,2195,2197,2200],{"className":2196},[252],[28,2198,155],{"className":2199,"style":605},[252,253],[28,2201,2203],{"className":2202},[403],[28,2204,2206],{"className":2205},[309],[28,2207,2209],{"className":2208},[314],[28,2210,2212],{"className":2211,"style":564},[318],[28,2213,2214,2217],{"style":567},[28,2215],{"className":2216,"style":420},[326],[28,2218,2220],{"className":2219},[331,332,333,334],[28,2221,2223,2226,2229],{"className":2222},[252,334],[28,2224,54],{"className":2225},[258,334],[28,2227,96],{"className":2228},[252,253,334],[28,2230,67],{"className":2231},[277,334],[28,2233],{"className":2234,"style":270},[171],[28,2236,1524,2238],{"className":2237},[393],[28,2239,1528],{"style":1527},[28,2241],{"className":2242,"style":270},[171],[28,2244,2246,2252,2301,2304,2342,2345],{"className":2245},[476],[28,2247,2249],{"className":2248,"style":484},[258,483],[28,2250,54],{"className":2251},[488,489],[28,2253,2255,2258],{"className":2254},[252],[28,2256,123],{"className":2257,"style":496},[252,253],[28,2259,2261],{"className":2260},[403],[28,2262,2264,2293],{"className":2263},[309,310],[28,2265,2267,2290],{"className":2266},[314],[28,2268,2270],{"className":2269,"style":509},[318],[28,2271,2272,2275],{"style":512},[28,2273],{"className":2274,"style":420},[326],[28,2276,2278],{"className":2277},[331,332,333,334],[28,2279,2281,2284,2287],{"className":2280},[252,334],[28,2282,57],{"className":2283,"style":262},[252,253,334],[28,2285,61],{"className":2286},[266,334],[28,2288,64],{"className":2289},[252,253,334],[28,2291,374],{"className":2292},[373],[28,2294,2296],{"className":2295},[314],[28,2297,2299],{"className":2298,"style":540},[318],[28,2300],{},[28,2302,54],{"className":2303},[258],[28,2305,2307,2310],{"className":2306},[252],[28,2308,138],{"className":2309},[252,253],[28,2311,2313],{"className":2312},[403],[28,2314,2316],{"className":2315},[309],[28,2317,2319],{"className":2318},[314],[28,2320,2322],{"className":2321,"style":564},[318],[28,2323,2324,2327],{"style":567},[28,2325],{"className":2326,"style":420},[326],[28,2328,2330],{"className":2329},[331,332,333,334],[28,2331,2333,2336,2339],{"className":2332},[252,334],[28,2334,54],{"className":2335},[258,334],[28,2337,96],{"className":2338},[252,253,334],[28,2340,67],{"className":2341},[277,334],[28,2343,67],{"className":2344},[277],[28,2346,2348],{"className":2347,"style":484},[277,483],[28,2349,67],{"className":2350},[488,489],[28,2352],{"className":2353,"style":592},[171],[28,2355,108],{"className":2356},[454],[28,2358],{"className":2359,"style":592},[171],[28,2361,2363,2366,2369,2372,2375,2378],{"className":2362},[243],[28,2364],{"className":2365,"style":248},[247],[28,2367,54],{"className":2368},[258],[28,2370,77],{"className":2371},[252],[28,2373],{"className":2374,"style":592},[171],[28,2376,108],{"className":2377},[454],[28,2379],{"className":2380,"style":592},[171],[28,2382,2384,2387,2425,2428,2431,2436,2439],{"className":2383},[243],[28,2385],{"className":2386,"style":2190},[247],[28,2388,2390,2393],{"className":2389},[252],[28,2391,155],{"className":2392,"style":605},[252,253],[28,2394,2396],{"className":2395},[403],[28,2397,2399],{"className":2398},[309],[28,2400,2402],{"className":2401},[314],[28,2403,2405],{"className":2404,"style":564},[318],[28,2406,2407,2410],{"style":567},[28,2408],{"className":2409,"style":420},[326],[28,2411,2413],{"className":2412},[331,332,333,334],[28,2414,2416,2419,2422],{"className":2415},[252,334],[28,2417,54],{"className":2418},[258,334],[28,2420,96],{"className":2421},[252,253,334],[28,2423,67],{"className":2424},[277,334],[28,2426,67],{"className":2427},[277],[28,2429],{"className":2430,"style":270},[171],[28,2432,1524,2434],{"className":2433},[393],[28,2435,1528],{"style":1527},[28,2437],{"className":2438,"style":270},[171],[28,2440,2442,2448,2451,2454,2457,2460,2509,2512,2550,2553],{"className":2441},[476],[28,2443,2445],{"className":2444,"style":484},[258,483],[28,2446,54],{"className":2447},[488,489],[28,2449,77],{"className":2450},[252],[28,2452],{"className":2453,"style":592},[171],[28,2455,108],{"className":2456},[454],[28,2458],{"className":2459,"style":592},[171],[28,2461,2463,2466],{"className":2462},[252],[28,2464,123],{"className":2465,"style":496},[252,253],[28,2467,2469],{"className":2468},[403],[28,2470,2472,2501],{"className":2471},[309,310],[28,2473,2475,2498],{"className":2474},[314],[28,2476,2478],{"className":2477,"style":509},[318],[28,2479,2480,2483],{"style":512},[28,2481],{"className":2482,"style":420},[326],[28,2484,2486],{"className":2485},[331,332,333,334],[28,2487,2489,2492,2495],{"className":2488},[252,334],[28,2490,57],{"className":2491,"style":262},[252,253,334],[28,2493,61],{"className":2494},[266,334],[28,2496,64],{"className":2497},[252,253,334],[28,2499,374],{"className":2500},[373],[28,2502,2504],{"className":2503},[314],[28,2505,2507],{"className":2506,"style":540},[318],[28,2508],{},[28,2510,54],{"className":2511},[258],[28,2513,2515,2518],{"className":2514},[252],[28,2516,138],{"className":2517},[252,253],[28,2519,2521],{"className":2520},[403],[28,2522,2524],{"className":2523},[309],[28,2525,2527],{"className":2526},[314],[28,2528,2530],{"className":2529,"style":564},[318],[28,2531,2532,2535],{"style":567},[28,2533],{"className":2534,"style":420},[326],[28,2536,2538],{"className":2537},[331,332,333,334],[28,2539,2541,2544,2547],{"className":2540},[252,334],[28,2542,54],{"className":2543},[258,334],[28,2545,96],{"className":2546},[252,253,334],[28,2548,67],{"className":2549},[277,334],[28,2551,67],{"className":2552},[277],[28,2554,2556],{"className":2555,"style":484},[277,483],[28,2557,67],{"className":2558},[488,489],[11,2560,2561,2562,2564,2565,2568,2569,2572,2573,2575,2576,2579,2580,2582],{},"When ",[867,2563,1966],{},", the second term zeroes out (",[867,2566,2567],{},"1-1=0",") and only ",[867,2570,2571],{},"-log(f)"," survives. When ",[867,2574,1988],{},", the first term zeroes out and only ",[867,2577,2578],{},"-log(1-f)"," survives. The same line of code covers both cases, no ",[867,2581,1999],{}," needed.",[21,2584,2586],{"id":2585},"wrapping-up","Wrapping up",[878,2588,2589,2600],{},[881,2590,2591],{},[884,2592,2593,2597],{},[887,2594,2596],{"align":2595},"left","What I already knew",[887,2598,2599],{"align":2595},"What this lecture settled",[894,2601,2602,2610,2618],{},[884,2603,2604,2607],{},[899,2605,2606],{"align":2595},"Squared error gives linear regression a smooth bowl",[899,2608,2609],{"align":2595},"Squared error + sigmoid no longer gives a bowl, it has plateaus where the gradient nearly disappears",[884,2611,2612,2615],{},[899,2613,2614],{"align":2595},"A loss function measures one example's error",[899,2616,2617],{"align":2595},"The logistic loss punishes confident mistakes hard and barely touches confident correct answers, never flattening out",[884,2619,2620,2629],{},[899,2621,2622,2624,2625,2628],{"align":2595},[867,2623,1999],{},"\u002F",[867,2626,2627],{},"else"," splits cases",[899,2630,2631,2011,2633,2635,2636,2638],{"align":2595},[867,2632,155],{},[867,2634,2014],{}," as switches combine both cases into one formula, no ",[867,2637,1999],{}," needed",[21,2640,2642],{"id":2641},"practical-application","Practical Application",[11,2644,2645,2646,2650,2651,1006,2654,2657],{},"Using the logistic model already fit ",[15,2647,2649],{"href":2648},"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab02-sigmoid-function","in the sigmoid lab"," (",[867,2652,2653],{},"w=3.9565, b=-1.1326",[867,2655,2656],{},"worst concave points"," variable), I compute the loss for three real test-set patients, chosen to show both extremes and the middle:",[2659,2660,2665],"pre",{"className":2661,"code":2662,"language":2663,"meta":2664,"style":2664},"language-python shiki shiki-themes github-light github-dark","for name, x, y_real in patients:\n    f = sigmoid(w*x + b)\n    loss = -y_real*np.log(f) - (1-y_real)*np.log(1-f)\n    print(f\"{name}: f={f:.4f} loss={loss:.4f}\")\n","python","",[867,2666,2667,2674,2680,2686],{"__ignoreMap":2664},[28,2668,2671],{"class":2669,"line":2670},"line",1,[28,2672,2673],{},"for name, x, y_real in patients:\n",[28,2675,2677],{"class":2669,"line":2676},2,[28,2678,2679],{},"    f = sigmoid(w*x + b)\n",[28,2681,2683],{"class":2669,"line":2682},3,[28,2684,2685],{},"    loss = -y_real*np.log(f) - (1-y_real)*np.log(1-f)\n",[28,2687,2689],{"class":2669,"line":2688},4,[28,2690,2691],{},"    print(f\"{name}: f={f:.4f} loss={loss:.4f}\")\n",[2693,2694,2695,2700],"blockquote",{},[11,2696,2697],{},[929,2698,2699],{},"Output:",[878,2701,2702,2720],{},[881,2703,2704],{},[884,2705,2706,2709,2711,2715,2718],{},[887,2707,2708],{"align":2595},"Patient",[887,2710,2656],{"align":889},[887,2712,2714],{"align":2713},"center","true y",[887,2716,2717],{"align":889},"f(x)",[887,2719,1958],{"align":889},[894,2721,2722,2738,2753],{},[884,2723,2724,2727,2730,2732,2735],{},[899,2725,2726],{"align":2595},"Clearly malignant",[899,2728,2729],{"align":889},"0.2867",[899,2731,77],{"align":2713},[899,2733,2734],{"align":889},"0.9999",[899,2736,2737],{"align":889},"0.0001",[884,2739,2740,2743,2746,2748,2751],{},[899,2741,2742],{"align":2595},"Clearly benign",[899,2744,2745],{"align":889},"0.0000",[899,2747,101],{"align":2713},[899,2749,2750],{"align":889},"0.0003",[899,2752,2750],{"align":889},[884,2754,2755,2758,2761,2763,2766],{},[899,2756,2757],{"align":2595},"Ambiguous",[899,2759,2760],{"align":889},"0.1335",[899,2762,101],{"align":2713},[899,2764,2765],{"align":889},"0.5097",[899,2767,2768],{"align":889},"0.7127",[11,2770,2771,2772,2775,2776,2778],{},"The model gets the first two patients right with total confidence, their loss is practically zero. The third is the ambiguous case, sitting right on the decision boundary (the model gave it a ",[867,2773,2774],{},"51%"," chance of being malignant, but the patient was benign), and that single patient's loss (",[867,2777,2768],{},") is already bigger than the other two combined. It's exactly this kind of point, near the boundary and misclassified, that pushes the fit hardest during training, because it's the one carrying the high loss.",[2780,2781,2782],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":2664,"searchDepth":2676,"depth":2676,"links":2784},[2785,2786,2787,2788,2789],{"id":23,"depth":2676,"text":24},{"id":1042,"depth":2676,"text":1043},{"id":1992,"depth":2676,"text":1993},{"id":2585,"depth":2676,"text":2586},{"id":2641,"depth":2676,"text":2642},null,"2026-09-04","Week 3, Lab 4: the same cost function that worked so well for linear regression turns into a surface full of plateaus once it's squeezed behind a sigmoid. The fix is to swap the loss function, not the model.","md",{},true,15,"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab04-logistic-loss","machine-learning-specialization",{"title":6,"description":2792},"published","en\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab04-logistic-loss",[2803,2804,2805],"classification","logistic-regression","cost-function","DBauEJBxEhFpjAcl58xjs_iJ02G3hqGGVwuac3ZE8wY",1788965100591]