# Prediction W2 Assignment

**URL:** <https://community.deeplearning.ai/t/prediction-w2-assignment/255117>\
**Category:** Advanced Learning Algorithms\
**Tags:** week-module-2\
**Created:** [January 10, 2023, 5:00pm UTC](https://community.deeplearning.ai/t/prediction-w2-assignment/255117 "2023-01-10T17:00:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Leal](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/alexandre_leal/32/34925_2.png) [@Alexandre\_Leal](https://community.deeplearning.ai/u/Alexandre_Leal)\
**Post date:** [January 10, 2023, 5:00pm UTC](https://community.deeplearning.ai/t/prediction-w2-assignment/255117/1 "2023-01-10T17:00:07Z")

</div>

In the following code we have the prediction for the number in the exemple, but I didn’t get all clear about the number in the array(predicting Two).

image\_of\_two = X[1015]  
display\_digit(image\_of\_two)

prediction = model.predict(image\_of\_two.reshape(1,400)) # prediction

print(f" predicting a Two: \n{prediction}“)  
print(f” Largest Prediction index: {np.argmax(prediction)}")

The Output:

predicting a Two:  
[[-7.99 -2.23 0.77 -2.41 -11.66 -11.15 -9.53 -3.36 -4.42 -7.17]]  
Largest Prediction index: 2

Is this the probability of the number? Why is it negative?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![RyanCarr](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@RyanCarr](https://community.deeplearning.ai/u/RyanCarr)\
**Post date:** [January 10, 2023, 8:22pm UTC](https://community.deeplearning.ai/t/prediction-w2-assignment/255117/2 "2023-01-10T20:22:04Z")

</div>

They aren’t probabilities. The important thing is the positive number 0.77 in position [2] of the array. np.argmax finds the index with the largest value. We have trained the neural network to return smaller numbers if it doesn’t match and larger numbers if it does match. That’s why there are a bunch of negative numbers.

In the next step of the code it does the same thing using softmax which does return probabilities. If you add up all the numbers in the array prediction\_p they all add up to 1.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [January 10, 2023, 10:09pm UTC](https://community.deeplearning.ai/t/prediction-w2-assignment/255117/3 "2023-01-10T22:09:08Z")

</div>

Just to add, since the sigmoid-then-softmax functions are monotonic, it doesn’t matter whether it is included when you are trying to find the output with the highest value.

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [January 10, 2023, 10:52pm UTC](https://community.deeplearning.ai/t/prediction-w2-assignment/255117/4 "2023-01-10T22:52:31Z")

</div>

Hello @Alexandre_Leal,

Some other things that I want to add is that those numbers are called logits, and they can be positive or negative. Softmax transforms logits to probabilities. The model keeps logits as output to take advantage of the `from_logits=True` option which has been explained [in this video by Andrew](https://www.coursera.org/learn/advanced-learning-algorithms/lecture/Tyil1/improved-implementation-of-softmax).

Cheers,  
Raymond

---

<div class="post-metadata">

**Author:** ![Alexandre\_Leal](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/alexandre_leal/32/34925_2.png) [@Alexandre\_Leal](https://community.deeplearning.ai/u/Alexandre_Leal)\
**Post date:** [January 14, 2023, 4:37pm UTC](https://community.deeplearning.ai/t/prediction-w2-assignment/255117/5 "2023-01-14T16:37:49Z")

</div>

Thank you for all the explanations. Much appreciated!
