I am new at ML, and still trying to understand some concepts, so I figured I could ask here and maybe finally understand.

How does it work the whole splitting data from a data set?

Before answering, here is what I "know" and "understand" so far:

I have a data set, I'll call it "ds". ds has 10 features, f1,f2...f10, would be represented by each column of the ds. Now, I also have an array of labels that goes with each row of ds, which represents what each sample of data outputs.

Samples F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 Labels
1 ele1 ele2 ele3 ele4 ele5 ele6 ele7 ele8 ele9 ele10 1
2 ele11 ele12 ele13 ele14 ele15 ele16 ele17 ele18 ele19 ele20 0
... ... ... ... ... ... ... ... ... ... ... ...
n n n+1 n+2 n+3 n+4 n+5 n+6 n+7 n+8 n+9 1

Next, when testing ML algorithms, I'm suppose to split the ds into training data (training_data) and testing data (testing_data), and same thing with the labels, training label (training_labels), and testing labels (testing_labels). So now I have 4 pieces of information.

In order to check the algorithm's performance, I have to run the algorithm to each set of training data (rows...), and it would produce one result for each row, to which I would like to call "trained data". Once the algorithm has been run on the training data, I will also have an array of "trained_labels" ->[trained_label1, trained_label2, ... trained_label_n ] which it's size will match with the number of rows of the training_data.

Finally, I'm supposed to use this newly created "trained_labels" and compare it to the testing_labels and based on the accuracy (if all the trained_labels match all the testing_labels then it would be 100% accurate), I will be able to tell how good was the algorithm

Assuming a proportion 80% training and 20% testing, here is the big question that I still I am not able to wrap my head around, the size of the trained_labels will be different to the size of the testing labels, so given that fact, how can I campare the accuracy?

Like coding that with python syntax would be:

accuracy = (testing_labels == trained_labels).sum() / len(testing_labels) *100,

So if I could get some guidance it would be very appreciated.

Kind regards

P.S: I don't think slicing the training_labels size to match testing_labels size would be the answer.


1 Answer 1


I think there is a slight misconception here. When you are training your data, the algorithm is not producing a "trained label", it is using the labels to try to find the best fit of the model on your data to maximize its performance (getting it as close as possible as trained labels that we know). So your models literally "knows" the value of the training sample and labels.
Now what we want to do is evaluate whether this model that we fitted is performing decently on data it has not learned directly on. This is why we have the test data, which is data not seen yet by the algo. We will then compare the labels given by our model for the data it has not seen yet with the true results (test labels) that we know.
Regarding the 80/20 split or different cross validation techniques, we want to optimize the amount of data we train our model on. Basically you want your model to be trained on as much of "production like" data as possible, depending on your use case you might change the split arbitrarily or use cross validation to optimize the amount of data you train/test on.

  • $\begingroup$ Thanks @Mayeul sgc, I appreciate it, though I'm still not clear on a few things. Maybe if I break it down into smaller bits I might get the hang of it. So when the algorithm produces an output when evaluating the features i.e A(f1,f2,f3...f10) -> "output" (what I initially considered a trained label) for each training data row, what does that represent then? $\endgroup$
    – gustavexx
    Apr 2, 2022 at 3:03

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.