How to do recursive feature elimination in Python?
FEATURE EXTRACTION DATA CLEANING PYTHON DATA MUNGING MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to do recursive feature elimination in Python?

How to do recursive feature elimination in Python?

This recipe helps you do recursive feature elimination in Python

0

Recipe Objective

To increse the score of the model we need to remove the features which are recursive. Removing recursive feature reduces the computational cost and increase the efficiency.

So this is the recipe on How we can do recursive feature elimination in Python.

Step 1 - Import the library

from sklearn.datasets import make_regression from sklearn.feature_selection import RFECV from sklearn import linear_model

We have only imported datasets to import the datasets, RFECV and liner_model.

Step 2 - Setting up the Data

We have imported inbuilt boston dataset and stored data in X and target in y. We have also used print statement to print rows of the dataset. dataset = datasets.load_boston() X = dataset.data y = dataset.target

Step 3 - Selecting recursive Features

We have used linear Regression as a model and RFECV is used for recursive feature elimination we have used negative mean squared error as a scoring with cross validation as 4. We have fit and transform rfecv. ols = linear_model.LinearRegression() rfecv = RFECV(estimator=ols, step=1, scoring="neg_mean_squared_error", cv=4, verbose=0, n_jobs=4) rfecv.fit(X, y) rfecv.transform(X) print(rfecv) print(rfecv.n_features_) So the output comes as

RFECV(cv=4,
   estimator=LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,
         normalize=False),
   min_features_to_select=1, n_jobs=4, scoring="neg_mean_squared_error",
   step=1, verbose=0)

6

Relevant Projects

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.