What Is Feature Selection and Why Can Fewer Variables Give You a Better Model?
Feature selection is the process of choosing which columns of a dataset enter a machine learning model. Fewer variables can give you a better model because every extra column adds noise, processing cost, and a chance for the model to memorize patterns that do not repeat. The goal is not to cut for the sake of cutting, but to measure what each variable actually contributes.
What is feature selection, in practice?
Feature selection is deciding which columns of a dataset go into a machine learning model. Instead of feeding the whole table in, you evaluate what each variable adds and keep only the subset that carries useful information about the target. It is a decision about which columns stay, not a transformation of their values.
It helps to separate it from dimensionality reduction. Feature selection keeps a subset of the original columns, so the result stays readable: you can say which variable stayed and which one was dropped. Techniques such as principal component analysis build new combined variables and lose that direct reading. Both shrink the input, but they answer different questions.
In practice, the work starts with meaning, not metrics. Read what each column represents and how it is collected before you look at any score. A variable can correlate strongly with the target and still be useless in production, because it only exists after the outcome you are trying to predict. That kind of data leakage produces strong validation numbers and a model that fails on new data.
- Understand what each column represents and how it is collected
- Drop constant, duplicated, or leaky columns
- Measure each variable's relationship with the target through correlation, mutual information, or importance
- Train the model on different subsets and compare them with cross-validation
- Document what was left out and why, so the decision can be repeated
Why can fewer variables give you a better model?
Every extra variable enlarges the space of hypotheses the model has to search. With many columns and few rows, it becomes easy to find a combination that fits the past and misses the future. That is overfitting: the model memorizes noise instead of learning the pattern. Fewer variables shrink that space and reduce the chance of memorizing.
Redundant variables cause a second problem. When two columns carry nearly the same information, the coefficients of a linear model become unstable: small changes in the data move the weights a lot, and reading the model stops making sense. Keeping one of the two usually gives a steadier and more explainable result.
Cost and clarity count as well. Fewer columns mean faster training, less memory, and fewer inputs to monitor after deployment. In a project that other people have to maintain, a model with ten understandable variables is often more useful than one with two hundred that nobody can explain.
None of this is a guarantee. Removing a variable that carries real signal makes the model worse, and there are cases where the full set wins. The answer is to measure: compare performance with and without the subset using cross-validation instead of trusting intuition.
Which feature selection methods are there?
The methods fall into three families. Filter methods score each variable with a statistical measure and never train a model. Wrapper methods train the model repeatedly on different subsets. Embedded methods perform the selection during training itself.
Among embedded methods, L1 regularization drives the coefficients of weak variables to zero in linear models. Tree models expose feature importance, and Random Forest, Gradient Boosting, XGBoost and LightGBM are commonly used to rank columns before deciding what stays. Which method you pick depends on the size of the dataset, the time you have, and how much you need to explain the decision.
The trap is always the same: any selection done before splitting the data into training and test contaminates the evaluation. Ranking belongs inside the training pipeline, and cross-validation is what shows whether the chosen subset actually helps.
- Filter: variance, correlation, chi-square, and mutual information
- Wrapper: forward selection, backward selection, and recursive feature elimination
- Embedded: L1 regularization and tree-based feature importance
How do you run feature selection without fooling yourself?
Split the data first. If you rank variables on the full dataset and then split, the test set has already influenced which columns were kept, and the score you get is optimistic. Fit the selection inside each cross-validation fold so the evaluation reflects what happens with unseen data.
Keep a baseline. Train one model with all the features and one with the selected subset, using the same split and the same metric. If the smaller model is not better, there is no reason to pay the cost of the extra columns.
Check the meaning of what survived. A variable that ranks high but cannot exist at prediction time is a leak, not a discovery. Read the list of selected features as a set of decisions about the data collection process, not just as a ranking output.
Finally, write down what was dropped and why. Feature selection is a decision that gets revisited when data changes, and a short record of the reasoning saves time later.
Where does feature selection fit in a Python workflow?
In Python, feature selection sits between data preparation and model training. You load the data, clean it, deal with outliers, and then decide which columns enter the model. Doing it in the wrong order, or before the train-test split, is one of the most common sources of misleading results.
The Python for Data Science and Analytics course follows that path from the beginning: IDE and Jupyter Notebook setup, basic functions, NumPy and Pandas, user-defined functions, loops and conditionals, data visualization, data cleaning and preparation, and outlier detection. The machine learning part covers linear and logistic regression, K-Means, SVM, Naive Bayes, decision tree, Random Forest, Gradient Boosting, XGBoost, LightGBM, feature selection, and cross-validation.
The course closes with an end-to-end final project that combines exploratory analysis and machine learning. It is organized into three main modules — Basic, Intermediate and Advanced — plus bonus modules, with recorded lessons you watch at your own pace, guided exercises, and real market projects to build a portfolio. No prior programming is required to start, access is unlimited with no expiry date, and there is a certificate of completion and an exclusive community for networking. The price is R$ 470, or 12 installments of R$ 20.37 on card, paid through the Hotmart checkout with card or boleto. Full details are on python.paanalytics.net.
| Method family | How it decides | What you get back |
|---|---|---|
| Filter | Scores each variable with a statistic, without training a model | A ranking of individual variables |
| Wrapper | Trains the model repeatedly on different subsets | A subset chosen by measured model performance |
| Embedded | Selects during training, through regularization or tree importance | A trained model plus the variables it relies on |
Method families are standard machine learning categories. The table describes how each family works and does not use vendor or competitor data.
Start from zero and reach end-to-end machine learning
Secure payment via Hotmart, up to 12 installments.
Enroll now Product siteFrequently asked questions
Is feature selection the same as dimensionality reduction?
No. Feature selection keeps a subset of the original columns, so the result stays readable and you can name what stayed and what was dropped. Dimensionality reduction techniques such as principal component analysis create new combined variables and lose that direct reading. Both reduce the size of the input, but only selection preserves the original column meaning.
Do I need to know Python before learning feature selection?
You do not need prior programming experience to start the Python for Data Science and Analytics course, which begins with IDE and Jupyter Notebook setup and basic functions. Feature selection appears later, in the machine learning part, after NumPy, Pandas, data cleaning, and outlier detection. The concept itself is about deciding which columns to keep, so it is worth understanding even before you write the code.
How many features should I keep?
There is no universal number. The right subset depends on how many rows you have, how much signal each variable carries, and how the model will be used and maintained. The practical approach is to compare a model with all features against one with the selected subset, using the same split and the same metric under cross-validation.
Does feature selection work with tree models like XGBoost and LightGBM?
Yes. Tree-based models expose feature importance, so Random Forest, Gradient Boosting, XGBoost, and LightGBM are commonly used to rank columns before you decide what stays. That ranking is an embedded method: the selection happens during training rather than as a separate step. It still needs to be fitted inside the training pipeline, not on the full dataset.
Can I select features before splitting the data?
No. Ranking variables on the full dataset and then splitting lets the test set influence which columns were kept, and the resulting score is optimistic. Fit the selection inside each cross-validation fold so the evaluation reflects performance on data the model has not seen.