All Projects → kaushalshetty → Featureselectionga

kaushalshetty / Featureselectionga

Licence: mit
Feature Selection using Genetic Algorithm (DEAP Framework)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Featureselectionga

Metaheuristics
Implement the-state-of-the-art meta-heuristic algorithms using python (numpy)
Stars: ✭ 95 (-36.67%)
Mutual labels:  genetic-algorithm
Cephalopods
Evolving squids through neuroevolution
Stars: ✭ 122 (-18.67%)
Mutual labels:  genetic-algorithm
Evolutionary.jl
Evolutionary & genetic algorithms for Julia
Stars: ✭ 142 (-5.33%)
Mutual labels:  genetic-algorithm
Openclga
A Python Library for Genetic Algorithm on OpenCL
Stars: ✭ 103 (-31.33%)
Mutual labels:  genetic-algorithm
Neat Genetic Mario
Update of Seth Bling's MarI/O
Stars: ✭ 112 (-25.33%)
Mutual labels:  genetic-algorithm
Machine Learning Flappy Bird
Machine Learning for Flappy Bird using Neural Network and Genetic Algorithm
Stars: ✭ 1,683 (+1022%)
Mutual labels:  genetic-algorithm
Time Table Scheduler
Time Table generation using Genetic Algorithms ( Java-Struts2)
Stars: ✭ 90 (-40%)
Mutual labels:  genetic-algorithm
Bluepyopt
Blue Brain Python Optimisation Library
Stars: ✭ 143 (-4.67%)
Mutual labels:  genetic-algorithm
Evolving Simple Organisms
Evolving simple organisms using a genetic algorithm and deep learning from scratch with python
Stars: ✭ 117 (-22%)
Mutual labels:  genetic-algorithm
Ai plays snake
AI trained using Genetic Algorithm and Deep Learning to play the game of snake
Stars: ✭ 137 (-8.67%)
Mutual labels:  genetic-algorithm
Oxigen
Fast, parallel, extensible and adaptable genetic algorithms framework written in Rust
Stars: ✭ 108 (-28%)
Mutual labels:  genetic-algorithm
Genetic Algorithm
Generic implementation of genetic algorithm in Java.
Stars: ✭ 112 (-25.33%)
Mutual labels:  genetic-algorithm
Bot Evolution
An interesting display of evolution through neural networks and a genetic algorithm
Stars: ✭ 135 (-10%)
Mutual labels:  genetic-algorithm
Genetic Programming
Symbolic regression solver, based on genetic programming methodology.
Stars: ✭ 98 (-34.67%)
Mutual labels:  genetic-algorithm
Evolutionsimulator
Evolution Simulator with Box2D
Stars: ✭ 143 (-4.67%)
Mutual labels:  genetic-algorithm
Evoasm.rb
An AIMGP (Automatic Induction of Machine code by Genetic Programming) engine
Stars: ✭ 91 (-39.33%)
Mutual labels:  genetic-algorithm
Pytsp
A 2D/3D visualization of the Traveling Salesman Problem main heuristics
Stars: ✭ 122 (-18.67%)
Mutual labels:  genetic-algorithm
Fantasy Basketball
Scraping statistics, predicting NBA player performance with neural networks and boosting algorithms, and optimising lineups for Draft Kings with genetic algorithm. Capstone Project for Machine Learning Engineer Nanodegree by Udacity.
Stars: ✭ 146 (-2.67%)
Mutual labels:  genetic-algorithm
Mlkit
A simple machine learning framework written in Swift 🤖
Stars: ✭ 144 (-4%)
Mutual labels:  genetic-algorithm
Genetic Algorithm
遗传算法 - Matlab
Stars: ✭ 136 (-9.33%)
Mutual labels:  genetic-algorithm

FeatureSelectionGA

Feature Selection using Genetic Algorithm (DEAP Framework)

Data scientists find it really difficult to choose the right features to get maximum accuracy especially if you are dealing with a lot of features. There are currenlty lots of ways to select the right features. But we will have to struggle if the feature space is really big. Genetic algorithm is one solution which searches for one of the best feature set from other features in order to attain a high accuracy.

Installation:

$ pip install feature-selection-ga

Documentation:

https://featureselectionga.readthedocs.io/en/latest/

Usage:

from sklearn.datasets import make_classification
from sklearn import linear_model
from feature_selection_ga import FeatureSelectionGA, FitnessFunction

X, y = make_classification(n_samples=100, n_features=15, n_classes=3,
                           n_informative=4, n_redundant=1, n_repeated=2,
                           random_state=1)

model = linear_model.LogisticRegression(solver='lbfgs', multi_class='auto')
fsga = FeatureSelectionGA(model,X,y, ff_obj = FitnessFunction())
pop = fsga.generate(100)

#print(pop)

Usage (Advanced):

By default, the FeatureSelectionGA has its own fitness function class. We can also define our own FitnessFunction class.

class FitnessFunction:
    def __init__(self,n_splits = 5,*args,**kwargs):
        """
            Parameters
            -----------
            n_splits :int,
                Number of splits for cv

            verbose: 0 or 1
        """
        self.n_splits = n_splits

    def calculate_fitness(self,model,x,y):
        pass

With this, we can design our own fitness function by defining our calculate fitness! Consider the following example from Vieira, Mendoca, Sousa, et al. (2013) $f(X) = \alpha(1-P) + (1-\alpha) \left(1 - \dfrac{N_f}{N_t}\right)$

Define the constructor init with needed parameters: alpha and N_t.

class FitnessFunction:
    def __init__(self,n_total_features,n_splits = 5, alpha=0.01, *args,**kwargs):
        """
            Parameters
            -----------
            n_total_features :int
            	Total number of features N_t.
            n_splits :int, default = 5
                Number of splits for cv
            alpha :float, default = 0.01
                Tradeoff between the classifier performance P and size of
                feature subset N_f with respect to the total number of features
                N_t.

            verbose: 0 or 1
        """
        self.n_splits = n_splits
        self.alpha = alpha
        self.n_total_features = n_total_features

Next, we define the fitness function, the name has to be calculate_fitness:

    def calculate_fitness(self,model,x,y):
        alpha = self.alpha
        total_features = self.n_total_features

        cv_set = np.repeat(-1.,x.shape[0])
        skf = StratifiedKFold(n_splits = self.n_splits)
        for train_index,test_index in skf.split(x,y):
            x_train,x_test = x[train_index],x[test_index]
            y_train,y_test = y[train_index],y[test_index]
            if x_train.shape[0] != y_train.shape[0]:
                raise Exception()
            model.fit(x_train,y_train)
            predicted_y = model.predict(x_test)
            cv_set[test_index] = predicted_y

        P = accuracy_score(y, cv_set)
        fitness = (alpha*(1.0 - P) + (1.0 - alpha)*(1.0 - (x.shape[1])/total_features))
        return fitness

Example: You may also see example2.py

X, y = make_classification(n_samples=100, n_features=15, n_classes=3,
n_informative=4, n_redundant=1, n_repeated=2,
random_state=1)

# Define the model

model = linear_model.LogisticRegression(solver='lbfgs', multi_class='auto')

# Define the fitness function object

ff = FitnessFunction(n_total_features= X.shape[1], n_splits=3, alpha=0.05)
fsga = FeatureSelectionGA(model,X,y, ff_obj = ff)
pop = fsga.generate(100)

Example adopted from pyswarms

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].