How to do recursive feature elimination in Python?
FEATURE EXTRACTION

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
In [1]:
## How to do recursive feature elimination in Python
def Snippet_128():
    print()
    print(format('How to do recursive feature elimination in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    from sklearn.datasets import make_regression
    from sklearn.feature_selection import RFECV
    from sklearn import linear_model

    # Create Data
    # Generate features matrix, target vector, and the true coefficients
    X, y = make_regression(n_samples = 10000, n_features = 100, n_informative = 2)
    print(); print(X.shape)

    # Create Linear Model
    ols = linear_model.LinearRegression()

    # Create recursive feature eliminator that scores features by mean squared errors
    rfecv = RFECV(estimator=ols, step=1, scoring='neg_mean_squared_error', cv=4, verbose=0,
                  n_jobs=4)

    # Fit recursive feature eliminator 
    rfecv.fit(X, y)

    # Recursive feature elimination
    rfecv.transform(X)

    # Number of best features
    print(); print(rfecv)
    print(); print(rfecv.n_features_)

Snippet_128()
****************How to do recursive feature elimination in Python*****************

(10000, 100)

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)

4

Relevant Projects

Anomaly Detection Using Deep Learning and Autoencoders
Deep Learning Project- Learn about implementation of a machine learning algorithm using autoencoders for anomaly detection.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

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

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

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.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.