Script to select the best subset of variables based on genetic algorithm in R
Branch: master
Clone or download
Latest commit 354c266 Jan 21, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information. update readme Jan 21, 2019
data_breast_cancer2.csv init commit Jan 10, 2019
lib_ga.R init commit Jan 10, 2019
var_sel_gen_alg.R fix elitism Jan 18, 2019

Feature Selection using Genetic Algorithms in R

This script select the 'best' subset of variables based on genetic algorithms in R.

It uses a custom fitness function for binary-class classification. Please modify it to use in other scenarios.

This sctipt is realated to the blog post: Feature Selection using Genetic Algorithms in R.

How to run the example?

The code is ready to calculate the best subset for a cancer dataset (data_breast_cancer2.csv), included in the repo. This is in var_sel_gen_alg.R.

The initial data preparation removes the NA, and it converts the target variable (data_y) into a factor in order to create the predictive model. Both are conditions for the Random Forest that is built behind, using caret package.

You can find how the predictive model is created in the function get_roc_metric, inside the lib_ga.R file. And it is, as the name suggests, prepared for a binary classification problem.

My suggestion before applying with your data is, use the function get_roc_metric directly with your current dataset, and see if it ends ok. If so, proceed to apply the GA procedure.

My idea was to encapsulate the fitness function so you can adjust it better for your purposes. For example, if you want to return Kappa statistic (multi-class target), or RMSE (regression-target). You have to replace get_roc_metric function.


Feel free to share your insights, have fun!