Features Selection by using Voting Approach

How to apply a variety of techniques to select features with Xverse package.

Davis David
Analytics Vidhya
5 min readFeb 12, 2020

--

Feature Selection is the process where you automatically or manually select those features which contribute most to your prediction variable or output in which you are interested.
One major reason is that machine learning follows the rule of “garbage in garbage out” and that is why you need to be very concerned about the features that are being fed to the model.

Having irrelevant features in your data can both increase the computational cost of modeling and decrease the accuracy of the models and make your model learn based on irrelevant features. This means you need to select only important features to be presented during model training.

Top reasons to apply feature selection are:

  • It enables the machine learning algorithm to train faster.
  • It reduces the complexity of a model and makes it easier to interpret.
  • It improves the accuracy of a model if the right subset is chosen.
  • It reduces overfitting.

“I prepared a model by selecting all the features and I got an accuracy of around 65% which is not pretty good for a predictive model and after doing some feature selection and feature engineering without doing any logical changes in my model code my accuracy jumped to 81% which is quite impressive”- By Raheel Shaikh

Feature selection methods are intended to reduce the number of features to those that are believed to be most useful/important to a model in order to predict the target feature. There are different feature selection methods available that can help you to select important features. The most popular methods are.

You can read more about feature selection methods from Scikit learn library.

One of the challenges of these methods is to identify which method(s) should you apply in your dataset to select important features. Each method has its own way to identify the important features. For example, a certain feature can be selected as an important feature in one method and not selected as an important feature in another method.

Xverse package can help you to solve this problem.

“At the end of the day, some machine learning projects succeed and some fail.What makes the difference? Easily the most important factor is the features used.” — Pedro Domingos

What is Xverse?

Xverse stands for X Universe which is the python package for machine learning to assist Data Scientists with feature transformation and feature selection. Xverse is created by Sundar Krishnan.

How does it work?

Xverse applies a variety of techniques to select features. When an algorithm picks a feature, it gives a vote for that feature. In the end, Xverse calculates the total votes for each feature and then pick the best ones based on votes. This way, we end up picking the best variables with minimum effort in the features selection process.

Xverse uses the following methods to select important features.

  • Information Value using Weight of evidence.
  • Variable Importance using Random Forest.
  • Recursive Feature Elimination.
  • Variable Importance using Extra trees classifier.
  • Chi-Square best variables.
  • L1 based feature selection.

Installation

The package requires numpy, pandas, scikit-learn, scipy and statsmodels. In addition, the package is tested on Python version 3.5 and above.

Run the following command to install Xverse.

I will use the Loan dataset to find the best features that can help to get good accuracy when predicting if a customer deserves to get a loan or not.You can download the dataset here.

Import important packages for this problem.

Load the Loan dataset.

We have 12 independent features and a target (Loan_Status). You can read the description of each feature here.

Features Definition

I have created a simple python function to handle missing data and feature engineering.

Let’s preprocess the loan dataset.

Split into independent features and target.

Now is time to call VotingSelector from Xverse and train it to find the best features by using the voting approach.

I have set minimum_votes= 2, this means feature to be selected must have at least a total of 2 votes from the six feature selection methods presented in Xverse. Features below a total of 2 votes will be neglected.

After training, we can see the feature importance in each feature selection method used during the training.

The output shows all the features and their values of importance in each method.

Now let’s observe the votes from these feature selection methods.

The output shows the variable name, list of feature selection methods and their votes and at last, it shows total votes for each feature.
It starts by show features with many votes to the features with low or zero votes.

You can see that Credit_History has a total of 6 votes, which means credit_History is a very important feature for this Loan problem. But both Gender and Self_employed features have 0 votes, which means we can neglect these two features because of the very low contribution to the prediction if a customer deserves to get a loan or not.

Now we can transform our data to remain with only important selected features.

Conclusion

Xverse is under active development. Currently, xverse package handles only binary target.

The code for this post is available on Github.

If you learned something new or enjoyed reading this article, please share it so that others can see it. Feel free to leave a comment too. Till then, see you in the next post! I can also be reached on Twitter @Davis_McDavid

--

--

Davis David
Analytics Vidhya

Data Scientist 📊 | Software Developer | Technical Writer 📝 | ML Course Author 👨🏽‍💻 | Giving talks. Check my new ML course: https://bit.ly/OptimizeMLModels