0
$\begingroup$

Where $h_{\theta} = \theta_{0} + \theta_{1}x$, I am trying to minimize $J(\theta) = \frac{1}{2m}\sum_{i = 1}^{m}(h_{\theta}(x^{(i)}) - y^{(i)})^{2}$

I first transform every sample in the feature (there is only one feature) using:

$X_{\alpha} = \frac{X - X_{min}}{X_{max} - X_{min}}$

Then, I run batch gradient descent (I'm implementing regression from an ML standpoint (if I can make the notion of regression approached from a field)), and these are the values of $\theta$ I get:

$\theta = [5.670, 2.301] = [\theta_{0}, \theta{1}]$

$X_{min} = 5.0269$

$X_{max} = 22.203$

To test these parameters, when I go to plot, I simply plot $(X, h_{\theta}(X_{\alpha}))$:

x = pylab.linspace(0,30, num = 1000)
x1 = (x - 5.0269)/(22.203 - 5.0269)

y = 5.67002243 + 2.301*x1
plt.plot(x,y)

That is, I take any value $x$, transform it to $x_{a}$, then finds its output $y$ using $h_{\theta}$ and plot $(x,y)$.

This does not give the line of best of fit, however.

$\endgroup$
2
  • $\begingroup$ It should work correctly, you are taking the right approach. How about if you plot x1 versus y? Does that look good? $\endgroup$
    – Tom
    Jun 4, 2016 at 10:00
  • $\begingroup$ My gradient descent didn't use a small enough tolerance (between $\theta_{n}$ and $\theta_{n+1}.$ That was the error. Just as an aside, if I construct any transformation $X_{\alpha} = f(X)$, is it a guarantee that parameters from this scaling can be used to calculate the "expected value" of any random point in $X$? $\endgroup$
    – Muno
    Jun 5, 2016 at 19:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.