0
$\begingroup$

The equation to find the partial derivative of a cost function with respect to a parameter θj is given in the book 'Hands on Machine Learning with scikit-learn, keras and tensorflow ':

enter image description here

  • m = number of instances in the dataset
  • x = input vector for the prediction
  • y = label for the input vector

I am not able to understand what the last scalar x(i)j means. Could someone please tell me what the variable means.

$\endgroup$
1
$\begingroup$

From the context you have provided, my reading is that $x^{(i)}_j$ is the $j$-th element of the $i$-th input vector $\mathbf{x}^{(i)}$, where there are $i = 1,..., m$ training instances.


Addressing comments.

In response to:

So in the case where $j = 1$, that is, $\theta_j = \theta_1$, then $x^{(i)}_j$ would be the 1st element of $\mathbf{x}^{(i)}$.

Yes you are entirely correct.

And in response to:

E.g : If $\mathbf{x}^{(i)} = [1,2,3,4,5]$ and $\theta_j = \theta_1$ then $x^{(i)}_j$ = 2 (considering 0 to be the first index).

This is just my view, but my personal preference, and also advice, is to make a distinction between formal "mathematics-indexing" which you see in mathematics in print, and implementational "Python-indexing". This is to avoid confusion.

In the case of mathematics-indexing, which is the convention for indexing vectors like $\mathbf{x}^{(i)}$ in print, then in your case $j = 1, ... 5$. In this case, then in your example $x^{(i)}_1 = 1$, i.e. the first element of the vector $\mathbf{x}^{(i)}$.

In the case of (what I am assuming to be) Python-indexing, which is what you will need for implementation, then $j = 0, ..., 4$. For your example, under this convention, then you are correct, $x^{(i)}_1 = 2$. Having now checked the book this is correct, Geron is using $j = 0, ..., n$ to index $(n+1)$ elements of the vector $\mathbf{x}^{(i)}$.

$\endgroup$
5
  • $\begingroup$ So if θj = θ1, then x(i)j would be the 1st element of x(i). E.g : If x(i) = [1,2,3,4,5] and θj = θ1 then x(i)j = 2 (considering 0 to be the first index). $\endgroup$ – Arya Man Apr 1 at 20:04
  • $\begingroup$ Thank you, that helps. $\endgroup$ – Arya Man Apr 1 at 20:42
  • $\begingroup$ Having now looked at the book - you are correct on both counts, the author is using using $j= 0, ..., n$ to index the $(n+1)$ elements of $\mathbf{x}^{(i)}$. $\endgroup$ – microhaus Apr 1 at 20:45
  • $\begingroup$ Sorry, but could I ask a small follow-up question? If θj = 5 then should the jth element in θ also be 5? E.g - If on the left hand side θj= θ3 = 5 then should the θ on the right-hand-side of the equation be [θ0, θ1, θ2, 5, θ4, θ5, θ6]? $\endgroup$ – Arya Man Apr 2 at 0:31
  • $\begingroup$ I will use a new response to answer your new question at stats.stackexchange.com/questions/517820/… and address this final comment in the new response $\endgroup$ – microhaus Apr 2 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.