01.04.2015 Views

1FfUrl0

1FfUrl0

1FfUrl0

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Regression – Recommendations<br />

In the following screenshot, we can see that visually it looks better (even though<br />

a few outliers may be having a disproportionate impact on the result):<br />

Ideally, though, we would like to measure how good of a fit this is quantitatively.<br />

In order to do so, we can ask how close our prediction is. For this, we now look<br />

at one of those other returned values from the np.linalg.lstsq function, the<br />

second element:<br />

(slope,bias),total_error,_,_ = np.linalg.lstsq(x,y)<br />

rmse = np.sqrt(total_error[0]/len(x))<br />

The np.linalg.lstsq function returns the total squared error. For each element, it<br />

checks the error (the difference between the line and the true value), squares it, and<br />

returns the sum of all these. It is more understandable to measure the average error,<br />

so we divide by the number of elements. Finally, we take the square root and print<br />

out the root mean squared error (RMSE). For the first unbiased regression, we get<br />

an error of 7.6, while adding the bias improves it to 6.6. This means that we can<br />

expect the price to be different from the real price by at the most 13 thousand dollars.<br />

[ 150 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!