项目作者: mgraffg

项目描述 :
Evolving Directed Acyclic Graph
高级语言: Python
项目地址: git://github.com/mgraffg/EvoDAG.git
创建时间: 2015-12-08T02:37:29Z
项目社区:https://github.com/mgraffg/EvoDAG

开源协议:Apache License 2.0

下载


Tests
Coverage Status
PyPI version
azure
Conda Version
Conda Platforms

EvoDAG

Evolving Directed Acyclic Graph (EvoDAG) is a steady-state Genetic Programming system
with tournament selection. The main characteristic of EvoDAG is that
the genetic operation is performed at the root. EvoDAG was inspired
by the geometric semantic crossover proposed by
Alberto Moraglio
et al. and the implementation performed by
Leonardo Vanneschi
et al.

EvoDAG is described in the following conference paper
EvoDAG: A semantic Genetic Programming Python library
Mario Graff, Eric S. Tellez, Sabino Miranda-Jiménez, Hugo Jair Escalante.
2016 IEEE International Autumn Meeting on Power, Electronics and Computing (ROPEC)
pp 1-6. A pre-print version can be download from here.

Quick Start

There are two options to use EvoDAG, one is as a library and the other is using the command line interface.

Using EvoDAG as library

Let us assume that X contains the inputs and y contains the
classes. Then in order to train an ensemble of 30 EvoDAG and predict
X one uses the following instructions:

  1. # Importing EvoDAG ensemble
  2. from EvoDAG.model import EvoDAGE
  3. # Importing iris dataset from sklearn
  4. from sklearn.datasets import load_iris
  5. # Reading data
  6. data = load_iris()
  7. X = data.data
  8. y = data.target
  9. #train the model
  10. m = EvoDAGE(n_estimators=30, n_jobs=4).fit(X, y)
  11. #predict X using the model
  12. hy = m.predict(X)

Using EvoDAG from the command line

Let us assume one wants to create a classifier of iris dataset. The
first step is to download the dataset from the UCI Machine Learning
Repository

  1. curl -O https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data

Training EvoDAG

Let us assume, you do not want to optimise the EvoDAG parameters, so the
default parameters are used when flag -P is not present, i.e.,

  1. EvoDAG-train -C -m model.evodag -n 100 -u 4 iris.data

-C flag indicates that it is a classification problem, and
-R is for regression problems; there are different default parameters
for each type of problems.

The performance of EvoDAG without optimising the parameters is
presented in the last column of the performance table.

Predict

Once the model is obtained, it is time to use it; given that iris.data
was not split into a training and test set, let us assume
that iris.data contains some unknown data.
In order to predict iris.data one would do:

  1. EvoDAG-predict -m model.evodag -o iris.predicted iris.data

where -o indicates the file name used to store the predictions, -m
contains the model, and iris.data is the test set.

Performance

The next table presents the average performance in terms of the
balance error rate (BER) of different classifiers found in
scikit-learn on nine classification
problems (these benchmarks can be found:
matlab and text).
The best performance among each classification dataset is in
bold face to facilitate the reading. EvoDAG is trained using the
commands describe in Quick Start Section.

Classifier Average rank banana thyroid diabetis heart ringnorm twonorm german image waveform
EvoDAG 2.4 12.0 7.7 25.0 16.1 1.5 2.3 28.3 3.6 10.8
SVC 5.3 11.6 8.1 29.8 17.7 1.8 2.7 33.3 8.9 10.7
GaussianNB 5.9 41.6 11.5 28.6 16.3 1.4 2.4 30.6 36.7 12.2
GradientBoosting 6.1 13.8 8.2 28.5 21.1 6.6 5.7 31.1 2.1 13.6
MLP 6.4 18.8 9.3 28.6 18.3 11.0 2.8 32.0 3.4 11.4
NearestCentroid 7.4 46.3 22.5 28.2 16.7 24.1 2.3 27.7 37.1 13.0
AdaBoost 8.3 28.2 8.7 29.3 22.5 7.0 5.4 31.6 3.2 14.6
ExtraTrees 8.7 13.5 6.6 33.0 21.1 8.4 7.8 36.9 2.4 16.5
LinearSVC 8.8 50.0 16.9 28.5 16.8 25.2 3.6 32.4 18.6 14.2
LogisticRegression 9.1 50.0 20.2 28.3 17.0 25.3 2.9 32.1 18.7 13.7
RandomForest 9.1 13.6 7.9 31.9 21.4 9.6 8.9 36.7 2.1 16.9
KNeighbors 9.4 11.9 12.1 32.1 18.6 43.7 3.8 36.2 5.3 13.8
BernoulliNB 11.6 45.5 32.5 31.9 16.6 28.1 5.8 32.8 39.0 14.3
DecisionTree 11.8 15.2 9.3 33.9 27.1 19.2 20.9 36.5 3.4 20.8
SGD 14.0 50.3 17.7 34.0 22.2 32.6 3.9 38.5 25.1 17.6
PassiveAggressive 14.1 49.0 19.5 34.7 23.3 31.5 3.9 38.7 26.2 17.1
Perceptron 14.4 50.2 18.2 34.6 21.6 33.5 3.9 37.5 26.7 19.0

The predictions of EvoDAG were obtained using the following script:

  1. dirname=evodag-`EvoDAG-params --version | awk '{print $2}'`
  2. [ ! -d $dirname ] && mkdir $dirname
  3. echo Haciendo `EvoDAG-params --version`
  4. for train in csv/*train_data*.csv;
  5. do
  6. test=`python -c "import sys; print(sys.argv[1].replace('train', 'test'))" $train`;
  7. output=`basename ${test} .csv`
  8. predict=${dirname}/${output}.predict
  9. model=${dirname}/${output}.model
  10. if [ ! -f $model ]
  11. then
  12. EvoDAG-train -C -u 32 -m $model -t $test $train
  13. fi
  14. if [ ! -f $predict ]
  15. then
  16. EvoDAG-predict -u 32 -m $model -o $predict $test
  17. fi
  18. done

The predictions sklearn classifiers were obtained using the following
code:

  1. from sklearn.linear_model import LogisticRegression, SGDClassifier, Perceptron
  2. from sklearn.linear_model import PassiveAggressiveClassifier
  3. from sklearn.neighbors import KNeighborsClassifier
  4. from sklearn.neighbors.nearest_centroid import NearestCentroid
  5. from sklearn.svm import SVC, LinearSVC
  6. from sklearn.naive_bayes import GaussianNB, BernoulliNB
  7. from sklearn.tree import DecisionTreeClassifier
  8. from sklearn.ensemble import RandomForestClassifier
  9. from sklearn.ensemble import ExtraTreesClassifier
  10. from sklearn.ensemble import AdaBoostClassifier
  11. from sklearn.ensemble import GradientBoostingClassifier
  12. from sklearn.neural_network import MLPClassifier
  13. from glob import glob
  14. import numpy as np
  15. def predict(train, test, alg):
  16. X = np.loadtxt(train, delimiter=',')
  17. Xtrain = X[:, :-1]
  18. ytrain = X[:, -1]
  19. Xtest = np.loadtxt(test, delimiter=',')
  20. m = alg().fit(Xtrain, ytrain)
  21. return m.predict(Xtest)
  22. ALG = [LogisticRegression, SGDClassifier, Perceptron,
  23. PassiveAggressiveClassifier, SVC, LinearSVC, KNeighborsClassifier, NearestCentroid,
  24. GaussianNB, BernoulliNB, DecisionTreeClassifier, RandomForestClassifier,
  25. ExtraTreesClassifier, AdaBoostClassifier, GradientBoostingClassifier, MLPClassifier]
  26. for dataset in ['banana', 'thyroid', 'diabetis', 'heart',
  27. 'ringnorm', 'twonorm', 'german', 'image',
  28. 'waveform']:
  29. for train in glob('csv/%s_train_data*.csv' % dataset):
  30. test = train.replace('_train_', '_test_')
  31. hy_alg = [predict(train, test, alg) for alg in ALG]

Citing EvoDAG

If you like EvoDAG, and it is used in a scientific publication, I would
appreciate citations to either the conference paper or the book chapter:

EvoDAG: A semantic Genetic Programming Python library
Mario Graff, Eric S. Tellez, Sabino Miranda-Jiménez, Hugo Jair Escalante.
2016 IEEE International Autumn Meeting on Power, Electronics and Computing (ROPEC)
pp 1-6.

  1. @inproceedings{graff_evodag:_2016,
  2. title = {{EvoDAG}: {A} semantic {Genetic} {Programming} {Python} library},
  3. shorttitle = {{EvoDAG}},
  4. doi = {10.1109/ROPEC.2016.7830633},
  5. abstract = {Genetic Programming (GP) is an evolutionary algorithm that has received a lot of attention lately due to its success in solving hard real-world problems. Lately, there has been considerable interest in GP's community to develop semantic genetic operators, i.e., operators that work on the phenotype. In this contribution, we describe EvoDAG (Evolving Directed Acyclic Graph) which is a Python library that implements a steady-state semantic Genetic Programming with tournament selection using an extension of our previous crossover operators based on orthogonal projections in the phenotype space. To show the effectiveness of EvoDAG, it is compared against state-of-the-art classifiers on different benchmark problems, experimental results indicate that EvoDAG is very competitive.},
  6. booktitle = {2016 {IEEE} {International} {Autumn} {Meeting} on {Power}, {Electronics} and {Computing} ({ROPEC})},
  7. author = {Graff, M. and Tellez, E. S. and Miranda-Jiménez, S. and Escalante, H. J.},
  8. month = nov,
  9. year = {2016},
  10. keywords = {directed graphs, Electronic mail, EvoDAG, evolving directed acyclic graph, Genetic algorithms, GP community, Libraries, semantic genetic operators, semantic genetic programming Python library, Semantics, Sociology, Statistics, Steady-state, steady-state semantic genetic programming, Training},
  11. pages = {1--6}
  12. }

Semantic Genetic Programming for Sentiment Analysis
Mario Graff, Eric S. Tellez, Hugo Jair Escalante, Sabino
Miranda-Jiménez. NEO 2015
Volume 663 of the series Studies in Computational Intelligence pp 43-65.

  1. @incollection{graff_semantic_2017,
  2. series = {Studies in {Computational} {Intelligence}},
  3. title = {Semantic {Genetic} {Programming} for {Sentiment} {Analysis}},
  4. copyright = 2017 Springer International Publishing Switzerland},
  5. isbn = {9783319440026 9783319440033},
  6. url = {http://link.springer.com/chapter/10.1007/978-3-319-44003-3_2},
  7. abstract = {Sentiment analysis is one of the most important tasks in text mining. This field has a high impact for government and private companies to support major decision-making policies. Even though Genetic Programming (GP) has been widely used to solve real world problems, GP is seldom used to tackle this trendy problem. This contribution starts rectifying this research gap by proposing a novel GP system, namely, Root Genetic Programming, and extending our previous genetic operators based on projections on the phenotype space. The results show that these systems are able to tackle this problem being competitive with other state-of-the-art classifiers, and, also, give insight to approach large scale problems represented on high dimensional spaces.},
  8. language = {en},
  9. number = {663},
  10. urldate = {2016-09-20},
  11. booktitle = {{NEO} 2015},
  12. publisher = {Springer International Publishing},
  13. author = {Graff, Mario and Tellez, Eric S. and Escalante, Hugo Jair and Miranda-Jiménez, Sabino},
  14. editor = {Schütze, Oliver and Trujillo, Leonardo and Legrand, Pierrick and Maldonado, Yazmin},
  15. year = {2017},
  16. note = {DOI: 10.1007/978-3-319-44003-3\_2},
  17. keywords = {Artificial Intelligence (incl. Robotics), Big Data/Analytics, Computational intelligence, Computer Imaging, Vision, Pattern Recognition and Graphics, Genetic programming, optimization, Semantic Crossover, sentiment analysis, Text mining},
  18. pages = {43--65}
  19. }

EvoDAG from command line

Let us assume one wants to create a classifier of iris dataset. The
first step is to download the dataset from the UCI Machine Learning
Repository

  1. curl -O https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data

Random search on the EvoDAG’s parameters space

In order to boost the performance of EvoDAG, it is recommended to optimize the parameters used by
EvoDAG. In order to free the user from this task, EvoDAG can perform a random
search on the parameter space. EvoDAG selects the best configuration found
on the random search. This can be performed as follows:

  1. EvoDAG-params -C -P params.evodag -r 734 -u 4 iris.data

where -C indicates that the task is classification,
-P indicates the file name where the parameters sampled are
stored, -r specifies the number of samples
(all the experiments presented here sampled 734 points which
corresponded, in early versions, the 0.1% of the search space), -u indicates the number of
cpu cores, and iris.data is the dataset.

params.evodag looks like:

  1. [
  2. {
  3. "Add": 30,
  4. "Cos": false,
  5. "Div": true,
  6. "Exp": true,
  7. "Fabs": true,
  8. "If": true,
  9. "Ln": true,
  10. "Max": 5,
  11. "Min": 30,
  12. "Mul": 0,
  13. "Sigmoid": true,
  14. "Sin": false,
  15. "Sq": true,
  16. "Sqrt": true,
  17. "classifier": true,
  18. "early_stopping_rounds": 2000,
  19. "fitness": [
  20. 0.0,
  21. 0.0,
  22. 0.0
  23. ],
  24. "popsize": 500,
  25. "seed": 0,
  26. "unique_individuals": true
  27. },
  28. ...

where fitness is the balance error rate on a validation set, which
is randomly taken from the training set, in this case the 20% of iris.data.

Training EvoDAG

At this point, we are in the position to train a model. Let us assume
one would like to create an ensemble of 10 classifiers on
iris.data. The following command performs this action:

  1. EvoDAG-train -P params.evodag -m model.evodag -n 100 -u 4 iris.data

where -m specifies the file name used to store the model, -n is
the size of the ensemble, -P receives EvoDAG’s parameters, -u is
the number of cpu cores, and iris.data is the dataset.

Predict using EvoDAG model

At this point, EvoDAG has been trained and the model is stored in
model.evodag, the next step is to use this model to predict some
unknown data. Given that iris.data was not split into a training
and test set, let us assume that iris.data contains some unknown
data. In order to predict iris.data one would do:

  1. EvoDAG-predict -m model.evodag -o iris.predicted iris.data

where -o indicates the file name used to store the predictions, -m
contains the model, and iris.data has the test set.

iris.predicted looks like:

  1. Iris-setosa
  2. Iris-setosa
  3. Iris-setosa
  4. Iris-setosa
  5. Iris-setosa
  6. ...

Install EvoDAG

  • Installing evodag from the conda-forge channel can be achieved by adding conda-forge to your channels with:
    1. conda config --add channels conda-forge
    2. conda config --set channel_priority strict
    3. conda install evodag
    or with mamba:
  1. mamba install evodag
  • Install using pip
    1. pip install EvoDAG

Using source code

  • Clone the repository
    git clone https://github.com/mgraffg/EvoDAG.git
  • Install the package as usual
    python setup.py install
  • To install only for the use then
    python setup.py install --user