![]() |
VOOZH | about |
In machine learning, having too many features (also called variables or columns) can lead to complex models that are hard to understand and may not perform well. Feature selection helps us choose only the most important features, making models faster, simpler, and often more accurate.
There are three main types of feature selection methods:
Embedded methods combine the best parts of filter and wrapper methods. They choose important features as the model is being trained. This makes them faster than wrapper methods and often more accurate than filter methods.
These methods are usually part of the learning algorithm itself. Examples include decision trees, regularization methods like Lasso, and some types of linear models.
Let’s look at the most popular embedded methods used in machine learning.
Lasso stands for Least Absolute Shrinkage and Selection Operator. It is a type of linear regression that uses L1 regularization, which can shrink some feature weights to zero. When a feature’s weight becomes zero, the model ignores it.
Where:
When is high, more weights become zero.
Lasso, the California housing dataset, and utilities for splitting data and handling DataFrames. X contains features like house age, income, etc. y is the median house value.train_test_split.alpha=0.1 is trained on the data. Lasso automatically reduces coefficients of less important features to zero.Output
Useful when there are many correlated features.
Tree-based models like Decision Trees, Random Forests, and Gradient Boosting automatically rank features by importance.
Just like Lasso works for linear regression, it also works for classification using logistic regression.
Used for binary classification with automatic feature selection.
SVMs can also be used with L1 regularization to remove irrelevant features. This is called L1-SVM. It's more advanced but helpful when features are many and irrelevant ones need to be removed.