Calculus Week 3, Lab 1: Issues Running on Local Machine

For those wanting to run the Regression with Perceptron lab (Lab 1 of week 3) on your local machine, there are some changes that are needed if you are running a newer version of Numpy. The hosted notebook is running v. 1.20.1, while I have v. 1.26.2. An issue arises with the new version when calculating the norms using the Pandas DataFrame in section 1.3.

In particular, the later version of Numpy requires the code to specify an axis when calculating the mean. Here is the warning:

FutureWarning: The behavior of DataFrame.std with axis=None is 
deprecated, in a future version this will reduce over both axes and
 return a scalar. To retain the old behavior, pass axis=0 (or do not 
pass axis)   return std(axis=axis, dtype=dtype, out=out, ddof=ddof, 
**kwargs)

I initially just plugged in axis=0 as suggested, but this resulted in a divergent series when running the nn_model() function, not a convergent series. There may be a more elegant ways to resolve this, but this is the code I used:

adv_norm = pd.DataFrame({
    "TV": (adv["TV"] - np.mean(adv["TV"]))/np.std(adv["TV"]),
    "Sales": (adv["Sales"] - np.mean(adv["Sales"]))/np.std(adv["Sales"])
})

PS: I have posted code here because this is for a non-graded lab assignment which is presented for student review; thus I do not believe this to be a breach of the Code of Conduct.

1 Like

Thanks for posting this information.

1 Like