Optional lab: Gradient descent

The link to open the optional lab: Gradient Descent does not work.

Thanks, I’ll send a report to the course staff.

Reports from staff are that it seems to work fine when they test it.
Are you still seeing this issue?

1 Like

Also I’ve moved this to the Week 1 discussion area, since that’s what is shown in the image you attached.

1 Like

Hi,

When i run the “C1_W1_Lab05_Gradient_Descent_Soln.ipynb” locally, i am getting error on the last command where Alpha is increased and the graph is plotted to show how gradient descent never converges.
This is working fine when run directly from the optional lab link.
Can anyone help what i am missing when running on my local notebook ?

Hey @thahura,
It happens due to something known as sys.maxsize. Since this most probably differs for the remote machine and your local machine, hence, the error is generated. You can know more about this and one possible way to rectify this error on this thread. I hope this helps.

Regards,
Elemento

@Elemento
Thanks. I’ll check the link where this is discussed and see if it can be fixed.

1 Like

@Elemento
Was able to fix this by making this change in plt_divergence

cost = np.zeros_like(w_array)
cost=cost.astype(float)

z=np.zeros_like(tmp_b)
z=z.astype(float)

7 Likes

Hi, I am facing the same issue but am unable to understand the solution mentioned here. I had opened the “lab_utils_uni.py” file and referred to the “plt_divergence” section mentioned there.
But I couldn’t find where to insert the above-mentioned code?[quote=“thahura, post:8, topic:138954, full:true”]
@Elemento
Was able to fix this by making this change in plt_divergence

cost = np.zeros_like(w_array)
cost=cost.astype(float)

z=np.zeros_like(tmp_b)
z=z.astype(float)
[/quote]

1 Like

Hey @Deependu_Ghosh,
You can find them as below. I am mentioning a few lines before and after just for your reference.

First Change

# Print w vs cost to see minimum
fix_b = 100
w_array = np.arange(-70000, 70000, 1000)
cost = np.zeros_like(w_array)

After the last line of code (in the above lines) cost = np.zeros_like(w_array), another line of code cost=cost.astype(float) is added.

Second Change

tmp_b,tmp_w = np.meshgrid(np.arange(-35000, 35000, 500),np.arange(-70000, 70000, 500))
z=np.zeros_like(tmp_b)
for i in range(tmp_w.shape[0]):
    for j in range(tmp_w.shape[1]):

After the second line of code (in the above lines) z=np.zeros_like(tmp_b), another line of code z=z.astype(float) is added.

I hope this helps.

Cheers,
Elemento

1 Like

Hello @Elemento,

I had referred to the abovementioned changes in the codes but still got the same error. In fact, I had tried replacing “float” with “int64” but still no luck. screenshots are attached for your preview, kindly assist with the same.
Change_1


Hey @Deependu_Ghosh,
Apologies for the inconvenience, I misunderstood the reply posted by Thahura. Please refer to my updated reply once, and if it doesn’t help, then please refer to this thread. This is the original StackOverflow thread that I posted for this discussion. I hope this helps.

Cheers,
Elemento


Hello @Elemento ,
I am facing this issue related to IndexError and working on the same since 20th July 2022 but the issue stills exist. The thread shared here StackOverflow is not having the proper solution. Also, the changes in “lab_utlis_uni.py” were made for error removal but weren’t of any help.

Requesting you, to provide the necessary assistance as I am facing similar issues in other Lab sessions also while working on jupyter notebooks for practice purposes!

Hey @Deependu_Ghosh,
The lab runs perfectly fine on my local system. Can you please let me know the changes that you have done in the lab before running it on your local system, so that I can re-produce this issue?

Cheers,
Elemento

Hello @Elemento,
As advised in the trailing set of emails, the necessary changes were made as advised above (screenshot attached) and also the error screenshot attached for reference.
AddedAsAdvised_1


Hey @Deependu_Ghosh,
I tried with and without these changes. The lab is running perfectly fine in my local system without any errors. I am assuming that the error is arising due to the difference in the versions of the packages used. You can try creating a new virtual environment, and install the same version of all the packages used in this lab, and then try running this lab in the virtual environment. Or, you can simply run this in the Coursera labs, for which this and other labs are designed to run in. I hope this helps.

Cheers,
Elemento

@Elemento , Thank you for being patient!

The Coursera lab version details are as follows:

From my local system details are as follows:

After incorporating the initially mentioned changes in lab_utils_uni.py, the code worked just fine.

Hey @Deependu_Ghosh,
I am glad you were able to run your code without any issues. Happy learning!

Cheers,
Elemento

Thank you for your answer. It worked fine for me.