Been doing machine learning since a few months by now. I've a grounding questions that I couldn't answer by my self. It's possible I'm asking the wrong question: When training models, like XGBoost, you can't predict over new data that hasn't the same number of columns. Does the column names matter? How does number and column names interact when predicting? Thanks in advance.


1 Answer 1


It depends on the model. Some models work without column names, other require them. The models that do not require column names, take in consideration the position of the column. If your columns are not named, and are misplaced you will have a really bad time. For the best practice, keep the columns named and in the same positions as in the training set.

Some models even work with less columns than the training set, however this will result in a low accuracy and will throw in a warning: "different number of features ...". If you have less columns in the new data, just train the model with the same columns. Do not train the model on more columns than you will have in the new (unseen) data.

  • $\begingroup$ thanks! is there a anywhere I can read more about this? different machine learning algorithms and how they interact with columns $\endgroup$
    – juanmac
    Jan 24, 2023 at 17:23
  • $\begingroup$ Unfortunately, I cannot find something similar. You can try by searching for the name of the model you are interested in and "feature names"/ "feature positions" or "unnamed features"/ "misplaced features". Generally, you should just keep in mind that you should name them, and keep them in the same positions. This does not take a lot of effort. It is just 2 lines of code. Even if you do not know what a certain column represents, give it a name and keep the same name in the new data. $\endgroup$ Jan 26, 2023 at 10:13
  • $\begingroup$ I'll do that. thanks for your help $\endgroup$
    – juanmac
    Jan 26, 2023 at 17:45

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.