Recursive Feature Elimination Last Updated : 29 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report RFE works by iteratively eliminating the least relevant features according to a model's performance, finally choosing the most informative subset. This method is model-agnostic and can be applied to linear models, support vector machines, decision trees, and so on.Recursive Feature Elimination (RFE) is a greedy optimization technique applied to decrease the number of input features by repeatedly fitting a model and eliminating the weakest feature(s) until the specified number of features is obtained.Process Overview:Train a model on the full set of features.Rank features based on importance (e.g., weights, coefficients).Remove the least important feature(s).Repeat the process on the reduced feature set.The final output is a ranking of features and the subset that provides the best predictive performance.Why Use RFE?RFE is especially helpful when:The dataset contains a large number of features.You suspect many features are redundant or irrelevant.You want to improve training speed and model generalization.RFE can improve model performance by:Eliminating noisy or uninformative features.Reducing variance in predictions.Making models easier to interpret.Implementation Using scikit-learnRFE Initialization: RFE() takes Logistic Regression as the model and n_features_to_select= 2, which means we are to retain the first 2 highest-importance features.Feature Selection: RFE recursively orders features by importance and drops the smallest-importance feature until 2 features are left.Model Training: The model is trained with the selected features (X_train_rfe) and tested against the test set (X_test_rfe).Performance Evaluation: The accuracy of the model is computed after the feature selection process. Python from sklearn.datasets import load_breast_cancer from sklearn.linear_model import LogisticRegression from sklearn.feature_selection import RFE from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score data = load_breast_cancer() X, y = data.data, data.target # Split dataset X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) # Define the base model model = LogisticRegression(max_iter=5000) # Apply RFE rfe = RFE(estimator=model, n_features_to_select=10) rfe.fit(X_train, y_train) # Predict and evaluate y_pred = rfe.predict(X_test) print("Selected features:", rfe.support_) print("Test Accuracy:", accuracy_score(y_test, y_pred)) Output: Applications of RFERFE is widely used in various domains:Healthcare: To identify the most relevant biomarkers or clinical variables.Finance: To reduce dimensionality in stock price prediction or credit scoring.Text classification: To select the most important n-grams or TF-IDF terms.Computer vision: To select discriminative image features in object recognition.Limitations and ConsiderationsWhile RFE is powerful, it has some limitations:Computational Cost: It can be slow on very large datasets or when using complex models.Dependency on the base model: Feature rankings depend heavily on the model used.Risk of overfitting: If not cross-validated properly, it can overfit during feature selection.Best PracticesUse cross-validation in conjunction with RFE (e.g., RFECV in scikit-learn).Choose a simple, interpretable base model for faster and more transparent feature selection.Standardize or normalize your data before applying RFE, especially with linear models.Related ArticlesRecursive Feature Elimination with Cross-Validation in Scikit LearnPerforming Feature Selection with gridsearchcv in SklearnHow can Feature Selection reduce overfitting?SVM Feature Selection in R with ExampleJoint Feature Selection with multi-task Lasso in Scikit Learn Comment More infoAdvertise with us Next Article Recursive Feature Elimination V Vandita Gupta Improve Article Tags : Machine Learning AI-ML-DS Practice Tags : Machine Learning Similar Reads Machine Learning Tutorial Machine learning is a branch of Artificial Intelligence that focuses on developing models and algorithms that let computers learn from data without being explicitly programmed for every task. In simple words, ML teaches the systems to think and understand like humans by learning from the data.Machin 5 min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Linear Regression in Machine learning Linear regression is a type of supervised machine-learning algorithm that learns from the labelled datasets and maps the data points with most optimized linear functions which can be used for prediction on new datasets. It assumes that there is a linear relationship between the input and output, mea 15+ min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Support Vector Machine (SVM) Algorithm Support Vector Machine (SVM) is a supervised machine learning algorithm used for classification and regression tasks. It tries to find the best boundary known as hyperplane that separates different classes in the data. It is useful when you want to do binary classification like spam vs. not spam or 9 min read Logistic Regression in Machine Learning Logistic Regression is a supervised machine learning algorithm used for classification problems. Unlike linear regression which predicts continuous values it predicts the probability that an input belongs to a specific class. It is used for binary classification where the output can be one of two po 11 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read 100+ Machine Learning Projects with Source Code [2025] This article provides over 100 Machine Learning projects and ideas to provide hands-on experience for both beginners and professionals. Whether you're a student enhancing your resume or a professional advancing your career these projects offer practical insights into the world of Machine Learning an 5 min read K means Clustering â Introduction K-Means Clustering is an Unsupervised Machine Learning algorithm which groups unlabeled dataset into different clusters. It is used to organize data into groups based on their similarity. Understanding K-means ClusteringFor example online store uses K-Means to group customers based on purchase frequ 4 min read K-Nearest Neighbor(KNN) Algorithm K-Nearest Neighbors (KNN) is a supervised machine learning algorithm generally used for classification but can also be used for regression tasks. It works by finding the "k" closest data points (neighbors) to a given input and makesa predictions based on the majority class (for classification) or th 8 min read Like