{"id":14970675,"url":"https://github.com/timzatko/sklearn-nature-inspired-algorithms","last_synced_at":"2026-02-23T00:12:22.101Z","repository":{"id":42424555,"uuid":"263010812","full_name":"timzatko/Sklearn-Nature-Inspired-Algorithms","owner":"timzatko","description":"Nature-inspired algorithms for hyper-parameter tuning of Scikit-Learn models.","archived":false,"fork":false,"pushed_at":"2023-10-03T20:38:06.000Z","size":486,"stargazers_count":28,"open_issues_count":4,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T19:12:06.908Z","etag":null,"topics":["data-science","hyper-parameter-optimization","hyper-parameter-tuning","nature-inspired-algorithms","python","scikit-learn"],"latest_commit_sha":null,"homepage":"https://sklearn-nature-inspired-algorithms.readthedocs.io/en/stable/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timzatko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-11T10:28:58.000Z","updated_at":"2024-04-01T17:32:42.000Z","dependencies_parsed_at":"2023-10-02T00:22:10.996Z","dependency_job_id":null,"html_url":"https://github.com/timzatko/Sklearn-Nature-Inspired-Algorithms","commit_stats":{"total_commits":150,"total_committers":4,"mean_commits":37.5,"dds":"0.040000000000000036","last_synced_commit":"6deb2506dc4f6b59833083b8efc67d4323a7f97c"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timzatko%2FSklearn-Nature-Inspired-Algorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timzatko%2FSklearn-Nature-Inspired-Algorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timzatko%2FSklearn-Nature-Inspired-Algorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timzatko%2FSklearn-Nature-Inspired-Algorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timzatko","download_url":"https://codeload.github.com/timzatko/Sklearn-Nature-Inspired-Algorithms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238337291,"owners_count":19455284,"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","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":["data-science","hyper-parameter-optimization","hyper-parameter-tuning","nature-inspired-algorithms","python","scikit-learn"],"created_at":"2024-09-24T13:43:58.484Z","updated_at":"2026-02-23T00:12:22.090Z","avatar_url":"https://github.com/timzatko.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nature-Inspired Algorithms for scikit-learn\n\n[![CI](https://github.com/timzatko/Sklearn-Nature-Inspired-Algorithms/workflows/CI/badge.svg?branch=master)](https://github.com/timzatko/Sklearn-Nature-Inspired-Algorithms/actions?query=workflow:CI+branch:master)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sklearn-nature-inspired-algorithms)\n[![PyPI version](https://badge.fury.io/py/sklearn-nature-inspired-algorithms.svg)](https://pypi.org/project/sklearn-nature-inspired-algorithms/)\n[![PyPI downloads](https://img.shields.io/pypi/dm/sklearn-nature-inspired-algorithms)](https://pypi.org/project/sklearn-nature-inspired-algorithms/)\n[![Fedora package](https://img.shields.io/fedora/v/python3-sklearn-nature-inspired-algorithms?color=blue\u0026label=Fedora%20Linux\u0026logo=fedora)](https://src.fedoraproject.org/rpms/python-sklearn-nature-inspired-algorithms)\n\nNature-inspired algorithms for hyper-parameter tuning of [scikit-learn](https://github.com/scikit-learn/scikit-learn) models. This package uses algorithms implementation from [NiaPy](https://github.com/NiaOrg/NiaPy). \n\n## Installation\n\n```shell script\n$ pip install sklearn-nature-inspired-algorithms\n```\n\nTo install this package on Fedora, run:\n\n```sh\n$ dnf install python3-sklearn-nature-inspired-algorithms\n```\n\n## Usage\n\nThe usage is similar to using sklearn's `GridSearchCV`. Refer to the [documentation](https://sklearn-nature-inspired-algorithms.readthedocs.io/en/stable/) for more detailed guides and more examples.\n\n```python\nfrom sklearn_nature_inspired_algorithms.model_selection import NatureInspiredSearchCV\nfrom sklearn.ensemble import RandomForestClassifier\n\nparam_grid = { \n    'n_estimators': range(20, 100, 20), \n    'max_depth': range(2, 40, 2),\n    'min_samples_split': range(2, 20, 2), \n    'max_features': [\"auto\", \"sqrt\", \"log2\"],\n}\n\nclf = RandomForestClassifier(random_state=42)\n\nnia_search = NatureInspiredSearchCV(\n    clf,\n    param_grid,\n    algorithm='hba', # hybrid bat algorithm\n    population_size=50,\n    max_n_gen=100,\n    max_stagnating_gen=10,\n    runs=3,\n    random_state=None, # or any number if you want same results on each run\n)\n\nnia_search.fit(X_train, y_train)\n\n# the best params are stored in nia_search.best_params_\n# finally you can train your model with best params from nia search\nnew_clf = RandomForestClassifier(**nia_search.best_params_, random_state=42)\n```\n\nAlso you plot the search process with _line plot_ or _violin plot_.\n\n```python\nfrom sklearn_nature_inspired_algorithms.helpers import score_by_generation_lineplot, score_by_generation_violinplot\n\n# line plot will plot all of the runs, you can specify the metric to be plotted ('min', 'max', 'median', 'mean')\nscore_by_generation_lineplot(nia_search, metric='max')\n\n# in violin plot you need to specify the run to be plotted\nscore_by_generation_violinplot(nia_search, run=0)\n```\n\nJupyter notebooks with full examples are available in [here](examples/notebooks).\n\n### Using a Custom Nature-Inspired Algorithm\n\nIf you do not want to use any of the pre-defined algorithm configurations, you can use any algorithm from the  [NiaPy](https://github.com/NiaOrg/NiaPy) collection.\nThis will allow you to have more control of the algorithm behavior. \nRefer to their [documentation](https://niapy.readthedocs.io/en/latest/) and [examples](https://github.com/NiaOrg/NiaPy/tree/master/examples) for the usage. \n\n__Note:__ Use version \u003e2.x.x of NiaPy package\n\n```python\nfrom niapy.algorithms.basic import GeneticAlgorithm\n\nalgorithm = GeneticAlgorithm() # when custom algorithm is provided random_state is ignored\nalgorithm.set_parameters(NP=50, Ts=5, Mr=0.25)\n\nnia_search = NatureInspiredSearchCV(\n    clf,\n    param_grid,\n    algorithm=algorithm,\n    population_size=50,\n    max_n_gen=100,\n    max_stagnating_gen=20,\n    runs=3,\n)\n\nnia_search.fit(X_train, y_train)\n```\n\n## Contributing \n\nDetailed information on the contribution guidelines are in the [CONTRIBUTING.md](./CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimzatko%2Fsklearn-nature-inspired-algorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimzatko%2Fsklearn-nature-inspired-algorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimzatko%2Fsklearn-nature-inspired-algorithms/lists"}