Example #1
0
    def run(self, generation):
        runned_generation = list()
        data_reader = DataReader.getInstance()
        X, Y, X_test, X_output = data_reader.read_data()

        #for each gene of this generation
        for i in range(0, len(generation)):

            this_gene = generation[i]
            # runner is which algorithm will I use:
            # 0 is XGBoost Classifier
            # 1 is XGBoost regressor
            # 2 is SVC
            # 3 is DecisionTreeClassifier
            # 4 is AdaBoost applied to DecisionTreeClassifier
            # 5 is GradientBoosting
            # 6 is KNeighbors
            # 7 is RandomForest
            # 8 is RandomForest but simplified (more defaults and less configuration)
            runner = None
            if (this_gene.way == 0):
                runner = TitanicBoostClassifier()
            else:
                if (this_gene.way == 1):
                    runner = TitanicBoostRegressor()
                else:
                    runner = VariousForests()

            runner.set_datasets(X, Y, X_test, X_output)
            runner.set_gene_to_model(this_gene)  #here we configure the model
            this_gene.set_fitness_level(runner.run())
            runned_generation.append(this_gene)

        return runned_generation
Example #2
0
https://www.kaggle.com/c/titanic

'''
if __name__ == "__main__":

    ## the application is quite fast, because the Db is small.. so in a normal laptop we can run with
    ## 15-20 generations and a population of 60-100..
    population = 80
    n_generations = 15

    # this class can create randome genes in order to initialize the genetic algoritgm
    creator = GeneCreator()

    # method to implement the genetic algorithm itself
    breeder = Breeder()
    data_reader = DataReader.getInstance()
    X, Y, X_test, X_output = data_reader.read_data()

    #print( X.head() )

    #try regressors
    print("\n\n\n########################## BEGIN! ##########################")
    generation = breeder.get_first_generation(population)
    generation = breeder.run(generation)

    for i in range(0, n_generations):
        print("\n\n\n########################## GENERATION: " + str(i) +
              " ##########################")
        generation = breeder.get_new_generation(generation, population)
        generation = breeder.run(generation)
        #print( "gen lenght: " + str(len(generation)) )