Practice lab week 3

Hello Team
Quick question please what does w_tmp = np.randon.rand(X_tmp.shape(-1, )-0.5 refer to …not able to understand -1 and -0.5 at the end. Thank you

1 Like

Hi @Jasmine7

The .reshape(-1,) reshapes the array to have a single dimension, preserving the total number of elements (in this case: 6).

The - 0.5 operation is performed element-wise and it is intended to shift the range of random values [0, 1) downwards by 0.5 [-0.5, 0.5).

4 Likes

This is another example where you could have easily answered the question yourself with a little experimentation and debugging print statements.

I recommend you get in the habit of doing small experiments to explore how Python works.

2 Likes

Thanks TMosh for your suggestion, I do that already. I would also like to use this forum as much as possible. I hope thats okay with you.

3 Likes

We are all here to learn, and its no harm asking questions @TMosh . Everybody is a learner once, nobody is born with the knowledge. Hence, people should have the freedom to ask any questions they have without any hesitation.

2 Likes

Thanks so much @Alireza_Saei
Thats very helpful

1 Like

Hi @Alireza_Saei why do we need to push values to -0.5, 0.5 is it because to ensure it includes the decision boundary

1 Like

Certainly this is true.

You can also discover a lot of answers with your own research.

2 Likes

Hello @Jasmine7

Pay attention that we’re discussing weight initialization (w_tmp), not data values (X_tmp). The values of X_tmp are all between 0 and 1 because of np.random.rand().

Limiting the range of weight initialization ensures a balanced starting point for the learning process and prevents weights from becoming too large or too small, which can lead to numerical instability and hinder convergence.

2 Likes

You’re welcome! happy to help :raised_hands:

1 Like

Obviously @TMosh I am doing my research at the same time. Thank you for maintaining a safe learning environment.

2 Likes

Could we have used something else other than 0.5…0.3 for example ?

1 Like

Yes, there are indeed various methods for weight initialization, and you can experiment with different ranges based on your specific needs. However, setting weight values to exactly 0 is typically avoided.

3 Likes