Issue in Programming Assignment: Deep Learning for Content-Based Filtering

I am facing while Write a function to compute the square distance . please anyone tell me the code .



def sq_dist(a,b):
Returns the squared distance between two vectors
a (ndarray (n,)): vector with n features
b (ndarray (n,)): vector with n features
d (float) : distance
d=d + np.square(b)
return d

Hi @Shagun_jain ,

Please follow the formula marked (1). You need to find the difference between each element of vector a, and vector b, and then square the differences, and finally add those differences together to produce a single value.
To get the difference of each element between vector a and b, you can simply do a-b, resulting a vector of differences. You can then call np.square() with the differences vector as parameter, and finally, call np.sum() over the squared differences vector to produce a single value.

1 Like

Hi @Shagun_jain, and @Kic,

I just wrote a topic on the exercise, and I just want to share it with you.


1 Like


Thank you for creating the post on MLS resources.

@rmwkwok Thank you so much . i understand this concept now. thanks

You are welcome @Shagun_jain!

Hi everybody,
could you please help me with excercise 1 in this programming assignment?
I’ve seen the hints and solution, compared it to my code, but nevertheless I get back an error
I am attaching the screenshot if it helps.

{code removed by mentor}

Hello @Petar_Soric,

The error message below indicates that you were referencing a variable called Model which had never been defined.

However, the line that triggered the problem isn’t part of the exercise, so I supposed you had somehow unintentionally modified it. You might just replace that line with the following:

model = tf.keras.Model([input_user, input_item], output)

Note that unless we had from tensorflow.keras import Model (which we havn’t), we need to use tf.keras.Model to reference to it (since we have import tensorflow as tf)


PS: I will remove your code since we can’t share assignment code here. Next time, please just share a screenshot of just the error traceback.

Thanks a lot, @rmwkwok !

You are welcome @Petar_Soric!