Press "Enter" to skip to content

How to Use Feature Extraction on Tabular Data for Machine Learning


Machine learning predictive modeling performance is only as good as your data, and your data is only as good as the way you prepare it for modeling.

The most common approach to data preparation is to study a dataset and review the expectations of a machine learning algorithm, then carefully choose the most appropriate data preparation techniques to transform the raw data to best meet the expectations of the algorithm. This is slow, expensive, and requires a vast amount of expertise.

An alternative approach to data preparation is to apply a suite of common and commonly useful data preparation techniques to the raw data in parallel and combine the results of all of the transforms together into a single large dataset from which a model can be fit and evaluated.

This is an alternative philosophy for data preparation that treats data transforms as an approach to extract salient features from raw data to expose the structure of the problem to the learning algorithms. It requires learning algorithms that are scalable of weight input features and using those input features that are most relevant to the target that is being predicted.

This approach requires less expertise, is computationally effective compared to a full grid search of data preparation methods, and can aid in the discovery of unintuitive data preparation solutions that achieve good or best performance for a given predictive modeling problem.

In this tutorial, you will discover how to use feature extraction for data preparation with tabular data.

After completing this tutorial, you will know:

  • Feature extraction provides an alternate approach to data preparation for tabular data, where all data transforms are applied in parallel to raw input data and combined together to create one large dataset.
  • How to use the feature extraction method for data preparation to improve model performance over a baseline for a standard classification dataset.
  • How to add feature selection to the feature extraction modeling pipeline to give a further lift in modeling performance on a standard dataset.

Discover data cleaning, feature selection, data transforms, dimensionality reduction and much more in my new book, with 30 step-by-step tutorials and full Python source code.

Let’s get started.

How to Use Feature Extraction on Tabular Data for Data Preparation

How to Use Feature Extraction on Tabular Data for Data Preparation
Photo by Nicolas Valdes, some rights reserved.

Tutorial Overview

This tutorial is divided into three parts; they are:

  1. Feature Extraction Technique for Data Preparation
  2. Dataset and Performance Baseline
    1. Wine Classification Dataset
    2. Baseline Model Performance
  3. Feature Extraction Approach to Data Preparation

Feature Extraction Technique for Data Preparation

Data preparation can be challenging.

The approach that is most often prescribed and followed is to analyze the dataset, review the requirements of the algorithms, and transform the raw data to best meet the expectations of the algorithms.

This can be effective, but is also slow and can require deep expertise both with data analysis and machine learning algorithms.

An alternative approach is to treat the preparation of input variables as a hyperparameter of the modeling pipeline and to tune it along with the choice of algorithm and algorithm configuration.

This too can be an effective approach exposing unintuitive solutions and requiring very little expertise, although it can be computationally expensive.

An approach that seeks a middle ground between these two approaches to data preparation is to treat the transformation of input data as a feature engineering or feature extraction procedure. This involves applying a suite of common or commonly useful data preparation techniques to the raw data, then aggregating all features together to create one large dataset, then fit and evaluate a model on this data.

The philosophy of the approach treats each data preparation technique as a transform that extracts salient features from raw data to be presented to the learning algorithm. Ideally, such transforms untangle complex relationships and compound input variables, in turn allowing the use of simpler modeling algorithms, such as linear machine learning techniques.

For lack of a better name, we will refer to this as the “Feature Engineering Method” or the “Feature Extraction Method” for configuring data preparation for a predictive modeling project.

It allows data analysis and algorithm expertise to be used in the selection of data preparation methods and allows unintuitive solutions to be found but at a much lower computational cost.

The exclusion in the number of input features can also be explicitly addressed through the use of feature selection techniques that attempt to rank order the importance or value of the vast number of extracted features and only select a small subset of the most relevant to predicting the target variable.

We can explore this approach to data preparation with a worked example.

Before we dive into a worked example, let’s first select a standard dataset and develop a baseline in performance.

Want to Get Started With Data Preparation?

Take my free 7-day email crash course now (with sample code).

Click to sign-up and also get a free PDF Ebook version of the course.

Download Your FREE Mini-Course

Dataset and Performance Baseline

In this section, we will first select a standard machine learning dataset and establish a baseline in performance on this dataset. This will provide the context for exploring the feature extraction method of data preparation in the next section.

Wine Classification Dataset

We will use the wine classification dataset.

This dataset has 13 input variables that describe the chemical composition of samples of wine and requires that the wine be classified as one of three types.

You can learn more about the dataset here:

No need to download the dataset as we will download it automatically as part of our worked examples.

Open the dataset and review the raw data. The first few rows of data are listed below.

We can see that it is a multi-class classification predictive modeling problem with numerical input variables, each of which has different scales.

The example loads the dataset and splits it into the input and output columns, then summarizes the data arrays.

Running the example, we can see that the dataset was loaded correctly and that there are 179 rows of data with 13 input variables and a single target variable.

Next, let’s evaluate a model on this dataset and establish a baseline in performance.

Baseline Model Performance

We can establish a baseline in performance on the wine classification task by evaluating a model on the raw input data.

In this case, we will evaluate a logistic regression model.

First, we can perform minimum data preparation by ensuring the input variables are numeric and that the target variable is label encoded, as expected by the scikit-learn library.

Next, we can define our predictive model.

We will evaluate the model using the gold standard of repeated stratified k-fold cross-validation with 10 folds and three repeats.

Model performance will be evaluated using classification accuracy.

At the end of the run, we will report the mean and standard deviation of the accuracy scores collected across all repeats and evaluation folds.

Tying this together, the complete example of evaluating a logistic regression model on the raw wine classification dataset is listed below.

Running the example evaluates the model performance and reports the mean and standard deviation classification accuracy.

Your results may vary given the stochastic nature of the learning algorithm, the evaluation procedure, and differences in precision across machines. Try running the example a few times.

In this case, we can see that the logistic regression model fit on the raw input data achieved the average classification accuracy of about 95.3 percent, providing a baseline in performance.

Next, let’s explore whether we can improve the performance using the feature extraction based approach to data preparation.

Feature Extraction Approach to Data Preparation

In this section, we can explore whether we can improve performance using the feature extraction approach to data preparation.

The first step is to select a suite of common and commonly useful data preparation techniques.

In this case, given that the input variables are numeric, we will use a range of transforms to change the scale of the input variables such as MinMaxScaler, StandardScaler, and RobustScaler, as well as transforms for chaining the distribution of the input variables such as QuantileTransformer and KBinsDiscretizer. Finally, we will also use transforms that remove linear dependencies between the input variables such as PCA and TruncatedSVD.

The FeatureUnion class can be used to define a list of transforms to perform, the results of which will be aggregated together, i.e. unioned. This will create a new dataset that has a vast number of columns.

An estimate of the number of columns would be 13 input variables times five transforms or 65 plus the 14 columns output from the PCA and SVD dimensionality reduction methods, to give a total of about 79 features.

We can then create a modeling Pipeline with the FeatureUnion as the first step and the logistic regression model as the final step.

The pipeline can then be evaluated using repeated stratified k-fold cross-validation as before.

Tying this together, the complete example is listed below.

Running the example evaluates the model performance and reports the mean and standard deviation classification accuracy.

Your results may vary given the stochastic nature of the learning algorithm, the evaluation procedure, and differences in precision across machines. Try running the example a few times.

In this case, we can see a lift in performance over the baseline performance, achieving a mean classification accuracy of about 96.8 percent as compared to 95.3 percent in the previous section.

Try adding more data preparation methods to the FeatureUnion to see if you can improve the performance.

Can you get better results?
Let me know what you discover in the comments below.

We can also use feature selection to reduce the approximately 80 extracted features down to a subset of those that are most relevant to the model. In addition to reducing the complexity of the model, it can also result in a lift in performance by removing irrelevant and redundant input features.

In this case, we will use the Recursive Feature Elimination, or RFE, technique for feature selection and configure it to select the 15 most relevant features.

We can then add the RFE feature selection to the modeling pipeline after the FeatureUnion and before the LogisticRegression algorithm.

Tying this together, the complete example of the feature selection data preparation method with feature selection is listed below.

Running the example evaluates the model performance and reports the mean and standard deviation classification accuracy.

Your results may vary given the stochastic nature of the learning algorithm, the evaluation procedure, and differences in precision across machines. Try running the example a few times.

Again, we can see a further lift in performance from 96.8 percent with all extracted features to about 98.9 with feature selection used prior to modeling.

Can you achieve better performance with a different feature selection technique or with more or fewer selected features?
Let me know what you discover in the comments below.

Further Reading

This section provides more resources on the topic if you are looking to go deeper.

Related Tutorials

Books

APIs

Summary

In this tutorial, you discovered how to use feature extraction for data preparation with tabular data.

Specifically, you learned:

  • Feature extraction provides an alternate approach to data preparation for tabular data, where all data transforms are applied in parallel to raw input data and combined together to create one large dataset.
  • How to use the feature extraction method for data preparation to improve model performance over a baseline for a standard classification dataset.
  • How to add feature selection to the feature extraction modeling pipeline to give a further lift in modeling performance on a standard dataset.

Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.

Get a Handle on Modern Data Preparation!

Data Preparation for Machine Learning

Prepare Your Machine Learning Data in Minutes

…with just a few lines of python code

Discover how in my new Ebook:
Data Preparation for Machine Learning

It provides self-study tutorials with full working code on:
Feature Selection, RFE, Data Cleaning, Data Transforms, Scaling, Dimensionality Reduction, and much more…

Bring Modern Data Preparation Techniques to
Your Machine Learning Projects

See What’s Inside


17 Comments

  1. Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.

  2. SMS July 6, 2020

    Your site is very helpful. Many thanks for sharing!

  3. Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.

  4. SMS July 6, 2020

    I used to be able to find good info from your blog posts.

  5. converse July 12, 2020

    I must show my appreciation for your generosity supporting visitors who should have assistance with this content. Your special commitment to getting the message all-around was remarkably invaluable and has really allowed those just like me to realize their pursuits. Your warm and friendly help and advice indicates so much a person like me and still more to my peers. Thank you; from each one of us.

  6. yeezy 700 July 15, 2020

    I simply wanted to jot down a small remark in order to appreciate you for all of the pleasant concepts you are writing at this site. My long internet investigation has finally been recognized with high-quality details to exchange with my colleagues. I ‘d declare that many of us site visitors actually are undoubtedly lucky to live in a notable network with so many lovely professionals with useful principles. I feel truly blessed to have encountered the webpages and look forward to tons of more excellent moments reading here. Thanks a lot again for everything.

  7. curry 6 shoes July 22, 2020

    Thank you for your entire labor on this blog. My aunt take interest in setting aside time for research and it is simple to grasp why. A lot of people notice all about the dynamic form you present precious guidelines via your web site and even welcome participation from other people on this content plus our own girl is really starting to learn so much. Enjoy the remaining portion of the year. You’re doing a dazzling job.

  8. hermes birkin July 28, 2020

    My husband and i felt so comfortable when Albert managed to round up his researching using the precious recommendations he grabbed out of the web site. It is now and again perplexing just to happen to be giving away tips some people may have been selling. Therefore we grasp we have the blog owner to appreciate for this. The illustrations you have made, the easy website navigation, the relationships you assist to foster – it is all astounding, and it’s letting our son in addition to the family imagine that the concept is enjoyable, which is certainly pretty indispensable. Thank you for all the pieces!

  9. off white jordan 1 July 30, 2020

    I must express my thanks to the writer for rescuing me from this trouble. After looking out throughout the the web and coming across suggestions that were not productive, I was thinking my entire life was done. Existing without the presence of answers to the problems you’ve fixed as a result of your report is a critical case, and ones that could have negatively affected my career if I hadn’t encountered your website. The ability and kindness in dealing with all areas was invaluable. I don’t know what I would have done if I hadn’t discovered such a thing like this. I can at this point relish my future. Thanks so much for the high quality and sensible help. I will not be reluctant to recommend your blog to anybody who needs support on this subject.

  10. kd 10 August 3, 2020

    I simply had to say thanks once more. I do not know what I might have created without those creative ideas documented by you regarding my problem. It had been a real terrifying crisis in my opinion, however , being able to see this skilled manner you treated the issue made me to weep for fulfillment. I will be thankful for the assistance and then hope that you realize what a great job you have been putting in educating some other people via a site. I am sure you haven’t come across all of us.

  11. off white nike August 5, 2020

    Thanks so much for providing individuals with such a brilliant opportunity to check tips from this web site. It’s always very enjoyable and packed with a great time for me personally and my office co-workers to visit the blog minimum thrice weekly to read through the newest guidance you will have. Not to mention, we’re actually contented with all the splendid concepts you serve. Certain 4 areas on this page are ultimately the most effective I’ve had.

Leave a Reply

Your email address will not be published.