0
$\begingroup$

I am new to machine learning and i am trying to understand this called from scikit's learn website under linear regression example:

prediction = print((clf.predict(x_test) - y_test) **2)
score = print(clf.score(x_test, y_test))

Why would i use the test data to make predictions or for checking variance score? Shouldn't it be the train data? Also i am trying to understand the prediction formula's framework and if anyone has resources to refer me to, that would be great.

$\endgroup$
1
  • $\begingroup$ Please edit you code as code by indenting it 4 spaces. I tried to do it for you, but that was to little of a chance as to be accepted by this page (not at least 6 letters) $\endgroup$
    – Bernhard
    Commented Sep 9, 2016 at 6:38

1 Answer 1

0
$\begingroup$

I'd say it's well explained on Wikipedia

https://en.wikipedia.org/wiki/Test_set

Training set = used to fit your model , you look at it, you process it, you come up with good parameters.

Test set = independent data to check the robustness of the model you came up with at the training phase.

Imagine that you're trying to work out a relationship between how much people earn per month and how tall they are. You would study 100 people, get their salaries, measure them and try to fit some model (say a linear model). With that training data you would end up with a fit of the form:

$h = \alpha e + \beta + \text{noise}$

where $h$ is a person's height, $e$ is a person's salary and $\alpha$ and $\beta$ are picked, based on your data to provide a good fit.

Now, let's say you want to evaluate how good this model is. One thing would be to look at how big "noise" is. But another thing is: does this model work on other data, on people I have not seen ??? if it does then it's a good model, I may have actually found something. If not, then you've just found something within your data which is not reproducible.

So this is why people split the data set they have in training and test usually with an 80/20 thumb rule so that they can artificially recreate the test above for robustness.

Alright.

Onwards with your next question. The prediction formula looks like it's computing the square of the error for a single test point. I don't think it's a framework per se. However people do consider things like the MSE https://en.wikipedia.org/wiki/Mean_squared_error (which is what you have here with $n=1$ or the RMSE https://en.wikipedia.org/wiki/Root-mean-square_deviation which is a direct extension and many other depending on what you're interested in but these two are fairly standard.

$\endgroup$

Your Answer

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

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