[{"data":1,"prerenderedAt":3416},["ShallowReactive",2],{"lang-switch-post-\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw2-lab04-feature-engineering":3,"post-en-machine-learning-specialization-w2-lab04-feature-engineering":4},"\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw2-lab04-feature-engineering",{"id":5,"title":6,"body":7,"cover":3400,"date":3401,"description":3402,"extension":3403,"meta":3404,"navigation":3336,"order":3405,"path":3406,"playlist":3407,"seo":3408,"status":3409,"stem":3410,"tags":3411,"__hash__":3415},"posts\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw2-lab04-feature-engineering.md","Feature Engineering and Polynomial Regression",{"type":8,"value":9,"toc":3386},"minimark",[10,18,21,26,29,606,906,910,1079,1102,1162,1168,1263,1267,1863,1873,2143,2218,2222,2467,2471,2555,2560,2701,2705,2716,2721,2724,2812,2823,2827,2830,2836,2839,2842,2849,2853,2893,2897,3228,3232,3270,3273,3295,3306,3310,3322,3350,3366,3379,3382],[11,12,13],"p",{},[14,15],"img",{"alt":16,"src":17},"A \"Flex Tape\" meme: at the top, an excited man labeled \"ME\" next to a jar leaking water captioned \"MODEL WORKING LESS ACCURATELY.\" At the bottom, a hand pressing Flex Tape onto a cracked pane that's still leaking a little water through it, labeled \"FEATURE ENGINEERING\"","\u002Fimages\u002Fposts\u002Fmachine-learning-specialization\u002Fw2-lab04-feature-engineering\u002Fmeme-feature-engineering.jpeg",[11,19,20],{},"This is Week 2's fourth lab, and what I expected to be \"just another math trick\" ended up being the post that made me replan the most. The core idea fits in one sentence, but its consequences (including one the original lab never mentions at all) took over the whole post.",[22,23,25],"h2",{"id":24},"the-core-idea-linear-in-the-parameters-not-the-feature","The core idea: linear in the parameters, not the feature",[11,27,28],{},"Linear regression fits models of the form",[11,30,31],{},[32,33,36,156],"span",{"className":34},[35],"katex",[32,37,40],{"className":38},[39],"katex-mathml",[41,42,44],"math",{"xmlns":43},"http:\u002F\u002Fwww.w3.org\u002F1998\u002FMath\u002FMathML",[45,46,47,151],"semantics",{},[48,49,50,71,75,78,81,84,92,98,101,108,114,116,119,121,135,147,149],"mrow",{},[51,52,53,57],"msub",{},[54,55,56],"mi",{},"f",[48,58,59,63,68],{},[54,60,62],{"mathvariant":61},"bold","w",[64,65,67],"mo",{"separator":66},"true",",",[54,69,70],{},"b",[64,72,74],{"stretchy":73},"false","(",[54,76,77],{"mathvariant":61},"x",[64,79,80],{"stretchy":73},")",[64,82,83],{},"=",[51,85,86,88],{},[54,87,62],{},[89,90,91],"mn",{},"0",[51,93,94,96],{},[54,95,77],{},[89,97,91],{},[64,99,100],{},"+",[51,102,103,105],{},[54,104,62],{},[89,106,107],{},"1",[51,109,110,112],{},[54,111,77],{},[89,113,107],{},[64,115,100],{},[64,117,118],{},"…",[64,120,100],{},[51,122,123,125],{},[54,124,62],{},[48,126,127,130,133],{},[54,128,129],{},"n",[64,131,132],{},"−",[89,134,107],{},[51,136,137,139],{},[54,138,77],{},[48,140,141,143,145],{},[54,142,129],{},[64,144,132],{},[89,146,107],{},[64,148,100],{},[54,150,70],{},[152,153,155],"annotation",{"encoding":154},"application\u002Fx-tex","f_{\\mathbf{w},b}(\\mathbf{x}) = w_0x_0 + w_1x_1 + \\ldots + w_{n-1}x_{n-1} + b",[32,157,160,263,366,461,481,596],{"className":158,"ariaHidden":66},[159],"katex-html",[32,161,164,169,240,244,247,251,256,260],{"className":162},[163],"base",[32,165],{"className":166,"style":168},[167],"strut","height:1.0361em;vertical-align:-0.2861em;",[32,170,173,178],{"className":171},[172],"mord",[32,174,56],{"className":175,"style":177},[172,176],"mathnormal","margin-right:0.1076em;",[32,179,182],{"className":180},[181],"msupsub",[32,183,187,231],{"className":184},[185,186],"vlist-t","vlist-t2",[32,188,191,226],{"className":189},[190],"vlist-r",[32,192,196],{"className":193,"style":195},[194],"vlist","height:0.3361em;",[32,197,199,204],{"style":198},"top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;",[32,200],{"className":201,"style":203},[202],"pstrut","height:2.7em;",[32,205,211],{"className":206},[207,208,209,210],"sizing","reset-size6","size3","mtight",[32,212,214,219,223],{"className":213},[172,210],[32,215,62],{"className":216,"style":218},[172,217,210],"mathbf","margin-right:0.016em;",[32,220,67],{"className":221},[222,210],"mpunct",[32,224,70],{"className":225},[172,176,210],[32,227,230],{"className":228},[229],"vlist-s","​",[32,232,234],{"className":233},[190],[32,235,238],{"className":236,"style":237},[194],"height:0.2861em;",[32,239],{},[32,241,74],{"className":242},[243],"mopen",[32,245,77],{"className":246},[172,217],[32,248,80],{"className":249},[250],"mclose",[32,252],{"className":253,"style":255},[254],"mspace","margin-right:0.2778em;",[32,257,83],{"className":258},[259],"mrel",[32,261],{"className":262,"style":255},[254],[32,264,266,270,314,355,359,363],{"className":265},[163],[32,267],{"className":268,"style":269},[167],"height:0.7333em;vertical-align:-0.15em;",[32,271,273,277],{"className":272},[172],[32,274,62],{"className":275,"style":276},[172,176],"margin-right:0.0269em;",[32,278,280],{"className":279},[181],[32,281,283,305],{"className":282},[185,186],[32,284,286,302],{"className":285},[190],[32,287,290],{"className":288,"style":289},[194],"height:0.3011em;",[32,291,293,296],{"style":292},"top:-2.55em;margin-left:-0.0269em;margin-right:0.05em;",[32,294],{"className":295,"style":203},[202],[32,297,299],{"className":298},[207,208,209,210],[32,300,91],{"className":301},[172,210],[32,303,230],{"className":304},[229],[32,306,308],{"className":307},[190],[32,309,312],{"className":310,"style":311},[194],"height:0.15em;",[32,313],{},[32,315,317,320],{"className":316},[172],[32,318,77],{"className":319},[172,176],[32,321,323],{"className":322},[181],[32,324,326,347],{"className":325},[185,186],[32,327,329,344],{"className":328},[190],[32,330,332],{"className":331,"style":289},[194],[32,333,335,338],{"style":334},"top:-2.55em;margin-left:0em;margin-right:0.05em;",[32,336],{"className":337,"style":203},[202],[32,339,341],{"className":340},[207,208,209,210],[32,342,91],{"className":343},[172,210],[32,345,230],{"className":346},[229],[32,348,350],{"className":349},[190],[32,351,353],{"className":352,"style":311},[194],[32,354],{},[32,356],{"className":357,"style":358},[254],"margin-right:0.2222em;",[32,360,100],{"className":361},[362],"mbin",[32,364],{"className":365,"style":358},[254],[32,367,369,372,412,452,455,458],{"className":368},[163],[32,370],{"className":371,"style":269},[167],[32,373,375,378],{"className":374},[172],[32,376,62],{"className":377,"style":276},[172,176],[32,379,381],{"className":380},[181],[32,382,384,404],{"className":383},[185,186],[32,385,387,401],{"className":386},[190],[32,388,390],{"className":389,"style":289},[194],[32,391,392,395],{"style":292},[32,393],{"className":394,"style":203},[202],[32,396,398],{"className":397},[207,208,209,210],[32,399,107],{"className":400},[172,210],[32,402,230],{"className":403},[229],[32,405,407],{"className":406},[190],[32,408,410],{"className":409,"style":311},[194],[32,411],{},[32,413,415,418],{"className":414},[172],[32,416,77],{"className":417},[172,176],[32,419,421],{"className":420},[181],[32,422,424,444],{"className":423},[185,186],[32,425,427,441],{"className":426},[190],[32,428,430],{"className":429,"style":289},[194],[32,431,432,435],{"style":334},[32,433],{"className":434,"style":203},[202],[32,436,438],{"className":437},[207,208,209,210],[32,439,107],{"className":440},[172,210],[32,442,230],{"className":443},[229],[32,445,447],{"className":446},[190],[32,448,450],{"className":449,"style":311},[194],[32,451],{},[32,453],{"className":454,"style":358},[254],[32,456,100],{"className":457},[362],[32,459],{"className":460,"style":358},[254],[32,462,464,468,472,475,478],{"className":463},[163],[32,465],{"className":466,"style":467},[167],"height:0.6667em;vertical-align:-0.0833em;",[32,469,118],{"className":470},[471],"minner",[32,473],{"className":474,"style":358},[254],[32,476,100],{"className":477},[362],[32,479],{"className":480,"style":358},[254],[32,482,484,488,538,587,590,593],{"className":483},[163],[32,485],{"className":486,"style":487},[167],"height:0.7917em;vertical-align:-0.2083em;",[32,489,491,494],{"className":490},[172],[32,492,62],{"className":493,"style":276},[172,176],[32,495,497],{"className":496},[181],[32,498,500,529],{"className":499},[185,186],[32,501,503,526],{"className":502},[190],[32,504,506],{"className":505,"style":289},[194],[32,507,508,511],{"style":292},[32,509],{"className":510,"style":203},[202],[32,512,514],{"className":513},[207,208,209,210],[32,515,517,520,523],{"className":516},[172,210],[32,518,129],{"className":519},[172,176,210],[32,521,132],{"className":522},[362,210],[32,524,107],{"className":525},[172,210],[32,527,230],{"className":528},[229],[32,530,532],{"className":531},[190],[32,533,536],{"className":534,"style":535},[194],"height:0.2083em;",[32,537],{},[32,539,541,544],{"className":540},[172],[32,542,77],{"className":543},[172,176],[32,545,547],{"className":546},[181],[32,548,550,579],{"className":549},[185,186],[32,551,553,576],{"className":552},[190],[32,554,556],{"className":555,"style":289},[194],[32,557,558,561],{"style":334},[32,559],{"className":560,"style":203},[202],[32,562,564],{"className":563},[207,208,209,210],[32,565,567,570,573],{"className":566},[172,210],[32,568,129],{"className":569},[172,176,210],[32,571,132],{"className":572},[362,210],[32,574,107],{"className":575},[172,210],[32,577,230],{"className":578},[229],[32,580,582],{"className":581},[190],[32,583,585],{"className":584,"style":535},[194],[32,586],{},[32,588],{"className":589,"style":358},[254],[32,591,100],{"className":592},[362],[32,594],{"className":595,"style":358},[254],[32,597,599,603],{"className":598},[163],[32,600],{"className":601,"style":602},[167],"height:0.6944em;",[32,604,70],{"className":605},[172,176],[11,607,608,609,613,614,658,659,730,731,794,795,842,843,872,873,901,902,905],{},"What makes this \"linear\" is the relationship between the output and the ",[610,611,612],"strong",{},"parameters"," ",[32,615,617,635],{"className":616},[35],[32,618,620],{"className":619},[39],[41,621,622],{"xmlns":43},[45,623,624,632],{},[48,625,626,628,630],{},[54,627,62],{"mathvariant":61},[64,629,67],{"separator":66},[54,631,70],{},[152,633,634],{"encoding":154},"\\mathbf{w}, b",[32,636,638],{"className":637,"ariaHidden":66},[159],[32,639,641,645,648,651,655],{"className":640},[163],[32,642],{"className":643,"style":644},[167],"height:0.8889em;vertical-align:-0.1944em;",[32,646,62],{"className":647,"style":218},[172,217],[32,649,67],{"className":650},[222],[32,652],{"className":653,"style":654},[254],"margin-right:0.1667em;",[32,656,70],{"className":657},[172,176],", not the relationship between the output and the original variable. Nothing stops ",[32,660,662,680],{"className":661},[35],[32,663,665],{"className":664},[39],[41,666,667],{"xmlns":43},[45,668,669,677],{},[48,670,671],{},[51,672,673,675],{},[54,674,77],{},[89,676,107],{},[152,678,679],{"encoding":154},"x_1",[32,681,683],{"className":682,"ariaHidden":66},[159],[32,684,686,690],{"className":685},[163],[32,687],{"className":688,"style":689},[167],"height:0.5806em;vertical-align:-0.15em;",[32,691,693,696],{"className":692},[172],[32,694,77],{"className":695},[172,176],[32,697,699],{"className":698},[181],[32,700,702,722],{"className":701},[185,186],[32,703,705,719],{"className":704},[190],[32,706,708],{"className":707,"style":289},[194],[32,709,710,713],{"style":334},[32,711],{"className":712,"style":203},[202],[32,714,716],{"className":715},[207,208,209,210],[32,717,107],{"className":718},[172,210],[32,720,230],{"className":721},[229],[32,723,725],{"className":724},[190],[32,726,728],{"className":727,"style":311},[194],[32,729],{}," from being ",[32,732,734,754],{"className":733},[35],[32,735,737],{"className":736},[39],[41,738,739],{"xmlns":43},[45,740,741,751],{},[48,742,743],{},[744,745,746,748],"msup",{},[54,747,77],{},[89,749,750],{},"2",[152,752,753],{"encoding":154},"x^2",[32,755,757],{"className":756,"ariaHidden":66},[159],[32,758,760,764],{"className":759},[163],[32,761],{"className":762,"style":763},[167],"height:0.8141em;",[32,765,767,770],{"className":766},[172],[32,768,77],{"className":769},[172,176],[32,771,773],{"className":772},[181],[32,774,776],{"className":775},[185],[32,777,779],{"className":778},[190],[32,780,782],{"className":781,"style":763},[194],[32,783,785,788],{"style":784},"top:-3.063em;margin-right:0.05em;",[32,786],{"className":787,"style":203},[202],[32,789,791],{"className":790},[207,208,209,210],[32,792,750],{"className":793},[172,210]," itself, or ",[32,796,798,818],{"className":797},[35],[32,799,801],{"className":800},[39],[41,802,803],{"xmlns":43},[45,804,805,815],{},[48,806,807,810,813],{},[54,808,809],{},"log",[64,811,812],{},"⁡",[54,814,77],{},[152,816,817],{"encoding":154},"\\log x",[32,819,821],{"className":820,"ariaHidden":66},[159],[32,822,824,827,836,839],{"className":823},[163],[32,825],{"className":826,"style":644},[167],[32,828,831,832],{"className":829},[830],"mop","lo",[32,833,835],{"style":834},"margin-right:0.0139em;","g",[32,837],{"className":838,"style":654},[254],[32,840,77],{"className":841},[172,176],", or the product of two other columns. No matter how I tune ",[32,844,846,859],{"className":845},[35],[32,847,849],{"className":848},[39],[41,850,851],{"xmlns":43},[45,852,853,857],{},[48,854,855],{},[54,856,62],{},[152,858,62],{"encoding":154},[32,860,862],{"className":861,"ariaHidden":66},[159],[32,863,865,869],{"className":864},[163],[32,866],{"className":867,"style":868},[167],"height:0.4306em;",[32,870,62],{"className":871,"style":276},[172,176]," and ",[32,874,876,889],{"className":875},[35],[32,877,879],{"className":878},[39],[41,880,881],{"xmlns":43},[45,882,883,887],{},[48,884,885],{},[54,886,70],{},[152,888,70],{"encoding":154},[32,890,892],{"className":891,"ariaHidden":66},[159],[32,893,895,898],{"className":894},[163],[32,896],{"className":897,"style":602},[167],[32,899,70],{"className":900},[172,176],", the equation never becomes a curve if the features are straight lines. But if I ",[610,903,904],{},"engineer"," a curved feature and plug it in, the exact same machinery fits the curve. That's feature engineering.",[22,907,909],{"id":908},"polynomial-features-in-practice","Polynomial features in practice",[11,911,912,913,1020,1021,1049,1050,1078],{},"I tested this with a simple target: ",[32,914,916,943],{"className":915},[35],[32,917,919],{"className":918},[39],[41,920,921],{"xmlns":43},[45,922,923,940],{},[48,924,925,928,930,932,934],{},[54,926,927],{},"y",[64,929,83],{},[89,931,107],{},[64,933,100],{},[744,935,936,938],{},[54,937,77],{},[89,939,750],{},[152,941,942],{"encoding":154},"y = 1 + x^2",[32,944,946,966,985],{"className":945,"ariaHidden":66},[159],[32,947,949,953,957,960,963],{"className":948},[163],[32,950],{"className":951,"style":952},[167],"height:0.625em;vertical-align:-0.1944em;",[32,954,927],{"className":955,"style":956},[172,176],"margin-right:0.0359em;",[32,958],{"className":959,"style":255},[254],[32,961,83],{"className":962},[259],[32,964],{"className":965,"style":255},[254],[32,967,969,973,976,979,982],{"className":968},[163],[32,970],{"className":971,"style":972},[167],"height:0.7278em;vertical-align:-0.0833em;",[32,974,107],{"className":975},[172],[32,977],{"className":978,"style":358},[254],[32,980,100],{"className":981},[362],[32,983],{"className":984,"style":358},[254],[32,986,988,991],{"className":987},[163],[32,989],{"className":990,"style":763},[167],[32,992,994,997],{"className":993},[172],[32,995,77],{"className":996},[172,176],[32,998,1000],{"className":999},[181],[32,1001,1003],{"className":1002},[185],[32,1004,1006],{"className":1005},[190],[32,1007,1009],{"className":1008,"style":763},[194],[32,1010,1011,1014],{"style":784},[32,1012],{"className":1013,"style":203},[202],[32,1015,1017],{"className":1016},[207,208,209,210],[32,1018,750],{"className":1019},[172,210],", for ",[32,1022,1024,1037],{"className":1023},[35],[32,1025,1027],{"className":1026},[39],[41,1028,1029],{"xmlns":43},[45,1030,1031,1035],{},[48,1032,1033],{},[54,1034,77],{},[152,1036,77],{"encoding":154},[32,1038,1040],{"className":1039,"ariaHidden":66},[159],[32,1041,1043,1046],{"className":1042},[163],[32,1044],{"className":1045,"style":868},[167],[32,1047,77],{"className":1048},[172,176]," from 0 to 19. First, the naive attempt: feeding the model raw ",[32,1051,1053,1066],{"className":1052},[35],[32,1054,1056],{"className":1055},[39],[41,1057,1058],{"xmlns":43},[45,1059,1060,1064],{},[48,1061,1062],{},[54,1063,77],{},[152,1065,77],{"encoding":154},[32,1067,1069],{"className":1068,"ariaHidden":66},[159],[32,1070,1072,1075],{"className":1071},[163],[32,1073],{"className":1074,"style":868},[167],[32,1076,77],{"className":1077},[172,176],".",[1080,1081,1086],"pre",{"className":1082,"code":1083,"language":1084,"meta":1085,"style":1085},"language-python shiki shiki-themes github-light github-dark","x = list(range(20))\ny = [1 + xi**2 for xi in x]\n","python","",[1087,1088,1089,1096],"code",{"__ignoreMap":1085},[32,1090,1093],{"class":1091,"line":1092},"line",1,[32,1094,1095],{},"x = list(range(20))\n",[32,1097,1099],{"class":1091,"line":1098},2,[32,1100,1101],{},"y = [1 + xi**2 for xi in x]\n",[11,1103,1104,1105,872,1133,1161],{},"Drag the degree to 1 in the simulator below and notice: no value of ",[32,1106,1108,1121],{"className":1107},[35],[32,1109,1111],{"className":1110},[39],[41,1112,1113],{"xmlns":43},[45,1114,1115,1119],{},[48,1116,1117],{},[54,1118,62],{},[152,1120,62],{"encoding":154},[32,1122,1124],{"className":1123,"ariaHidden":66},[159],[32,1125,1127,1130],{"className":1126},[163],[32,1128],{"className":1129,"style":868},[167],[32,1131,62],{"className":1132,"style":276},[172,176],[32,1134,1136,1149],{"className":1135},[35],[32,1137,1139],{"className":1138},[39],[41,1140,1141],{"xmlns":43},[45,1142,1143,1147],{},[48,1144,1145],{},[54,1146,70],{},[152,1148,70],{"encoding":154},[32,1150,1152],{"className":1151,"ariaHidden":66},[159],[32,1153,1155,1158],{"className":1154},[163],[32,1156],{"className":1157,"style":602},[167],[32,1159,70],{"className":1160},[172,176]," fixes this, because the model is a line and the target is a parabola. Now drag it to 2:",[1163,1164],"polynomial-fit-explorer",{":initial-degree":107,":max-degree":1165,":x-train":1166,":y-train":1167,"x-label":77,"y-label":927},"4","[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]","[1,2,5,10,17,26,37,50,65,82,101,122,145,170,197,226,257,290,325,362]",[11,1169,1170,1171,1174,1175,1203,1204,1262],{},"At degree 2 the fit becomes exact, zero RMSE. What I swapped wasn't the algorithm, it was the ",[610,1172,1173],{},"feature",": instead of ",[32,1176,1178,1191],{"className":1177},[35],[32,1179,1181],{"className":1180},[39],[41,1182,1183],{"xmlns":43},[45,1184,1185,1189],{},[48,1186,1187],{},[54,1188,77],{},[152,1190,77],{"encoding":154},[32,1192,1194],{"className":1193,"ariaHidden":66},[159],[32,1195,1197,1200],{"className":1196},[163],[32,1198],{"className":1199,"style":868},[167],[32,1201,77],{"className":1202},[172,176],", I fed in ",[32,1205,1207,1224],{"className":1206},[35],[32,1208,1210],{"className":1209},[39],[41,1211,1212],{"xmlns":43},[45,1213,1214,1222],{},[48,1215,1216],{},[744,1217,1218,1220],{},[54,1219,77],{},[89,1221,750],{},[152,1223,753],{"encoding":154},[32,1225,1227],{"className":1226,"ariaHidden":66},[159],[32,1228,1230,1233],{"className":1229},[163],[32,1231],{"className":1232,"style":763},[167],[32,1234,1236,1239],{"className":1235},[172],[32,1237,77],{"className":1238},[172,176],[32,1240,1242],{"className":1241},[181],[32,1243,1245],{"className":1244},[185],[32,1246,1248],{"className":1247},[190],[32,1249,1251],{"className":1250,"style":763},[194],[32,1252,1253,1256],{"style":784},[32,1254],{"className":1255,"style":203},[202],[32,1257,1259],{"className":1258},[207,208,209,210],[32,1260,750],{"className":1261},[172,210]," (plus the rest of the polynomial) and let the same old linear regression find the right weight.",[22,1264,1266],{"id":1265},"choosing-features-without-knowing-the-answer-beforehand","Choosing features, without knowing the answer beforehand",[11,1268,1269,1270,1273,1274,1332,1333,1650,1651,1709,1710,1738,1739,1798,1799,1857,1858,1862],{},"Up there I already ",[610,1271,1272],{},"knew"," the right term was ",[32,1275,1277,1294],{"className":1276},[35],[32,1278,1280],{"className":1279},[39],[41,1281,1282],{"xmlns":43},[45,1283,1284,1292],{},[48,1285,1286],{},[744,1287,1288,1290],{},[54,1289,77],{},[89,1291,750],{},[152,1293,753],{"encoding":154},[32,1295,1297],{"className":1296,"ariaHidden":66},[159],[32,1298,1300,1303],{"className":1299},[163],[32,1301],{"className":1302,"style":763},[167],[32,1304,1306,1309],{"className":1305},[172],[32,1307,77],{"className":1308},[172,176],[32,1310,1312],{"className":1311},[181],[32,1313,1315],{"className":1314},[185],[32,1316,1318],{"className":1317},[190],[32,1319,1321],{"className":1320,"style":763},[194],[32,1322,1323,1326],{"style":784},[32,1324],{"className":1325,"style":203},[202],[32,1327,1329],{"className":1328},[207,208,209,210],[32,1330,750],{"className":1331},[172,210],". In practice, you don't. One strategy is to throw several candidates at it and let the fit decide: I tested ",[32,1334,1336,1393],{"className":1335},[35],[32,1337,1339],{"className":1338},[39],[41,1340,1341],{"xmlns":43},[45,1342,1343,1390],{},[48,1344,1345,1347,1349,1355,1357,1359,1365,1371,1373,1379,1386,1388],{},[54,1346,927],{},[64,1348,83],{},[51,1350,1351,1353],{},[54,1352,62],{},[89,1354,91],{},[54,1356,77],{},[64,1358,100],{},[51,1360,1361,1363],{},[54,1362,62],{},[89,1364,107],{},[744,1366,1367,1369],{},[54,1368,77],{},[89,1370,750],{},[64,1372,100],{},[51,1374,1375,1377],{},[54,1376,62],{},[89,1378,750],{},[744,1380,1381,1383],{},[54,1382,77],{},[89,1384,1385],{},"3",[64,1387,100],{},[54,1389,70],{},[152,1391,1392],{"encoding":154},"y = w_0x + w_1x^2 + w_2x^3 + b",[32,1394,1396,1414,1472,1557,1641],{"className":1395,"ariaHidden":66},[159],[32,1397,1399,1402,1405,1408,1411],{"className":1398},[163],[32,1400],{"className":1401,"style":952},[167],[32,1403,927],{"className":1404,"style":956},[172,176],[32,1406],{"className":1407,"style":255},[254],[32,1409,83],{"className":1410},[259],[32,1412],{"className":1413,"style":255},[254],[32,1415,1417,1420,1460,1463,1466,1469],{"className":1416},[163],[32,1418],{"className":1419,"style":269},[167],[32,1421,1423,1426],{"className":1422},[172],[32,1424,62],{"className":1425,"style":276},[172,176],[32,1427,1429],{"className":1428},[181],[32,1430,1432,1452],{"className":1431},[185,186],[32,1433,1435,1449],{"className":1434},[190],[32,1436,1438],{"className":1437,"style":289},[194],[32,1439,1440,1443],{"style":292},[32,1441],{"className":1442,"style":203},[202],[32,1444,1446],{"className":1445},[207,208,209,210],[32,1447,91],{"className":1448},[172,210],[32,1450,230],{"className":1451},[229],[32,1453,1455],{"className":1454},[190],[32,1456,1458],{"className":1457,"style":311},[194],[32,1459],{},[32,1461,77],{"className":1462},[172,176],[32,1464],{"className":1465,"style":358},[254],[32,1467,100],{"className":1468},[362],[32,1470],{"className":1471,"style":358},[254],[32,1473,1475,1479,1519,1548,1551,1554],{"className":1474},[163],[32,1476],{"className":1477,"style":1478},[167],"height:0.9641em;vertical-align:-0.15em;",[32,1480,1482,1485],{"className":1481},[172],[32,1483,62],{"className":1484,"style":276},[172,176],[32,1486,1488],{"className":1487},[181],[32,1489,1491,1511],{"className":1490},[185,186],[32,1492,1494,1508],{"className":1493},[190],[32,1495,1497],{"className":1496,"style":289},[194],[32,1498,1499,1502],{"style":292},[32,1500],{"className":1501,"style":203},[202],[32,1503,1505],{"className":1504},[207,208,209,210],[32,1506,107],{"className":1507},[172,210],[32,1509,230],{"className":1510},[229],[32,1512,1514],{"className":1513},[190],[32,1515,1517],{"className":1516,"style":311},[194],[32,1518],{},[32,1520,1522,1525],{"className":1521},[172],[32,1523,77],{"className":1524},[172,176],[32,1526,1528],{"className":1527},[181],[32,1529,1531],{"className":1530},[185],[32,1532,1534],{"className":1533},[190],[32,1535,1537],{"className":1536,"style":763},[194],[32,1538,1539,1542],{"style":784},[32,1540],{"className":1541,"style":203},[202],[32,1543,1545],{"className":1544},[207,208,209,210],[32,1546,750],{"className":1547},[172,210],[32,1549],{"className":1550,"style":358},[254],[32,1552,100],{"className":1553},[362],[32,1555],{"className":1556,"style":358},[254],[32,1558,1560,1563,1603,1632,1635,1638],{"className":1559},[163],[32,1561],{"className":1562,"style":1478},[167],[32,1564,1566,1569],{"className":1565},[172],[32,1567,62],{"className":1568,"style":276},[172,176],[32,1570,1572],{"className":1571},[181],[32,1573,1575,1595],{"className":1574},[185,186],[32,1576,1578,1592],{"className":1577},[190],[32,1579,1581],{"className":1580,"style":289},[194],[32,1582,1583,1586],{"style":292},[32,1584],{"className":1585,"style":203},[202],[32,1587,1589],{"className":1588},[207,208,209,210],[32,1590,750],{"className":1591},[172,210],[32,1593,230],{"className":1594},[229],[32,1596,1598],{"className":1597},[190],[32,1599,1601],{"className":1600,"style":311},[194],[32,1602],{},[32,1604,1606,1609],{"className":1605},[172],[32,1607,77],{"className":1608},[172,176],[32,1610,1612],{"className":1611},[181],[32,1613,1615],{"className":1614},[185],[32,1616,1618],{"className":1617},[190],[32,1619,1621],{"className":1620,"style":763},[194],[32,1622,1623,1626],{"style":784},[32,1624],{"className":1625,"style":203},[202],[32,1627,1629],{"className":1628},[207,208,209,210],[32,1630,1385],{"className":1631},[172,210],[32,1633],{"className":1634,"style":358},[254],[32,1636,100],{"className":1637},[362],[32,1639],{"className":1640,"style":358},[254],[32,1642,1644,1647],{"className":1643},[163],[32,1645],{"className":1646,"style":602},[167],[32,1648,70],{"className":1649},[172,176]," against a pure ",[32,1652,1654,1671],{"className":1653},[35],[32,1655,1657],{"className":1656},[39],[41,1658,1659],{"xmlns":43},[45,1660,1661,1669],{},[48,1662,1663],{},[744,1664,1665,1667],{},[54,1666,77],{},[89,1668,750],{},[152,1670,753],{"encoding":154},[32,1672,1674],{"className":1673,"ariaHidden":66},[159],[32,1675,1677,1680],{"className":1676},[163],[32,1678],{"className":1679,"style":763},[167],[32,1681,1683,1686],{"className":1682},[172],[32,1684,77],{"className":1685},[172,176],[32,1687,1689],{"className":1688},[181],[32,1690,1692],{"className":1691},[185],[32,1693,1695],{"className":1694},[190],[32,1696,1698],{"className":1697,"style":763},[194],[32,1699,1700,1703],{"style":784},[32,1701],{"className":1702,"style":203},[202],[32,1704,1706],{"className":1705},[207,208,209,210],[32,1707,750],{"className":1708},[172,210]," target, and the solver zeroed out ",[32,1711,1713,1726],{"className":1712},[35],[32,1714,1716],{"className":1715},[39],[41,1717,1718],{"xmlns":43},[45,1719,1720,1724],{},[48,1721,1722],{},[54,1723,77],{},[152,1725,77],{"encoding":154},[32,1727,1729],{"className":1728,"ariaHidden":66},[159],[32,1730,1732,1735],{"className":1731},[163],[32,1733],{"className":1734,"style":868},[167],[32,1736,77],{"className":1737},[172,176],"'s and ",[32,1740,1742,1760],{"className":1741},[35],[32,1743,1745],{"className":1744},[39],[41,1746,1747],{"xmlns":43},[45,1748,1749,1757],{},[48,1750,1751],{},[744,1752,1753,1755],{},[54,1754,77],{},[89,1756,1385],{},[152,1758,1759],{"encoding":154},"x^3",[32,1761,1763],{"className":1762,"ariaHidden":66},[159],[32,1764,1766,1769],{"className":1765},[163],[32,1767],{"className":1768,"style":763},[167],[32,1770,1772,1775],{"className":1771},[172],[32,1773,77],{"className":1774},[172,176],[32,1776,1778],{"className":1777},[181],[32,1779,1781],{"className":1780},[185],[32,1782,1784],{"className":1783},[190],[32,1785,1787],{"className":1786,"style":763},[194],[32,1788,1789,1792],{"style":784},[32,1790],{"className":1791,"style":203},[202],[32,1793,1795],{"className":1794},[207,208,209,210],[32,1796,1385],{"className":1797},[172,210],"'s weights on its own, leaving basically only ",[32,1800,1802,1819],{"className":1801},[35],[32,1803,1805],{"className":1804},[39],[41,1806,1807],{"xmlns":43},[45,1808,1809,1817],{},[48,1810,1811],{},[744,1812,1813,1815],{},[54,1814,77],{},[89,1816,750],{},[152,1818,753],{"encoding":154},[32,1820,1822],{"className":1821,"ariaHidden":66},[159],[32,1823,1825,1828],{"className":1824},[163],[32,1826],{"className":1827,"style":763},[167],[32,1829,1831,1834],{"className":1830},[172],[32,1832,77],{"className":1833},[172,176],[32,1835,1837],{"className":1836},[181],[32,1838,1840],{"className":1839},[185],[32,1841,1843],{"className":1842},[190],[32,1844,1846],{"className":1845,"style":763},[194],[32,1847,1848,1851],{"style":784},[32,1849],{"className":1850,"style":203},[202],[32,1852,1854],{"className":1853},[207,208,209,210],[32,1855,750],{"className":1856},[172,210],"'s standing. (The original notebook runs this same test with gradient descent and only manages to ",[1859,1860,1861],"em",{},"shrink"," the wrong weights, not zero them, because convergence never fully finishes. With an exact solution, the result comes out clean.)",[11,1864,1865,1866,1869,1870,1872],{},"Another way to think about it: after creating the features, I'm still doing ",[610,1867,1868],{},"linear"," regression. So the best feature is the one with a ",[610,1871,1868],{}," relationship to the target. That turns into an easy-to-compute Pearson correlation:",[1874,1875,1876,1972],"table",{},[1877,1878,1879],"thead",{},[1880,1881,1882,1887],"tr",{},[1883,1884,1886],"th",{"align":1885},"left","Feature",[1883,1888,1890,1891],{"align":1889},"right","Correlation with ",[32,1892,1894,1916],{"className":1893},[35],[32,1895,1897],{"className":1896},[39],[41,1898,1899],{"xmlns":43},[45,1900,1901,1913],{},[48,1902,1903,1905,1907],{},[54,1904,927],{},[64,1906,83],{},[744,1908,1909,1911],{},[54,1910,77],{},[89,1912,750],{},[152,1914,1915],{"encoding":154},"y=x^2",[32,1917,1919,1937],{"className":1918,"ariaHidden":66},[159],[32,1920,1922,1925,1928,1931,1934],{"className":1921},[163],[32,1923],{"className":1924,"style":952},[167],[32,1926,927],{"className":1927,"style":956},[172,176],[32,1929],{"className":1930,"style":255},[254],[32,1932,83],{"className":1933},[259],[32,1935],{"className":1936,"style":255},[254],[32,1938,1940,1943],{"className":1939},[163],[32,1941],{"className":1942,"style":763},[167],[32,1944,1946,1949],{"className":1945},[172],[32,1947,77],{"className":1948},[172,176],[32,1950,1952],{"className":1951},[181],[32,1953,1955],{"className":1954},[185],[32,1956,1958],{"className":1957},[190],[32,1959,1961],{"className":1960,"style":763},[194],[32,1962,1963,1966],{"style":784},[32,1964],{"className":1965,"style":203},[202],[32,1967,1969],{"className":1968},[207,208,209,210],[32,1970,750],{"className":1971},[172,210],[1973,1974,1975,2011,2078],"tbody",{},[1880,1976,1977,2008],{},[1978,1979,1980],"td",{"align":1885},[32,1981,1983,1996],{"className":1982},[35],[32,1984,1986],{"className":1985},[39],[41,1987,1988],{"xmlns":43},[45,1989,1990,1994],{},[48,1991,1992],{},[54,1993,77],{},[152,1995,77],{"encoding":154},[32,1997,1999],{"className":1998,"ariaHidden":66},[159],[32,2000,2002,2005],{"className":2001},[163],[32,2003],{"className":2004,"style":868},[167],[32,2006,77],{"className":2007},[172,176],[1978,2009,2010],{"align":1889},"0.965",[1880,2012,2013,2073],{},[1978,2014,2015],{"align":1885},[32,2016,2018,2035],{"className":2017},[35],[32,2019,2021],{"className":2020},[39],[41,2022,2023],{"xmlns":43},[45,2024,2025,2033],{},[48,2026,2027],{},[744,2028,2029,2031],{},[54,2030,77],{},[89,2032,750],{},[152,2034,753],{"encoding":154},[32,2036,2038],{"className":2037,"ariaHidden":66},[159],[32,2039,2041,2044],{"className":2040},[163],[32,2042],{"className":2043,"style":763},[167],[32,2045,2047,2050],{"className":2046},[172],[32,2048,77],{"className":2049},[172,176],[32,2051,2053],{"className":2052},[181],[32,2054,2056],{"className":2055},[185],[32,2057,2059],{"className":2058},[190],[32,2060,2062],{"className":2061,"style":763},[194],[32,2063,2064,2067],{"style":784},[32,2065],{"className":2066,"style":203},[202],[32,2068,2070],{"className":2069},[207,208,209,210],[32,2071,750],{"className":2072},[172,210],[1978,2074,2075],{"align":1889},[610,2076,2077],{},"1.000",[1880,2079,2080,2140],{},[1978,2081,2082],{"align":1885},[32,2083,2085,2102],{"className":2084},[35],[32,2086,2088],{"className":2087},[39],[41,2089,2090],{"xmlns":43},[45,2091,2092,2100],{},[48,2093,2094],{},[744,2095,2096,2098],{},[54,2097,77],{},[89,2099,1385],{},[152,2101,1759],{"encoding":154},[32,2103,2105],{"className":2104,"ariaHidden":66},[159],[32,2106,2108,2111],{"className":2107},[163],[32,2109],{"className":2110,"style":763},[167],[32,2112,2114,2117],{"className":2113},[172],[32,2115,77],{"className":2116},[172,176],[32,2118,2120],{"className":2119},[181],[32,2121,2123],{"className":2122},[185],[32,2124,2126],{"className":2125},[190],[32,2127,2129],{"className":2128,"style":763},[194],[32,2130,2131,2134],{"style":784},[32,2132],{"className":2133,"style":203},[202],[32,2135,2137],{"className":2136},[207,208,209,210],[32,2138,1385],{"className":2139},[172,210],[1978,2141,2142],{"align":1889},"0.986",[11,2144,2145,2203,2204,2207,2208,2213,2214,2217],{},[32,2146,2148,2165],{"className":2147},[35],[32,2149,2151],{"className":2150},[39],[41,2152,2153],{"xmlns":43},[45,2154,2155,2163],{},[48,2156,2157],{},[744,2158,2159,2161],{},[54,2160,77],{},[89,2162,750],{},[152,2164,753],{"encoding":154},[32,2166,2168],{"className":2167,"ariaHidden":66},[159],[32,2169,2171,2174],{"className":2170},[163],[32,2172],{"className":2173,"style":763},[167],[32,2175,2177,2180],{"className":2176},[172],[32,2178,77],{"className":2179},[172,176],[32,2181,2183],{"className":2182},[181],[32,2184,2186],{"className":2185},[185],[32,2187,2189],{"className":2188},[190],[32,2190,2192],{"className":2191,"style":763},[194],[32,2193,2194,2197],{"style":784},[32,2195],{"className":2196,"style":203},[202],[32,2198,2200],{"className":2199},[207,208,209,210],[32,2201,750],{"className":2202},[172,210]," has perfect correlation because it ",[610,2205,2206],{},"is"," the target, up to scale. I already mentioned this same heuristic (plot feature against target, look for the line) in ",[2209,2210,2212],"a",{"href":2211},"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw2-lab03-feature-scaling","the normalization post",", it's the same idea, just now applied to choose the right ",[1859,2215,2216],{},"shape"," of the feature, not just its scale.",[22,2219,2221],{"id":2220},"normalizing-again-the-extreme-version","Normalizing, again (the extreme version)",[11,2223,2224,2225,2253,2254,2312,2313,2371,2372,2375,2376,872,2404,2462,2463,2466],{},"Polynomial features are the most extreme case of different scales I've seen so far: ",[32,2226,2228,2241],{"className":2227},[35],[32,2229,2231],{"className":2230},[39],[41,2232,2233],{"xmlns":43},[45,2234,2235,2239],{},[48,2236,2237],{},[54,2238,77],{},[152,2240,77],{"encoding":154},[32,2242,2244],{"className":2243,"ariaHidden":66},[159],[32,2245,2247,2250],{"className":2246},[163],[32,2248],{"className":2249,"style":868},[167],[32,2251,77],{"className":2252},[172,176]," goes up to 19, ",[32,2255,2257,2274],{"className":2256},[35],[32,2258,2260],{"className":2259},[39],[41,2261,2262],{"xmlns":43},[45,2263,2264,2272],{},[48,2265,2266],{},[744,2267,2268,2270],{},[54,2269,77],{},[89,2271,750],{},[152,2273,753],{"encoding":154},[32,2275,2277],{"className":2276,"ariaHidden":66},[159],[32,2278,2280,2283],{"className":2279},[163],[32,2281],{"className":2282,"style":763},[167],[32,2284,2286,2289],{"className":2285},[172],[32,2287,77],{"className":2288},[172,176],[32,2290,2292],{"className":2291},[181],[32,2293,2295],{"className":2294},[185],[32,2296,2298],{"className":2297},[190],[32,2299,2301],{"className":2300,"style":763},[194],[32,2302,2303,2306],{"style":784},[32,2304],{"className":2305,"style":203},[202],[32,2307,2309],{"className":2308},[207,208,209,210],[32,2310,750],{"className":2311},[172,210]," up to 361, ",[32,2314,2316,2333],{"className":2315},[35],[32,2317,2319],{"className":2318},[39],[41,2320,2321],{"xmlns":43},[45,2322,2323,2331],{},[48,2324,2325],{},[744,2326,2327,2329],{},[54,2328,77],{},[89,2330,1385],{},[152,2332,1759],{"encoding":154},[32,2334,2336],{"className":2335,"ariaHidden":66},[159],[32,2337,2339,2342],{"className":2338},[163],[32,2340],{"className":2341,"style":763},[167],[32,2343,2345,2348],{"className":2344},[172],[32,2346,77],{"className":2347},[172,176],[32,2349,2351],{"className":2350},[181],[32,2352,2354],{"className":2353},[185],[32,2355,2357],{"className":2356},[190],[32,2358,2360],{"className":2359,"style":763},[194],[32,2361,2362,2365],{"style":784},[32,2363],{"className":2364,"style":203},[202],[32,2366,2368],{"className":2367},[207,208,209,210],[32,2369,1385],{"className":2370},[172,210]," up to 6859, a ratio of ",[610,2373,2374],{},"361 times"," between ",[32,2377,2379,2392],{"className":2378},[35],[32,2380,2382],{"className":2381},[39],[41,2383,2384],{"xmlns":43},[45,2385,2386,2390],{},[48,2387,2388],{},[54,2389,77],{},[152,2391,77],{"encoding":154},[32,2393,2395],{"className":2394,"ariaHidden":66},[159],[32,2396,2398,2401],{"className":2397},[163],[32,2399],{"className":2400,"style":868},[167],[32,2402,77],{"className":2403},[172,176],[32,2405,2407,2424],{"className":2406},[35],[32,2408,2410],{"className":2409},[39],[41,2411,2412],{"xmlns":43},[45,2413,2414,2422],{},[48,2415,2416],{},[744,2417,2418,2420],{},[54,2419,77],{},[89,2421,750],{},[152,2423,753],{"encoding":154},[32,2425,2427],{"className":2426,"ariaHidden":66},[159],[32,2428,2430,2433],{"className":2429},[163],[32,2431],{"className":2432,"style":763},[167],[32,2434,2436,2439],{"className":2435},[172],[32,2437,77],{"className":2438},[172,176],[32,2440,2442],{"className":2441},[181],[32,2443,2445],{"className":2444},[185],[32,2446,2448],{"className":2447},[190],[32,2449,2451],{"className":2450,"style":763},[194],[32,2452,2453,2456],{"style":784},[32,2454],{"className":2455,"style":203},[202],[32,2457,2459],{"className":2458},[207,208,209,210],[32,2460,750],{"className":2461},[172,210]," alone. The same trick from ",[2209,2464,2465],{"href":2211},"the previous post"," fixes it: z-score each column, computed from training data only. The component I built for this post already normalizes under the hood before solving, exactly like I did back there.",[22,2468,2470],{"id":2469},"a-genuinely-complicated-function","A genuinely complicated function",[11,2472,2473,2474,2554],{},"With feature engineering I can model much wilder things than a parabola. I tested ",[32,2475,2477,2510],{"className":2476},[35],[32,2478,2480],{"className":2479},[39],[41,2481,2482],{"xmlns":43},[45,2483,2484,2507],{},[48,2485,2486,2488,2490,2493,2495,2497,2499,2503,2505],{},[54,2487,927],{},[64,2489,83],{},[54,2491,2492],{},"cos",[64,2494,812],{},[64,2496,74],{"stretchy":73},[54,2498,77],{},[54,2500,2502],{"mathvariant":2501},"normal","\u002F",[89,2504,750],{},[64,2506,80],{"stretchy":73},[152,2508,2509],{"encoding":154},"y = \\cos(x\u002F2)",[32,2511,2513,2531],{"className":2512,"ariaHidden":66},[159],[32,2514,2516,2519,2522,2525,2528],{"className":2515},[163],[32,2517],{"className":2518,"style":952},[167],[32,2520,927],{"className":2521,"style":956},[172,176],[32,2523],{"className":2524,"style":255},[254],[32,2526,83],{"className":2527},[259],[32,2529],{"className":2530,"style":255},[254],[32,2532,2534,2538,2541,2544,2547,2551],{"className":2533},[163],[32,2535],{"className":2536,"style":2537},[167],"height:1em;vertical-align:-0.25em;",[32,2539,2492],{"className":2540},[830],[32,2542,74],{"className":2543},[243],[32,2545,77],{"className":2546},[172,176],[32,2548,2550],{"className":2549},[172],"\u002F2",[32,2552,80],{"className":2553},[250]," with a polynomial up to degree 13:",[1163,2556],{":initial-degree":107,":max-degree":2557,":x-train":1166,":y-train":2558,"x-label":77,"y-label":2559},"13","[1.0,0.877583,0.540302,0.070737,-0.416147,-0.801144,-0.989992,-0.936457,-0.653644,-0.210796,0.283662,0.70867,0.96017,0.976588,0.753902,0.346635,-0.1455,-0.602012,-0.91113,-0.997172]","y = cos(x\u002F2)",[11,2561,2562,2563,2661,2662,2693,2694,2697,2698,2700],{},"Drag it up to degree 13: RMSE drops to ",[32,2564,2566,2596],{"className":2565},[35],[32,2567,2569],{"className":2568},[39],[41,2570,2571],{"xmlns":43},[45,2572,2573,2593],{},[48,2574,2575,2578,2581],{},[89,2576,2577],{},"1.1",[64,2579,2580],{},"×",[744,2582,2583,2586],{},[89,2584,2585],{},"10",[48,2587,2588,2590],{},[64,2589,132],{},[89,2591,2592],{},"5",[152,2594,2595],{"encoding":154},"1.1\\times10^{-5}",[32,2597,2599,2617],{"className":2598,"ariaHidden":66},[159],[32,2600,2602,2605,2608,2611,2614],{"className":2601},[163],[32,2603],{"className":2604,"style":972},[167],[32,2606,2577],{"className":2607},[172],[32,2609],{"className":2610,"style":358},[254],[32,2612,2580],{"className":2613},[362],[32,2615],{"className":2616,"style":358},[254],[32,2618,2620,2623,2626],{"className":2619},[163],[32,2621],{"className":2622,"style":763},[167],[32,2624,107],{"className":2625},[172],[32,2627,2629,2632],{"className":2628},[172],[32,2630,91],{"className":2631},[172],[32,2633,2635],{"className":2634},[181],[32,2636,2638],{"className":2637},[185],[32,2639,2641],{"className":2640},[190],[32,2642,2644],{"className":2643,"style":763},[194],[32,2645,2646,2649],{"style":784},[32,2647],{"className":2648,"style":203},[202],[32,2650,2652],{"className":2651},[207,208,209,210],[32,2653,2655,2658],{"className":2654},[172,210],[32,2656,132],{"className":2657},[172,210],[32,2659,2592],{"className":2660},[172,210],", a nearly perfect fit on the 20 training points. And here I deliberately swapped tools: instead of gradient descent with an ",[32,2663,2665,2680],{"className":2664},[35],[32,2666,2668],{"className":2667},[39],[41,2669,2670],{"xmlns":43},[45,2671,2672,2677],{},[48,2673,2674],{},[54,2675,2676],{},"α",[152,2678,2679],{"encoding":154},"\\alpha",[32,2681,2683],{"className":2682,"ariaHidden":66},[159],[32,2684,2686,2689],{"className":2685},[163],[32,2687],{"className":2688,"style":868},[167],[32,2690,2676],{"className":2691,"style":2692},[172,176],"margin-right:0.0037em;"," hand-tuned for every degree (what the original notebook does, and it's a lot of work), this component solves via the ",[610,2695,2696],{},"normal equation",", the same exact solution I already used to check results in ",[2209,2699,2465],{"href":2211},". That makes exploring many degrees instant, no alpha-hunting needed, leaving all the attention for what actually matters here: what happens once the model gets too flexible.",[22,2702,2704],{"id":2703},"the-elephant-in-the-room-overfitting","The elephant in the room: overfitting",[11,2706,2707,2708,2711,2712,2715],{},"I just fit ",[610,2709,2710],{},"14 parameters"," (13 weights + the bias) to ",[610,2713,2714],{},"20 data points",". The fit looked gorgeous. That should raise an alarm, not a celebration, and that's exactly what the original lab never does.",[2717,2718,2720],"h3",{"id":2719},"first-surprise-without-noise-flexibility-isnt-a-sin","First surprise: without noise, flexibility isn't a sin",[11,2722,2723],{},"I split the 20 points into 10 train (even indices) and 10 test (odd indices), with zero noise in the data:",[1874,2725,2726,2743],{},[1877,2727,2728],{},[1880,2729,2730,2734,2737,2740],{},[1883,2731,2733],{"align":2732},"center","Degree",[1883,2735,2736],{"align":1889},"Train RMSE",[1883,2738,2739],{"align":1889},"Test RMSE",[1883,2741,2742],{"align":1889},"test\u002Ftrain ratio",[1973,2744,2745,2758,2771,2784,2798],{},[1880,2746,2747,2749,2752,2755],{},[1978,2748,107],{"align":2732},[1978,2750,2751],{"align":1889},"0.708",[1978,2753,2754],{"align":1889},"0.709",[1978,2756,2757],{"align":1889},"1.0x",[1880,2759,2760,2762,2765,2768],{},[1978,2761,1385],{"align":2732},[1978,2763,2764],{"align":1889},"0.323",[1978,2766,2767],{"align":1889},"0.421",[1978,2769,2770],{"align":1889},"1.3x",[1880,2772,2773,2775,2778,2781],{},[1978,2774,2592],{"align":2732},[1978,2776,2777],{"align":1889},"0.043",[1978,2779,2780],{"align":1889},"0.141",[1978,2782,2783],{"align":1889},"3.3x",[1880,2785,2786,2789,2792,2795],{},[1978,2787,2788],{"align":2732},"7",[1978,2790,2791],{"align":1889},"0.002",[1978,2793,2794],{"align":1889},"0.039",[1978,2796,2797],{"align":1889},"21.4x",[1880,2799,2800,2803,2806,2809],{},[1978,2801,2802],{"align":2732},"9",[1978,2804,2805],{"align":1889},"0.000",[1978,2807,2808],{"align":1889},"0.009",[1978,2810,2811],{"align":1889},"24529x",[11,2813,2814,2815,2818,2819,2822],{},"I noticed something: at degree 9 (10 parameters for 10 training points, the exact boundary for a unique solution), the ratio looks catastrophic (24529 times!), but the ",[610,2816,2817],{},"absolute"," test error stays small (0.009). That contradicts the slogan \"lots of parameters always cause overfitting.\" The correct statement is more subtle: ",[610,2820,2821],{},"overfitting is the model fitting noise",", not simply having many parameters. With no noise to fit, a flexible model interpolates well, even at the extreme edge.",[2717,2824,2826],{"id":2825},"with-noise-the-phenomenon-shows-up-for-real","With noise, the phenomenon shows up for real",[11,2828,2829],{},"Real data always has noise. I added modest noise (standard deviation 0.15) and redid the test, now comparing several degrees at once:",[2831,2832],"train-test-curve-chart",{":points":2833,"test-label":2834,"train-label":2835},"[{\"degree\":1,\"trainRmse\":0.74482,\"testRmse\":0.7491},{\"degree\":2,\"trainRmse\":0.73486,\"testRmse\":0.76026},{\"degree\":3,\"trainRmse\":0.31894,\"testRmse\":0.42316},{\"degree\":4,\"trainRmse\":0.31481,\"testRmse\":0.4589},{\"degree\":5,\"trainRmse\":0.08323,\"testRmse\":0.27673},{\"degree\":6,\"trainRmse\":0.07051,\"testRmse\":0.1808},{\"degree\":7,\"trainRmse\":0.01868,\"testRmse\":0.45143},{\"degree\":8,\"trainRmse\":0.01212,\"testRmse\":0.72573},{\"degree\":9,\"trainRmse\":0.0,\"testRmse\":1.71735}]","test","train",[11,2837,2838],{},"Train error only ever drops (more parameters always fit what's already been seen at least as well, this is nearly a theorem, not a coincidence). Test error drops, hits a minimum around degree 6, then climbs sharply, reaching 1.72 at degree 9, worse than a degree-1 fit. That minimum is what matters, not whichever degree zeroes the training error.",[11,2840,2841],{},"Try it yourself, using only the 10 noisy training points (drag the degree and watch the live test RMSE, computed on the 10 points the fit never saw):",[1163,2843],{":initial-degree":107,":max-degree":2802,":x-train":2844,":y-train":2845,"x-label":77,"y-label":2846,":x-test":2847,":y-test":2848},"[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]","[1.193228, 0.550253, -0.579973, -1.143308, -0.623747, 0.365632, 0.960921, 0.528028, -0.097393, -0.880685]","y (with noise)","[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]","[1.094999, -0.043944, -0.796443, -1.151981, -0.19079, 0.571574, 0.966876, 0.427335, -0.243645, -1.018878]",[2717,2850,2852],{"id":2851},"extrapolation-where-it-gets-genuinely-dangerous","Extrapolation: where it gets genuinely dangerous",[11,2854,2855,2856,2859,2860,2888,2889,2892],{},"Everything so far was ",[1859,2857,2858],{},"inside"," the training range (",[32,2861,2863,2876],{"className":2862},[35],[32,2864,2866],{"className":2865},[39],[41,2867,2868],{"xmlns":43},[45,2869,2870,2874],{},[48,2871,2872],{},[54,2873,77],{},[152,2875,77],{"encoding":154},[32,2877,2879],{"className":2878,"ariaHidden":66},[159],[32,2880,2882,2885],{"className":2881},[163],[32,2883],{"className":2884,"style":868},[167],[32,2886,77],{"className":2887},[172,176]," from 0 to 19). Outside it, the behavior surprised me, and not in the way I expected. Drag the degree to 13 in the simulator below (the green band marks where the training data actually was) and notice: right past the edge, the degree-13 fit stays ",[610,2890,2891],{},"better"," than a low degree for a few points, because it learned the curve's shape with a lot of precision right at the boundary. That's exactly the trap: false confidence. Keep dragging the axis forward, and the same degree 13 that looked safe rockets off to infinity much faster than any low degree.",[1163,2894],{":initial-degree":1385,":max-degree":2557,":x-train":1166,":y-train":2558,"x-label":77,"y-label":2559,":view-max":2895,":view-min":2896},"30","-3",[11,2898,2899,2900,2953,2954,2989,2990,3019,3020,3049,3050,3101,3102,3137,3138,3167,3168,3227],{},"I computed the numbers to confirm what the eye sees: at ",[32,2901,2903,2922],{"className":2902},[35],[32,2904,2906],{"className":2905},[39],[41,2907,2908],{"xmlns":43},[45,2909,2910,2919],{},[48,2911,2912,2914,2916],{},[54,2913,77],{},[64,2915,83],{},[89,2917,2918],{},"22",[152,2920,2921],{"encoding":154},"x=22",[32,2923,2925,2943],{"className":2924,"ariaHidden":66},[159],[32,2926,2928,2931,2934,2937,2940],{"className":2927},[163],[32,2929],{"className":2930,"style":868},[167],[32,2932,77],{"className":2933},[172,176],[32,2935],{"className":2936,"style":255},[254],[32,2938,83],{"className":2939},[259],[32,2941],{"className":2942,"style":255},[254],[32,2944,2946,2950],{"className":2945},[163],[32,2947],{"className":2948,"style":2949},[167],"height:0.6444em;",[32,2951,2918],{"className":2952},[172],", three units past the boundary, degree 3 already misses by ",[32,2955,2957,2974],{"className":2956},[35],[32,2958,2960],{"className":2959},[39],[41,2961,2962],{"xmlns":43},[45,2963,2964,2971],{},[48,2965,2966,2968],{},[64,2967,132],{},[89,2969,2970],{},"5.42",[152,2972,2973],{"encoding":154},"-5.42",[32,2975,2977],{"className":2976,"ariaHidden":66},[159],[32,2978,2980,2983,2986],{"className":2979},[163],[32,2981],{"className":2982,"style":972},[167],[32,2984,132],{"className":2985},[172],[32,2987,2970],{"className":2988},[172]," (the true value is ",[32,2991,2993,3007],{"className":2992},[35],[32,2994,2996],{"className":2995},[39],[41,2997,2998],{"xmlns":43},[45,2999,3000,3005],{},[48,3001,3002],{},[89,3003,3004],{},"0.004",[152,3006,3004],{"encoding":154},[32,3008,3010],{"className":3009,"ariaHidden":66},[159],[32,3011,3013,3016],{"className":3012},[163],[32,3014],{"className":3015,"style":2949},[167],[32,3017,3004],{"className":3018},[172],") while degree 13 lands at ",[32,3021,3023,3037],{"className":3022},[35],[32,3024,3026],{"className":3025},[39],[41,3027,3028],{"xmlns":43},[45,3029,3030,3035],{},[48,3031,3032],{},[89,3033,3034],{},"0.03",[152,3036,3034],{"encoding":154},[32,3038,3040],{"className":3039,"ariaHidden":66},[159],[32,3041,3043,3046],{"className":3042},[163],[32,3044],{"className":3045,"style":2949},[167],[32,3047,3034],{"className":3048},[172],", nearly perfect. But by ",[32,3051,3053,3071],{"className":3052},[35],[32,3054,3056],{"className":3055},[39],[41,3057,3058],{"xmlns":43},[45,3059,3060,3068],{},[48,3061,3062,3064,3066],{},[54,3063,77],{},[64,3065,83],{},[89,3067,2895],{},[152,3069,3070],{"encoding":154},"x=30",[32,3072,3074,3092],{"className":3073,"ariaHidden":66},[159],[32,3075,3077,3080,3083,3086,3089],{"className":3076},[163],[32,3078],{"className":3079,"style":868},[167],[32,3081,77],{"className":3082},[172,176],[32,3084],{"className":3085,"style":255},[254],[32,3087,83],{"className":3088},[259],[32,3090],{"className":3091,"style":255},[254],[32,3093,3095,3098],{"className":3094},[163],[32,3096],{"className":3097,"style":2949},[167],[32,3099,2895],{"className":3100},[172],", degree 3 has only grown to ",[32,3103,3105,3122],{"className":3104},[35],[32,3106,3108],{"className":3107},[39],[41,3109,3110],{"xmlns":43},[45,3111,3112,3119],{},[48,3113,3114,3116],{},[64,3115,132],{},[89,3117,3118],{},"31",[152,3120,3121],{"encoding":154},"-31",[32,3123,3125],{"className":3124,"ariaHidden":66},[159],[32,3126,3128,3131,3134],{"className":3127},[163],[32,3129],{"className":3130,"style":972},[167],[32,3132,132],{"className":3133},[172],[32,3135,3118],{"className":3136},[172]," (bad, but growing slowly), while degree 13 is already at ",[32,3139,3141,3155],{"className":3140},[35],[32,3142,3144],{"className":3143},[39],[41,3145,3146],{"xmlns":43},[45,3147,3148,3153],{},[48,3149,3150],{},[89,3151,3152],{},"86",[152,3154,3152],{"encoding":154},[32,3156,3158],{"className":3157,"ariaHidden":66},[159],[32,3159,3161,3164],{"className":3160},[163],[32,3162],{"className":3163,"style":2949},[167],[32,3165,3152],{"className":3166},[172],", an absurd value for a function that never leaves ",[32,3169,3171,3197],{"className":3170},[35],[32,3172,3174],{"className":3173},[39],[41,3175,3176],{"xmlns":43},[45,3177,3178,3194],{},[48,3179,3180,3183,3185,3187,3189,3191],{},[64,3181,3182],{"stretchy":73},"[",[64,3184,132],{},[89,3186,107],{},[64,3188,67],{"separator":66},[89,3190,107],{},[64,3192,3193],{"stretchy":73},"]",[152,3195,3196],{"encoding":154},"[-1,1]",[32,3198,3200],{"className":3199,"ariaHidden":66},[159],[32,3201,3203,3206,3209,3212,3215,3218,3221,3224],{"className":3202},[163],[32,3204],{"className":3205,"style":2537},[167],[32,3207,3182],{"className":3208},[243],[32,3210,132],{"className":3211},[172],[32,3213,107],{"className":3214},[172],[32,3216,67],{"className":3217},[222],[32,3219],{"className":3220,"style":654},[254],[32,3222,107],{"className":3223},[172],[32,3225,3193],{"className":3226},[250],". The rule of thumb I'm keeping: never trust a polynomial prediction outside the training range, especially at higher degree, because the disaster isn't immediate, it's treacherous.",[22,3229,3231],{"id":3230},"wrapping-up","Wrapping up",[1874,3233,3234,3244],{},[1877,3235,3236],{},[1880,3237,3238,3241],{},[1883,3239,3240],{"align":1885},"What I already knew",[1883,3242,3243],{"align":1885},"What this post settled",[1973,3245,3246,3254,3262],{},[1880,3247,3248,3251],{},[1978,3249,3250],{"align":1885},"Linear regression only fits a line",[1978,3252,3253],{"align":1885},"Engineering new features (powers, logs, ratios), the same regression fits any curve",[1880,3255,3256,3259],{},[1978,3257,3258],{"align":1885},"More parameters fit what's already been seen better",[1978,3260,3261],{"align":1885},"That's nearly a theorem, and it's exactly why training error can't be used to pick a model",[1880,3263,3264,3267],{},[1978,3265,3266],{"align":1885},"The cost bowl is convex",[1978,3268,3269],{"align":1885},"Convex doesn't prevent overfitting: the problem isn't optimization, it's the model memorizing noise",[11,3271,3272],{},"Three takeaways:",[3274,3275,3276,3283,3289],"ol",{},[3277,3278,3279,3282],"li",{},[610,3280,3281],{},"Feature engineering doesn't change the algorithm",", it changes the data going into it. The same linear regression learns any curve if you hand it the right feature.",[3277,3284,3285,3288],{},[610,3286,3287],{},"Overfitting is about noise, not parameter count",": a flexible model with no noise to fit generalizes well, even at the extreme edge. The danger shows up once there's noise to memorize.",[3277,3290,3291,3294],{},[610,3292,3293],{},"Extrapolating with a high-degree polynomial is treacherous",": it can look better than a low degree right past the edge of the data, and still blow up far worse a bit further out.",[11,3296,3297,3298,3301,3302,1078],{},"One question remains: can I use all the flexibility of a high degree ",[610,3299,3300],{},"without"," paying overfitting's price? There's an answer with a continuous dial instead of the discrete choice of degree, called regularization, and it's ",[2209,3303,3305],{"href":3304},"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Ffeature-engineering-pitfalls","the subject of the next post",[22,3307,3309],{"id":3308},"practical-application","Practical application",[11,3311,3312,3313,3317,3318,3321],{},"Same real 50-house dataset from the previous posts. In ",[2209,3314,3316],{"href":3315},"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Ffeature-scaling-pitfalls","the normalization bonus post"," I already left a promise: \"feature engineering is the topic of the next lab.\" Following through: I created the feature ",[1087,3319,3320],{},"size_per_bedroom = square_feet \u002F num_bedrooms"," and compared the fit with and without it.",[1080,3323,3325],{"className":1082,"code":3324,"language":1084,"meta":1085,"style":1085},"size_per_bedroom = [s \u002F b for s, b in zip(square_feet, num_bedrooms)]\n\nrmse_before = fit_eval([square_feet, num_bedrooms, location_score, distance_to_center], price)\nrmse_after = fit_eval([square_feet, num_bedrooms, location_score, distance_to_center, size_per_bedroom], price)\n",[1087,3326,3327,3332,3338,3344],{"__ignoreMap":1085},[32,3328,3329],{"class":1091,"line":1092},[32,3330,3331],{},"size_per_bedroom = [s \u002F b for s, b in zip(square_feet, num_bedrooms)]\n",[32,3333,3334],{"class":1091,"line":1098},[32,3335,3337],{"emptyLinePlaceholder":3336},true,"\n",[32,3339,3341],{"class":1091,"line":3340},3,[32,3342,3343],{},"rmse_before = fit_eval([square_feet, num_bedrooms, location_score, distance_to_center], price)\n",[32,3345,3347],{"class":1091,"line":3346},4,[32,3348,3349],{},"rmse_after = fit_eval([square_feet, num_bedrooms, location_score, distance_to_center, size_per_bedroom], price)\n",[3351,3352,3353],"blockquote",{},[11,3354,3355,613,3358,3361,3362,3365],{},[610,3356,3357],{},"Output:",[1087,3359,3360],{},"RMSE without the new feature: 67.25"," \u002F ",[1087,3363,3364],{},"RMSE with the new feature: 65.13"," (thousand dollars)",[11,3367,3368,3369,3372,3373,3376,3377,1078],{},"A real, if modest, improvement (about 3%). Curious detail: the direct correlation between ",[1087,3370,3371],{},"size_per_bedroom"," and price is nearly zero (0.0069, very close to none), so if I'd only looked at the isolated correlation I'd have discarded this feature. It only helps once it joins the model ",[610,3374,3375],{},"together"," with the others, the same kind of hidden effect I already saw with the bedrooms coefficient in ",[2209,3378,2465],{"href":2211},[3380,3381],"housing-feature-engineering-explorer",{},[3383,3384,3385],"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":1085,"searchDepth":1098,"depth":1098,"links":3387},[3388,3389,3390,3391,3392,3393,3398,3399],{"id":24,"depth":1098,"text":25},{"id":908,"depth":1098,"text":909},{"id":1265,"depth":1098,"text":1266},{"id":2220,"depth":1098,"text":2221},{"id":2469,"depth":1098,"text":2470},{"id":2703,"depth":1098,"text":2704,"children":3394},[3395,3396,3397],{"id":2719,"depth":3340,"text":2720},{"id":2825,"depth":3340,"text":2826},{"id":2851,"depth":3340,"text":2852},{"id":3230,"depth":1098,"text":3231},{"id":3308,"depth":1098,"text":3309},null,"2026-08-19","How to make the exact same linear regression fit curves, by engineering new features instead of switching algorithms, and why that forced me to finally confront overfitting head-on.","md",{},8,"\u002Fen\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw2-lab04-feature-engineering","machine-learning-specialization",{"title":6,"description":3402},"published","en\u002Fplaylists\u002Fmachine-learning-specialization\u002Fw2-lab04-feature-engineering",[3412,3413,3414],"feature-engineering","polynomial-regression","overfitting","o5PN2HuTXzVCgWWHeOiFtGRm9a56zwrLaPudpL1oV10",1787338984895]