When running 2.44 3.4, the lab did not work in the right way. It overflowed. I am confused…
Code:
parameters_multi = nn_model(X_multi_norm, Y_multi_norm, num_iterations=100, print_cost=True)
print("W = " + str(parameters_multi[“W”]))
print("b = " + str(parameters_multi[“b”]))
W_multi = parameters_multi[“W”]
b_multi = parameters_multi[“b”]
Result:
Cost after iteration 0: 52.266244
Cost after iteration 1: 6618981604291.579102
Cost after iteration 2: 846311471320471930142720.000000
Cost after iteration 3: 108210469420893557562554204586770432.000000
Cost after iteration 4: 13835929311013789285734458757963686991802400768.000000
Cost after iteration 5: 1769079654897126770857256087341856345639617085546711482368.000000
Cost after iteration 6: 226196792063663968610530602691698484905007750099769924455996984393728.000000
Cost after iteration 7: 28921811744461971074263647029441669961057256873010218919233989563529600799080448.000000
Cost after iteration 8: 3697979918064753468611767061903613564854447867660278247773831145040239396492641364185448448.000000
Cost after iteration 9: 472828451939174241101160167524985525479677017422424281790690174628712046876677479756380366418217009152.000000
Cost after iteration 10: 60456451878244530430029171929007188343442993551648718108866132864433181150751073059623292032111550651175446511616.000000
Cost after iteration 11: 7730039422789805977543265648077239584304527807815652296397959581332504545474895051760172271236921257352072426273444806524928.000000
Cost after iteration 12: 988372748010822478507875547425075018179284770365458988985053588101430122555981400630442134759981168824130112868327892648533488201367552.000000
Cost after iteration 13: 126374606335177537346952003658909815802536310014330915178668880155622784852585336110695202906773248695662336387883048351735439918655576213016281088.000000
Cost after iteration 14: 16158419137428732557071000653563650415590689939276597030057474945531670419828762281445554618294888907475873148687125294604992298113099715419645342244122132480.000000
Cost after iteration 15: 2066036180784088932196025397644575441577376996106007468270517286640252130824718336621627302854273541652199449793115218461150252628845761183441746719397833845740979355648.000000
Cost after iteration 16: 264166034065888594994920277470848027424433222333237079115142656859937933655772737629977884983798853979600290690745963001240262348922298672576361613412997566575179978368383360958464.000000
Cost after iteration 17: 33776607691166578260156978892362428730432623733695873662095147388880126841226686985856082968172350797195948150977602656471011893601225970492984823147792106995880039840383265820638396360425472.000000
Cost after iteration 18: 4318720350090195007397869292663443417841863757956413633070920129669279127253670309255046811395317745601661521372590429033947121711994558964342935448252643620376984082906918890765715351353756504035426304.000000
Cost after iteration 19: 552197119166617028850131209212490444093105054755643021209521180569364014584883916970330077954404362306493696705664195679620776347778250461952377210559649878849461932276007861457626048523894693438641911680506789888.000000
Cost after iteration 20: 70604631394932144105822143178676692665470890816311924648653647041090519220645867506211199417932059332840987140501706109880335193740613515222609305528911316428376353486498080903763534169715068028865710213864540179863879811072.000000
Cost after iteration 21: 9027598662480696949791346234074689910217918656898007901767340465142563498978979872075747527490221771314542892597383773190924772640965134234731541576921036523041939283488631494732047689289065814216489241042450362705431794181789026615296.000000
Cost after iteration 22: 1154280335449395481067437683105948563797001418964732076327560912126540073829305817800488080959675675617504875358391955268529159374558627033823584923417578289140805501302290701208260652044467538082962603619273689835029631645767770208855801854951424.000000
Cost after iteration 23: 147587763104994789910827929846622944556688317698167280922796143807690307657626837573341062789309929452516452842045261885111475450824124391661241999487334529285182013460041416318747372374173425030077246278468425887808031052974204369428868183329886619392016384.000000
Cost after iteration 24: 18870760550430448032422151823432421034187229148334832210908129567559089569212959215897373298651027124534427451960260367428435156830652321854273385783079572678569835225541363602127040101614167841331660142172530082475360341806353036580160280061549308625518772129988870144.000000
Cost after iteration 25: 2412839630195806056086779727717868286202566319089730202051994440355653709722785033838408931386198874454777614749414534120780633665826925974391122547124641472125474550471115273757902239620878518259167792842121395213801366835927995292129781068945001974030670481163203200112882876416.000000
Cost after iteration 26: 308508767597638546987431066808771640538855783775107818633059004916463089227393414685663264111133720299752067319121686351861839254728439872730574809322337364163381163945687943778147841331009105531933192738157416928027465141051835709930310704314622784265849791764764885986421272104540517171200.000000
Cost after iteration 27: 39446326433593120950046469310987612741666700401366943235925957836628992364143012562959017745241431674821045489447943653937643500074979465691063014221000721230508072129669877103582591215393739234533793564156527250554049721377007996151617579978453306488876505946559964601420705452911222119100454312869888.000000
Cost after iteration 28: inf
Cost after iteration 29: inf
Cost after iteration 30: inf
Cost after iteration 31: inf
Cost after iteration 32: inf
Cost after iteration 33: inf
Cost after iteration 34: inf
Cost after iteration 35: inf
Cost after iteration 36: inf
Cost after iteration 37: inf
Cost after iteration 38: inf
Cost after iteration 39: inf
Cost after iteration 40: inf
Cost after iteration 41: inf
Cost after iteration 42: inf
Cost after iteration 43: inf
Cost after iteration 44: inf
Cost after iteration 45: inf
Cost after iteration 46: inf
Cost after iteration 47: inf
Cost after iteration 48: inf
Cost after iteration 49: inf
Cost after iteration 50: inf
Cost after iteration 51: inf
Cost after iteration 52: inf
Cost after iteration 53: inf
Cost after iteration 54: inf
Cost after iteration 55: inf
Cost after iteration 56: nan
Cost after iteration 57: nan
Cost after iteration 58: nan
Cost after iteration 59: nan
Cost after iteration 60: nan
Cost after iteration 61: nan
Cost after iteration 62: nan
Cost after iteration 63: nan
Cost after iteration 64: nan
Cost after iteration 65: nan
Cost after iteration 66: nan
Cost after iteration 67: nan
Cost after iteration 68: nan
Cost after iteration 69: nan
Cost after iteration 70: nan
Cost after iteration 71: nan
Cost after iteration 72: nan
Cost after iteration 73: nan
Cost after iteration 74: nan
Cost after iteration 75: nan
Cost after iteration 76: nan
Cost after iteration 77: nan
Cost after iteration 78: nan
Cost after iteration 79: nan
Cost after iteration 80: nan
Cost after iteration 81: nan
Cost after iteration 82: nan
Cost after iteration 83: nan
Cost after iteration 84: nan
Cost after iteration 85: nan
Cost after iteration 86: nan
Cost after iteration 87: nan
Cost after iteration 88: nan
Cost after iteration 89: nan
Cost after iteration 90: nan
Cost after iteration 91: nan
Cost after iteration 92: nan
Cost after iteration 93: nan
Cost after iteration 94: nan
Cost after iteration 95: nan
Cost after iteration 96: nan
Cost after iteration 97: nan
Cost after iteration 98: nan
Cost after iteration 99: nan
W = [[nan nan]]
b = [[nan]]
C:\Users\pangu\AppData\Local\Temp\ipykernel_22420\651274294.py:17: RuntimeWarning: overflow encountered in square
cost = np.sum((Y_hat - Y)**2)/(2*m)
C:\Users\pangu\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\fromnumeric.py:86: RuntimeWarning: overflow encountered in reduce
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
C:\Users\pangu\AppData\Local\Temp\ipykernel_22420\583824931.py:14: RuntimeWarning: invalid value encountered in matmul
Z = np.matmul(W, X) + b
Code:
X_pred_multi = np.array([[1710, 7], [1200, 6], [2200, 8]]).T
Y_pred_multi = predict(X_multi, Y_multi, parameters_multi, X_pred_multi)
print(f"Ground living area, square feet:\n{X_pred_multi[0]}“)
print(f"Rates of the overall quality of material and finish, 1-10:\n{X_pred_multi[1]}”)
print(f"Predictions of sales price, $:\n{np.round(Y_pred_multi)}")
Result:
ValueError Traceback (most recent call last)
Cell In[50], line 2
1 X_pred_multi = np.array([[1710, 7], [1200, 6], [2200, 8]]).T
----> 2 Y_pred_multi = predict(X_multi, Y_multi, parameters_multi, X_pred_multi)
4 print(f"Ground living area, square feet:\n{X_pred_multi[0]}“)
5 print(f"Rates of the overall quality of material and finish, 1-10:\n{X_pred_multi[1]}”)
Cell In[42], line 13, in predict(X, Y, parameters, X_pred)
11 X_pred_norm = ((X_pred - X_mean)/X_std).reshape((1, len(X_pred)))
12 else:
—> 13 X_mean = np.array(np.mean(X)).reshape((len(X.axes[1]),1))
14 X_std = np.array(np.std(X)).reshape((len(X.axes[1]),1))
15 X_pred_norm = ((X_pred - X_mean)/X_std)
ValueError: cannot reshape array of size 1 into shape (2,1)