{"id":30548499,"url":"https://github.com/jespb/python-m3gp","last_synced_at":"2025-08-28T03:08:11.543Z","repository":{"id":40304113,"uuid":"221902531","full_name":"jespb/Python-M3GP","owner":"jespb","description":"An easy-to-use scikit-learn inspired implementation of the Multidimensional Multiclass Genetic Programming with Multidimensional Populations (M3GP) algorithm","archived":false,"fork":false,"pushed_at":"2025-04-08T05:42:56.000Z","size":143,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-24T23:34:59.618Z","etag":null,"topics":["binary-classification","classification","clustering","evolutionary-algorithm","evolutionary-algorithms","evolutionary-computation","genetic-programming","machine-learning","multiclass-classification"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jespb.png","metadata":{"files":{"readme":"README.txt","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-11-15T10:39:02.000Z","updated_at":"2025-04-08T05:43:00.000Z","dependencies_parsed_at":"2024-03-04T12:39:35.016Z","dependency_job_id":"603b27cd-f74e-4689-9d93-ea485c784816","html_url":"https://github.com/jespb/Python-M3GP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jespb/Python-M3GP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jespb%2FPython-M3GP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jespb%2FPython-M3GP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jespb%2FPython-M3GP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jespb%2FPython-M3GP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jespb","download_url":"https://codeload.github.com/jespb/Python-M3GP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jespb%2FPython-M3GP/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272426368,"owners_count":24933024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-classification","classification","clustering","evolutionary-algorithm","evolutionary-algorithms","evolutionary-computation","genetic-programming","machine-learning","multiclass-classification"],"created_at":"2025-08-28T03:08:09.740Z","updated_at":"2025-08-28T03:08:11.534Z","avatar_url":"https://github.com/jespb.png","language":"Python","readme":"This is a, easy-to-use, scikit-learn inspired version of the M3GP algorithm.\n\n\nBy using this file, you are agreeing to this product's EULA\nThis product can be obtained in https://github.com/jespb/Python-M3GP\nCopyright ©2019-2025 J. E. Batista\n\n\nThis file contains information about the command and flags used in the stand-alone version of this implementation and an explanation on how to import, use and edit this implementation.\n\n\n\n\nThis implementation of M3GP can be used in a stand-alone fashion using the following command and flags:\n\n$ python Main_M3GP_standalone.py\n    \n    [-d datasets] \n        - This flag expects a set of csv dataset names separated by \";\" (e.g., \"a.csv;b.csv\")\n        - By default, the heart.csv dataset is used        \n\n    [-dsdir dir] \n        - States the dataset directory. \n        - By default \"datasets/\" is used \n        - Use \"-dsdir ./\" for the root directory    \n\n    [-es elite_size]\n        - This flag expects an integer with the elite size;\n        - By default, the elite has size 1.\n\n    [-md max_depth]\n        - This flag expects an integer with the maximum initial depth for the trees;\n        - By default, this value is set to 6.        \n\n    [-mg max_generation]\n        - This flag expects an integer with the maximum number of generations;\n        - By default, this value is set to 100.\n\n    [-odir dir] \n        - States the output directory. \n        - By default \"results/\" is used \n        - Use \"-odir ./\" for the root directory\n    \n    [-op operators]\n        - This flag excepts a set of operators and their number of arguments, separated by \";\"\n        - Allowed operators: +,2 ; -,2 ; *,2 ; /,2\n        - By default, the used operators are the sum, subtraction, multiplication and protected division: \"+,2;-,2;*,2;/,2\"    \n\n    [-ps population_size]\n        - This flag expects an integer with the size of the population;\n        - By default, this value is set to 500.\n\n    [-runs number_of_runs] \n        - This flag expects an integer with the number of runs to be made;\n        - By default, this values is set to 30\n    \n    [-tf train_fraction]\n        - This flag expects a float [0;1] with the fraction of the dataset to be used in training;\n        - By default, this value is set to 0.70\n    \n    [-ts tournament_size]\n        - This flag expects an integer with the tournament size;\n        - By default, this value is set to 10.\n\n    [-t number_of_threads]\n        - This flag expects an integer with the number of threads to use while evaluating the population;\n        - If the value is set to 1, the multiprocessing library will not be used \n        - By default, this value is set to 1.\n    \n    [-di minimum_number_of_dimension]\n        - This flag expects an integer with the minimum number of dimensions in each individual;\n        - This flag affects the number of dimensions in the initial individuals;\n        - By default, this value is set to 1\n\n    [-dm maximum_number_of_dimension]\n        - This flag expects an integer with the maximum number of dimensions in each individual;\n        - By default, this value is set to 9999\n\n    [-rs random state]\n        - This flag expects an integer with the seed to be used by the M3GP algorithm;\n        - By default, this value is set to 42\n\n\n    \n\nHow to import this implementation to your project:\n    - Download this repository;\n    - Copy the \"m3gp/\" directory to your project directory;\n    - import the M3GP class using \"from m3gp.M3GP import M3GP\".\n\nAlternativaly, m3gp can be installed using:\n    - pip install m3gp\n\n\nHow to use this implementation:\n    $ from m3gp.M3GP import M3GP\n    $ model = M3GP()\n    $ model.fit( training_x, training_y, test_x (optional), test_y (optional) )\n\n\nArguments for M3GP():\n    operators        -\u003e Operators used by the individual (default: [(\"+\",2),(\"-\",2),(\"*\",2),(\"/\",2)] )\n    max_depth        -\u003e Max initial depths of the individuals (default: 6)\n    population_size  -\u003e Population size (default: 500)\n    max_generation   -\u003e Maximum number of generations (default: 100)\n    tournament_size  -\u003e Tournament size (default: 5)\n    elitism_size     -\u003e Elitism selection size (default: 1)\n    limit_depth      -\u003e Maximum individual depth (default: 17)\n    threads          -\u003e Number of CPU threads to be used (default: 1)\n    random_state     -\u003e Random state (default: 42)\n    model_class      -\u003e Model to be used as the inner classifier/regressor (default: MahalanobisDistanceClassifier() )\n    fitnessType      -\u003e Fitness to be used (Accuracy, WAF, 2FOLD - Classification, MSE - Regression) (default: \"Accuracy\") # \"2FOLD\" means 2-folds on the training data, using WAF\n    dim_min          -\u003e Minimum number of dimensions (default: 1)\n    dim_max          -\u003e Maximum number of dimensions (default: 9999) #The algorithm will not reach this value\n\nArguments for model.fit():\n    Tr_X         -\u003e Training samples\n    Tr_Y         -\u003e Training labels\n    Te_X         -\u003e Test samples, used in the standalone version (default: None)\n    Te_Y         -\u003e Test labels, used in the standalone version (default: None)\n\nUseful methods:\n    $ model = M3GP()    -\u003e starts the model, the model will be optimized for the MahalanobisDistance classifier, a cluster-based algorithm;\n    $ model = M3GP(model_class = RandomForestClassifier(max_depth=6), fitnessType=\"2FOLD\")\n        -\u003e the model will be optimized for the RF classifier\n        -\u003e Since RF models with no depth limit will memorize the training data, the models will obtain perfect accuracy in early generations,\n        -\u003e to predent this, either limit the RF trees depth (e.g., max_depth=6), or use \"2FOLD\" as fitnessType;\n    $ model.fit(X, Y)    -\u003e fits the model to the dataset;\n    $ model.predict(X)    -\u003e Returns a list with the prediction of the given dataset.\n\n\n\n\nHow to edit this implementation:\n    Fitness Function ( m3gp.Individual ):\n        - Change the getFitness() method to use your own fitness function;\n        - This implementation assumes that a higher fitness is always better. To change this, edit the __gt__ method in this class;\n        - Warning: Since M3GP is a slow method, a fitness function that escalates well with the number of features is recommended. \n\n   \n\n\nCitation: \n    If you use this implementation, please cite one of the works below, where the implementation is also used:\n\n    @inproceedings{Batista2022,\n      doi = {10.1109/cec55065.2022.9870343},\n      url = {https://doi.org/10.1109/cec55065.2022.9870343},\n      year = {2022},\n      month = jul,\n      publisher = {{IEEE}},\n      author = {Joao E. Batista and Sara Silva},\n      title = {Comparative study of classifier performance using automatic feature construction by M3GP},\n      booktitle = {2022 {IEEE} Congress on Evolutionary Computation ({CEC})}\n    }\n\n    @Article{rs13091623,\n        AUTHOR = {Batista, João E. and Cabral, Ana I. R. and Vasconcelos, Maria J. P. and Vanneschi, Leonardo and Silva, Sara},\n        TITLE = {Improving Land Cover Classification Using Genetic Programming for Feature Construction},\n        JOURNAL = {Remote Sensing},\n        VOLUME = {13},\n        YEAR = {2021},\n        NUMBER = {9},\n        ARTICLE-NUMBER = {1623},\n        URL = {https://www.mdpi.com/2072-4292/13/9/1623},\n        ISSN = {2072-4292},\n        DOI = {10.3390/rs13091623}\n    }\n\n    @INPROCEEDINGS{9185630,\n        author={Batista, João E. and Silva, Sara},\n        booktitle={2020 IEEE Congress on Evolutionary Computation (CEC)}, \n        title={Improving the Detection of Burnt Areas in Remote Sensing using Hyper-features Evolved by M3GP}, \n        year={2020},\n        pages={1-8},\n        doi={10.1109/CEC48606.2020.9185630}\n    }\n\n\n\n\nReference:\n    Muñoz, L., Trujillo, L., \u0026 Silva, S. (2015). M3GP – multiclass classification with GP. In Genetic Programming - 18th European Conference, EuroGP 2015, Proceedings (Vol. 9025, pp. 78-91). (Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics); Vol. 9025). Springer-Verlag. https://doi.org/10.1007/978-3-319-16501-1_7\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjespb%2Fpython-m3gp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjespb%2Fpython-m3gp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjespb%2Fpython-m3gp/lists"}