[{"data":1,"prerenderedAt":1343},["ShallowReactive",2],{"lang-switch-post-\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab02-sigmoid-function":3,"post-en-machine-learning-specialization-w3-lab02-sigmoid-function":4},"\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab02-sigmoid-function",{"id":5,"title":6,"body":7,"cover":1326,"date":1327,"description":1328,"extension":1329,"meta":1330,"navigation":1331,"order":1332,"path":1333,"playlist":1334,"seo":1335,"status":1336,"stem":1337,"tags":1338,"__hash__":1342},"posts\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab02-sigmoid-function.md","The Sigmoid Function: Putting a Ceiling on Regression",{"type":8,"value":9,"toc":1319},"minimark",[10,32,37,291,335,363,442,528,532,536,647,1018,1145,1149,1152,1167,1186,1190,1233,1237,1249,1258,1268,1276,1291,1308,1315],[11,12,13,18,19,23,24,27,28,31],"p",{},[14,15,17],"a",{"href":16},"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab01-classification","In the last lab",", linear regression's raw output reached ",[20,21,22],"code",{},"1.4043"," for one real patient, a number that means nothing as a \"probability of cancer\". It was missing a ceiling. That's exactly what the sigmoid function (also called the logistic function) fixes: it takes any number, positive, negative, huge, tiny, and always returns something between ",[20,25,26],{},"0"," and ",[20,29,30],{},"1",".",[33,34,36],"h2",{"id":35},"the-formula-no-drama","The formula, no drama",[11,38,39],{},[40,41,44,107],"span",{"className":42},[43],"katex",[40,45,48],{"className":46},[47],"katex-mathml",[49,50,52],"math",{"xmlns":51},"http:\u002F\u002Fwww.w3.org\u002F1998\u002FMath\u002FMathML",[53,54,55,102],"semantics",{},[56,57,58,62,67,70,73,76],"mrow",{},[59,60,61],"mi",{},"g",[63,64,66],"mo",{"stretchy":65},"false","(",[59,68,69],{},"z",[63,71,72],{"stretchy":65},")",[63,74,75],{},"=",[77,78,79,82],"mfrac",{},[80,81,30],"mn",{},[56,83,84,86,89],{},[80,85,30],{},[63,87,88],{},"+",[90,91,92,95],"msup",{},[59,93,94],{},"e",[56,96,97,100],{},[63,98,99],{},"−",[59,101,69],{},[103,104,106],"annotation",{"encoding":105},"application\u002Fx-tex","g(z) = \\frac{1}{1+e^{-z}}",[40,108,112,151],{"className":109,"ariaHidden":111},[110],"katex-html","true",[40,113,116,121,127,131,135,139,144,148],{"className":114},[115],"base",[40,117],{"className":118,"style":120},[119],"strut","height:1em;vertical-align:-0.25em;",[40,122,61],{"className":123,"style":126},[124,125],"mord","mathnormal","margin-right:0.0359em;",[40,128,66],{"className":129},[130],"mopen",[40,132,69],{"className":133,"style":134},[124,125],"margin-right:0.044em;",[40,136,72],{"className":137},[138],"mclose",[40,140],{"className":141,"style":143},[142],"mspace","margin-right:0.2778em;",[40,145,75],{"className":146},[147],"mrel",[40,149],{"className":150,"style":143},[142],[40,152,154,158],{"className":153},[115],[40,155],{"className":156,"style":157},[119],"height:1.2484em;vertical-align:-0.4033em;",[40,159,161,165,288],{"className":160},[124],[40,162],{"className":163},[130,164],"nulldelimiter",[40,166,168],{"className":167},[77],[40,169,173,279],{"className":170},[171,172],"vlist-t","vlist-t2",[40,174,177,274],{"className":175},[176],"vlist-r",[40,178,182,248,259],{"className":179,"style":181},[180],"vlist","height:0.8451em;",[40,183,185,190],{"style":184},"top:-2.655em;",[40,186],{"className":187,"style":189},[188],"pstrut","height:3em;",[40,191,197],{"className":192},[193,194,195,196],"sizing","reset-size6","size3","mtight",[40,198,200,203,207],{"className":199},[124,196],[40,201,30],{"className":202},[124,196],[40,204,88],{"className":205},[206,196],"mbin",[40,208,210,213],{"className":209},[124,196],[40,211,94],{"className":212},[124,125,196],[40,214,217],{"className":215},[216],"msupsub",[40,218,220],{"className":219},[171],[40,221,223],{"className":222},[176],[40,224,227],{"className":225,"style":226},[180],"height:0.7027em;",[40,228,230,234],{"style":229},"top:-2.786em;margin-right:0.0714em;",[40,231],{"className":232,"style":233},[188],"height:2.5em;",[40,235,239],{"className":236},[193,237,238,196],"reset-size3","size1",[40,240,242,245],{"className":241},[124,196],[40,243,99],{"className":244},[124,196],[40,246,69],{"className":247,"style":134},[124,125,196],[40,249,251,254],{"style":250},"top:-3.23em;",[40,252],{"className":253,"style":189},[188],[40,255],{"className":256,"style":258},[257],"frac-line","border-bottom-width:0.04em;",[40,260,262,265],{"style":261},"top:-3.394em;",[40,263],{"className":264,"style":189},[188],[40,266,268],{"className":267},[193,194,195,196],[40,269,271],{"className":270},[124,196],[40,272,30],{"className":273},[124,196],[40,275,278],{"className":276},[277],"vlist-s","​",[40,280,282],{"className":281},[176],[40,283,286],{"className":284,"style":285},[180],"height:0.4033em;",[40,287],{},[40,289],{"className":290},[138,164],[11,292,293,294,296,297,300,301,303,304,306,307,309,310,312,313,315,316,319,320,323,324,328,329,331,332,334],{},"You don't need to memorize this to understand what it does: when ",[20,295,69],{}," is very negative, ",[20,298,299],{},"e^(-z)"," blows up and the fraction goes to nearly ",[20,302,26],{},". When ",[20,305,69],{}," is very positive, ",[20,308,299],{}," shrinks to nearly ",[20,311,26],{}," and the fraction goes to nearly ",[20,314,30],{},". Right in the middle, ",[20,317,318],{},"z=0",", it's exactly ",[20,321,322],{},"0.5",". It never actually ",[325,326,327],"strong",{},"reaches"," ",[20,330,26],{}," or ",[20,333,30],{},", only gets closer and closer.",[336,337,342],"pre",{"className":338,"code":339,"language":340,"meta":341,"style":341},"language-python shiki shiki-themes github-light github-dark","def sigmoid(z):\n    g = 1\u002F(1+np.exp(-z))\n    return g\n","python","",[20,343,344,351,357],{"__ignoreMap":341},[40,345,348],{"class":346,"line":347},"line",1,[40,349,350],{},"def sigmoid(z):\n",[40,352,354],{"class":346,"line":353},2,[40,355,356],{},"    g = 1\u002F(1+np.exp(-z))\n",[40,358,360],{"class":346,"line":359},3,[40,361,362],{},"    return g\n",[11,364,365,366,369,370,432,433,435,436,441],{},"Four lines. ",[20,367,368],{},"np.exp"," computes ",[40,371,373,391],{"className":372},[43],[40,374,376],{"className":375},[47],[49,377,378],{"xmlns":51},[53,379,380,388],{},[56,381,382],{},[90,383,384,386],{},[59,385,94],{},[59,387,69],{},[103,389,390],{"encoding":105},"e^z",[40,392,394],{"className":393,"ariaHidden":111},[110],[40,395,397,401],{"className":396},[115],[40,398],{"className":399,"style":400},[119],"height:0.6644em;",[40,402,404,407],{"className":403},[124],[40,405,94],{"className":406},[124,125],[40,408,410],{"className":409},[216],[40,411,413],{"className":412},[171],[40,414,416],{"className":415},[176],[40,417,419],{"className":418,"style":400},[180],[40,420,422,426],{"style":421},"top:-3.063em;margin-right:0.05em;",[40,423],{"className":424,"style":425},[188],"height:2.7em;",[40,427,429],{"className":428},[193,194,195,196],[40,430,69],{"className":431,"style":134},[124,125,196]," element by element, so this same function works whether ",[20,434,69],{}," is a single number or a whole array at once (",[437,438,440],"glossary-term",{"definition":439},"doing the math over the whole array at once, instead of looping item by item","vectorization",").",[443,444,445,454],"blockquote",{},[11,446,447,450,451,453],{},[325,448,449],{},"Output"," (",[20,452,69],{}," from -10 to 10, a few values):",[455,456,457,470],"table",{},[458,459,460],"thead",{},[461,462,463,467],"tr",{},[464,465,69],"th",{"align":466},"right",[464,468,469],{"align":466},"sigmoid(z)",[471,472,473,482,490,498,505,512,520],"tbody",{},[461,474,475,479],{},[476,477,478],"td",{"align":466},"-10",[476,480,481],{"align":466},"0.0000",[461,483,484,487],{},[476,485,486],{"align":466},"-2",[476,488,489],{"align":466},"0.1192",[461,491,492,495],{},[476,493,494],{"align":466},"-1",[476,496,497],{"align":466},"0.2689",[461,499,500,502],{},[476,501,26],{"align":466},[476,503,504],{"align":466},"0.5000",[461,506,507,509],{},[476,508,30],{"align":466},[476,510,511],{"align":466},"0.7311",[461,513,514,517],{},[476,515,516],{"align":466},"2",[476,518,519],{"align":466},"0.8808",[461,521,522,525],{},[476,523,524],{"align":466},"10",[476,526,527],{"align":466},"1.0000",[529,530],"sigmoid-curve-chart",{"curve-label":469,"threshold-label":531,"x-label":69,"y-label":469},"threshold (z=0, sigmoid=0.5)",[33,533,535],{"id":534},"logistic-regression-linear-regression-with-a-built-in-ceiling","Logistic regression: linear regression with a built-in ceiling",[11,537,538,539,646],{},"Logistic regression is just that: take the usual linear model, ",[40,540,542,573],{"className":541},[43],[40,543,545],{"className":544},[47],[49,546,547],{"xmlns":51},[53,548,549,570],{},[56,550,551,553,555,559,562,565,567],{},[59,552,69],{},[63,554,75],{},[59,556,558],{"mathvariant":557},"bold","w",[63,560,561],{},"⋅",[59,563,564],{"mathvariant":557},"x",[63,566,88],{},[59,568,569],{},"b",[103,571,572],{"encoding":105},"z = \\mathbf{w}\\cdot\\mathbf{x}+b",[40,574,576,595,617,636],{"className":575,"ariaHidden":111},[110],[40,577,579,583,586,589,592],{"className":578},[115],[40,580],{"className":581,"style":582},[119],"height:0.4306em;",[40,584,69],{"className":585,"style":134},[124,125],[40,587],{"className":588,"style":143},[142],[40,590,75],{"className":591},[147],[40,593],{"className":594,"style":143},[142],[40,596,598,602,607,611,614],{"className":597},[115],[40,599],{"className":600,"style":601},[119],"height:0.4445em;",[40,603,558],{"className":604,"style":606},[124,605],"mathbf","margin-right:0.016em;",[40,608],{"className":609,"style":610},[142],"margin-right:0.2222em;",[40,612,561],{"className":613},[206],[40,615],{"className":616,"style":610},[142],[40,618,620,624,627,630,633],{"className":619},[115],[40,621],{"className":622,"style":623},[119],"height:0.6667em;vertical-align:-0.0833em;",[40,625,564],{"className":626},[124,605],[40,628],{"className":629,"style":610},[142],[40,631,88],{"className":632},[206],[40,634],{"className":635,"style":610},[142],[40,637,639,643],{"className":638},[115],[40,640],{"className":641,"style":642},[119],"height:0.6944em;",[40,644,569],{"className":645},[124,125],", and run the result through the sigmoid.",[11,648,649],{},[40,650,652,737],{"className":651},[43],[40,653,655],{"className":654},[47],[49,656,657],{"xmlns":51},[53,658,659,734],{},[56,660,661,676,678,680,682,684,686,688,690,692,694,696,698,700,702],{},[662,663,664,667],"msub",{},[59,665,666],{},"f",[56,668,669,671,674],{},[59,670,558],{"mathvariant":557},[63,672,673],{"separator":111},",",[59,675,569],{},[63,677,66],{"stretchy":65},[59,679,564],{"mathvariant":557},[63,681,72],{"stretchy":65},[63,683,75],{},[59,685,61],{},[63,687,66],{"stretchy":65},[59,689,558],{"mathvariant":557},[63,691,561],{},[59,693,564],{"mathvariant":557},[63,695,88],{},[59,697,569],{},[63,699,72],{"stretchy":65},[63,701,75],{},[77,703,704,706],{},[80,705,30],{},[56,707,708,710,712],{},[80,709,30],{},[63,711,88],{},[90,713,714,716],{},[59,715,94],{},[56,717,718,720,722,724,726,728,730,732],{},[63,719,99],{},[63,721,66],{"stretchy":65},[59,723,558],{"mathvariant":557},[63,725,561],{},[59,727,564],{"mathvariant":557},[63,729,88],{},[59,731,569],{},[63,733,72],{"stretchy":65},[103,735,736],{"encoding":105},"f_{\\mathbf{w},b}(\\mathbf{x}) = g(\\mathbf{w}\\cdot\\mathbf{x}+b) = \\frac{1}{1+e^{-(\\mathbf{w}\\cdot\\mathbf{x}+b)}}",[40,738,740,819,843,861,882],{"className":739,"ariaHidden":111},[110],[40,741,743,747,801,804,807,810,813,816],{"className":742},[115],[40,744],{"className":745,"style":746},[119],"height:1.0361em;vertical-align:-0.2861em;",[40,748,750,754],{"className":749},[124],[40,751,666],{"className":752,"style":753},[124,125],"margin-right:0.1076em;",[40,755,757],{"className":756},[216],[40,758,760,792],{"className":759},[171,172],[40,761,763,789],{"className":762},[176],[40,764,767],{"className":765,"style":766},[180],"height:0.3361em;",[40,768,770,773],{"style":769},"top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;",[40,771],{"className":772,"style":425},[188],[40,774,776],{"className":775},[193,194,195,196],[40,777,779,782,786],{"className":778},[124,196],[40,780,558],{"className":781,"style":606},[124,605,196],[40,783,673],{"className":784},[785,196],"mpunct",[40,787,569],{"className":788},[124,125,196],[40,790,278],{"className":791},[277],[40,793,795],{"className":794},[176],[40,796,799],{"className":797,"style":798},[180],"height:0.2861em;",[40,800],{},[40,802,66],{"className":803},[130],[40,805,564],{"className":806},[124,605],[40,808,72],{"className":809},[138],[40,811],{"className":812,"style":143},[142],[40,814,75],{"className":815},[147],[40,817],{"className":818,"style":143},[142],[40,820,822,825,828,831,834,837,840],{"className":821},[115],[40,823],{"className":824,"style":120},[119],[40,826,61],{"className":827,"style":126},[124,125],[40,829,66],{"className":830},[130],[40,832,558],{"className":833,"style":606},[124,605],[40,835],{"className":836,"style":610},[142],[40,838,561],{"className":839},[206],[40,841],{"className":842,"style":610},[142],[40,844,846,849,852,855,858],{"className":845},[115],[40,847],{"className":848,"style":623},[119],[40,850,564],{"className":851},[124,605],[40,853],{"className":854,"style":610},[142],[40,856,88],{"className":857},[206],[40,859],{"className":860,"style":610},[142],[40,862,864,867,870,873,876,879],{"className":863},[115],[40,865],{"className":866,"style":120},[119],[40,868,569],{"className":869},[124,125],[40,871,72],{"className":872},[138],[40,874],{"className":875,"style":143},[142],[40,877,75],{"className":878},[147],[40,880],{"className":881,"style":143},[142],[40,883,885,889],{"className":884},[115],[40,886],{"className":887,"style":888},[119],"height:1.2889em;vertical-align:-0.4438em;",[40,890,892,895,1015],{"className":891},[124],[40,893],{"className":894},[130,164],[40,896,898],{"className":897},[77],[40,899,901,1006],{"className":900},[171,172],[40,902,904,1003],{"className":903},[176],[40,905,907,981,989],{"className":906,"style":181},[180],[40,908,910,913],{"style":909},"top:-2.6146em;",[40,911],{"className":912,"style":189},[188],[40,914,916],{"className":915},[193,194,195,196],[40,917,919,922,925],{"className":918},[124,196],[40,920,30],{"className":921},[124,196],[40,923,88],{"className":924},[206,196],[40,926,928,931],{"className":927},[124,196],[40,929,94],{"className":930},[124,125,196],[40,932,934],{"className":933},[216],[40,935,937],{"className":936},[171],[40,938,940],{"className":939},[176],[40,941,944],{"className":942,"style":943},[180],"height:0.822em;",[40,945,947,951],{"style":946},"top:-2.822em;margin-right:0.0714em;",[40,948],{"className":949,"style":950},[188],"height:2.5357em;",[40,952,954],{"className":953},[193,237,238,196],[40,955,957,960,963,966,969,972,975,978],{"className":956},[124,196],[40,958,99],{"className":959},[124,196],[40,961,66],{"className":962},[130,196],[40,964,558],{"className":965,"style":606},[124,605,196],[40,967,561],{"className":968},[206,196],[40,970,564],{"className":971},[124,605,196],[40,973,88],{"className":974},[206,196],[40,976,569],{"className":977},[124,125,196],[40,979,72],{"className":980},[138,196],[40,982,983,986],{"style":250},[40,984],{"className":985,"style":189},[188],[40,987],{"className":988,"style":258},[257],[40,990,991,994],{"style":261},[40,992],{"className":993,"style":189},[188],[40,995,997],{"className":996},[193,194,195,196],[40,998,1000],{"className":999},[124,196],[40,1001,30],{"className":1002},[124,196],[40,1004,278],{"className":1005},[277],[40,1007,1009],{"className":1008},[176],[40,1010,1013],{"className":1011,"style":1012},[180],"height:0.4438em;",[40,1014],{},[40,1016],{"className":1017},[138,164],[11,1019,1020,1021,1121,1122,1125,1126,1129,1130,1132,1133,1135,1136,1139,1140,1142,1143,31],{},"The output ",[40,1022,1024,1054],{"className":1023},[43],[40,1025,1027],{"className":1026},[47],[49,1028,1029],{"xmlns":51},[53,1030,1031,1051],{},[56,1032,1033,1045,1047,1049],{},[662,1034,1035,1037],{},[59,1036,666],{},[56,1038,1039,1041,1043],{},[59,1040,558],{"mathvariant":557},[63,1042,673],{"separator":111},[59,1044,569],{},[63,1046,66],{"stretchy":65},[59,1048,564],{"mathvariant":557},[63,1050,72],{"stretchy":65},[103,1052,1053],{"encoding":105},"f_{\\mathbf{w},b}(\\mathbf{x})",[40,1055,1057],{"className":1056,"ariaHidden":111},[110],[40,1058,1060,1063,1112,1115,1118],{"className":1059},[115],[40,1061],{"className":1062,"style":746},[119],[40,1064,1066,1069],{"className":1065},[124],[40,1067,666],{"className":1068,"style":753},[124,125],[40,1070,1072],{"className":1071},[216],[40,1073,1075,1104],{"className":1074},[171,172],[40,1076,1078,1101],{"className":1077},[176],[40,1079,1081],{"className":1080,"style":766},[180],[40,1082,1083,1086],{"style":769},[40,1084],{"className":1085,"style":425},[188],[40,1087,1089],{"className":1088},[193,194,195,196],[40,1090,1092,1095,1098],{"className":1091},[124,196],[40,1093,558],{"className":1094,"style":606},[124,605,196],[40,1096,673],{"className":1097},[785,196],[40,1099,569],{"className":1100},[124,125,196],[40,1102,278],{"className":1103},[277],[40,1105,1107],{"className":1106},[176],[40,1108,1110],{"className":1109,"style":798},[180],[40,1111],{},[40,1113,66],{"className":1114},[130],[40,1116,564],{"className":1117},[124,605],[40,1119,72],{"className":1120},[138]," is now interpreted as a ",[325,1123,1124],{},"probability",": the estimated chance of ",[20,1127,1128],{},"y=1"," given ",[20,1131,564],{},". To turn it into a final decision, the same ",[20,1134,322],{}," cutoff as before: ",[20,1137,1138],{},"f >= 0.5"," predicts ",[20,1141,30],{},", otherwise ",[20,1144,26],{},[33,1146,1148],{"id":1147},"the-same-test-from-the-last-lab-now-with-a-ceiling","The same test from the last lab, now with a ceiling",[11,1150,1151],{},"Back to the same tumor example, now with a toggle to switch between linear and logistic regression:",[1153,1154],"threshold-fit-explorer",{":allow-logistic-toggle":111,":base-points":1155,":outlier-points":1156,"accuracy-label":1157,"add-outlier-label":1158,"class0-label":1159,"class1-label":1160,"correct-label":1161,"logistic-toggle-label":1162,"remove-outlier-label":1163,"threshold-label":1164,"wrong-label":1165,"x-label":1166},"[[0,0],[1,0],[2,0],[3,1],[4,1],[5,1]]","[[10,1],[11,1]]","accuracy","Add large (malignant) tumors","Benign","Malignant","Correct","use logistic regression (sigmoid) instead of linear","Remove large tumors","Decision boundary","Wrong","tumor size",[11,1168,1169,1170,1173,1174,1177,1178,27,1180,1182,1183,1185],{},"Add the large tumors again (same as last lab): with linear regression, ",[20,1171,1172],{},"x=3"," keeps getting classified wrong. Check \"use logistic regression\": the sigmoid curve, unlike a straight line, ",[325,1175,1176],{},"finds a way to accommodate the new extreme points without warping in the middle",", because it already saturates near ",[20,1179,26],{},[20,1181,30],{}," instead of climbing forever. ",[20,1184,1172],{}," goes back to being classified correctly. No point moved, only the shape of the model learning the data changed.",[33,1187,1189],{"id":1188},"wrapping-up","Wrapping up",[455,1191,1192,1203],{},[458,1193,1194],{},[461,1195,1196,1200],{},[464,1197,1199],{"align":1198},"left","What I already knew",[464,1201,1202],{"align":1198},"What this lecture settled",[471,1204,1205,1213,1225],{},[461,1206,1207,1210],{},[476,1208,1209],{"align":1198},"Linear regression's output has no ceiling",[476,1211,1212],{"align":1198},"The sigmoid squashes any real number into the interval (0, 1)",[461,1214,1215,1222],{},[476,1216,1217,1218,1221],{"align":1198},"A ",[20,1219,1220],{},"> 0.5"," cutoff turns a number into a decision",[476,1223,1224],{"align":1198},"That still holds, except now the number crossing the cutoff is an actual probability, never above 1",[461,1226,1227,1230],{},[476,1228,1229],{"align":1198},"Linear regression warps around an extreme point",[476,1231,1232],{"align":1198},"Logistic regression (linear + sigmoid) resists that same extreme point, because the curve saturates instead of climbing forever",[33,1234,1236],{"id":1235},"practical-application","Practical Application",[11,1238,1239,1241,1242,1245,1246,1248],{},[14,1240,17],{"href":16},", raw linear regression on the real breast cancer dataset (",[20,1243,1244],{},"worst concave points",", 569 patients) returned ",[20,1247,22],{}," for one patient, a number that makes no sense as a probability. I run the sigmoid on that exact number:",[336,1250,1252],{"className":338,"code":1251,"language":340,"meta":341,"style":341},"print(sigmoid(1.4043))\n",[20,1253,1254],{"__ignoreMap":341},[40,1255,1256],{"class":346,"line":347},[40,1257,1251],{},[443,1259,1260],{},[11,1261,1262,328,1265,31],{},[325,1263,1264],{},"Output:",[20,1266,1267],{},"0.8028",[11,1269,1270,1272,1273,1275],{},[20,1271,1267],{}," is already an answer that makes sense: \"80% chance of being malignant\". I fit real logistic regression on this same dataset (gradient descent, the same ",[20,1274,1244],{}," variable, z-scored):",[336,1277,1279],{"className":338,"code":1278,"language":340,"meta":341,"style":341},"w, b = fit_logistic_1d(X_train_z, y_train)\nprint(f\"w={w:.4f} b={b:.4f}\")\n",[20,1280,1281,1286],{"__ignoreMap":341},[40,1282,1283],{"class":346,"line":347},[40,1284,1285],{},"w, b = fit_logistic_1d(X_train_z, y_train)\n",[40,1287,1288],{"class":346,"line":353},[40,1289,1290],{},"print(f\"w={w:.4f} b={b:.4f}\")\n",[443,1292,1293],{},[11,1294,1295,328,1297,1300,1301,1304,1305,31],{},[325,1296,1264],{},[20,1298,1299],{},"w=3.9565 b=-1.1326",", training accuracy ",[325,1302,1303],{},"0.9055",", test accuracy ",[325,1306,1307],{},"0.9211",[11,1309,1310,1311,1314],{},"On this particular dataset, with no dramatic outlier, the logistic version's accuracy ends up very close to the linear version from the last lab (0.9099\u002F0.9298 there, 0.9055\u002F0.9211 here), because real patients don't have some absurd \"tumor size of 10\" dragging the line around. The difference that matters isn't the accuracy on this specific dataset, it's the ",[325,1312,1313],{},"output",": every prediction from the logistic version is already born between 0 and 1, ready to be read as a probability, without needing to trust that no future patient will ever have an extreme enough value to blow up the math.",[1316,1317,1318],"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":341,"searchDepth":353,"depth":353,"links":1320},[1321,1322,1323,1324,1325],{"id":35,"depth":353,"text":36},{"id":534,"depth":353,"text":535},{"id":1147,"depth":353,"text":1148},{"id":1188,"depth":353,"text":1189},{"id":1235,"depth":353,"text":1236},null,"2026-09-04","Week 3, Lab 2: linear regression's raw output had no ceiling, so the course squeezes it through a function that always returns something between 0 and 1. The sigmoid is exactly that: a way to squash any number into a probability.","md",{},true,13,"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab02-sigmoid-function","machine-learning-specialization",{"title":6,"description":1328},"published","en\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw3-lab02-sigmoid-function",[1339,1340,1341],"classification","logistic-regression","sigmoid","Au_2qPpopxN6OJeBWt-EGy1fE_MjDY-GNHhSCgdyv_s",1788965100457]