How to do recursive feature elimination in Python?

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

In [1]:
## How to do recursive feature elimination in Python
def Snippet_128():
    print(format('How to do recursive feature elimination in Python','*^82'))

    import warnings

    # 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,

    # Fit recursive feature eliminator, y)

    # Recursive feature elimination

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

****************How to do recursive feature elimination in Python*****************

(10000, 100)

   estimator=LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,
   min_features_to_select=1, n_jobs=4, scoring='neg_mean_squared_error',
   step=1, verbose=0)


Relevant Projects

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

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.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

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.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

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.