{"id":13486993,"url":"https://github.com/rsteca/sklearn-deap","last_synced_at":"2025-03-27T21:31:45.501Z","repository":{"id":48351776,"uuid":"45146653","full_name":"rsteca/sklearn-deap","owner":"rsteca","description":"Use evolutionary algorithms instead of gridsearch in scikit-learn","archived":false,"fork":false,"pushed_at":"2024-02-10T07:16:54.000Z","size":111,"stargazers_count":772,"open_issues_count":28,"forks_count":129,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-02T21:37:53.871Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","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/rsteca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"publiccode":null,"codemeta":null}},"created_at":"2015-10-28T22:52:34.000Z","updated_at":"2025-01-26T03:46:08.000Z","dependencies_parsed_at":"2023-01-31T09:01:03.544Z","dependency_job_id":"559993ac-42b6-40e0-8ac3-fe3883ecf4d3","html_url":"https://github.com/rsteca/sklearn-deap","commit_stats":{"total_commits":81,"total_committers":22,"mean_commits":"3.6818181818181817","dds":0.7407407407407407,"last_synced_commit":"3ec2df4ec319dbf7a18b98a43ea30ef10f97bb90"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsteca%2Fsklearn-deap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsteca%2Fsklearn-deap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsteca%2Fsklearn-deap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsteca%2Fsklearn-deap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rsteca","download_url":"https://codeload.github.com/rsteca/sklearn-deap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245927286,"owners_count":20695204,"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":[],"created_at":"2024-07-31T18:00:54.137Z","updated_at":"2025-03-27T21:31:45.117Z","avatar_url":"https://github.com/rsteca.png","language":"Jupyter Notebook","readme":"# sklearn-deap\nUse evolutionary algorithms instead of gridsearch in scikit-learn. This allows you to reduce the time required to find the best parameters for your estimator. Instead of trying out every possible combination of parameters, evolve only the combinations that give the best results.\n\n[Here](https://github.com/rsteca/sklearn-deap/blob/master/test.ipynb) is an ipython notebook comparing EvolutionaryAlgorithmSearchCV against GridSearchCV and RandomizedSearchCV.\n\nIt's implemented using deap library: https://github.com/deap/deap\n\nInstall\n-------\n\nTo install the library use pip:\n\n    pip install sklearn-deap\n\n\nor clone the repo and just type the following on your shell:\n\n    python setup.py install\n\nUsage examples\n--------------\n\n\n\nExample of usage:\n\n```python\nimport sklearn.datasets\nimport numpy as np\nimport random\n\ndata = sklearn.datasets.load_digits()\nX = data[\"data\"]\ny = data[\"target\"]\n\nfrom sklearn.svm import SVC\nfrom sklearn.model_selection import StratifiedKFold\n\nparamgrid = {\"kernel\": [\"rbf\"],\n             \"C\"     : np.logspace(-9, 9, num=25, base=10),\n             \"gamma\" : np.logspace(-9, 9, num=25, base=10)}\n\nrandom.seed(1)\n\nfrom evolutionary_search import EvolutionaryAlgorithmSearchCV\ncv = EvolutionaryAlgorithmSearchCV(estimator=SVC(),\n                                   params=paramgrid,\n                                   scoring=\"accuracy\",\n                                   cv=StratifiedKFold(n_splits=4),\n                                   verbose=1,\n                                   population_size=50,\n                                   gene_mutation_prob=0.10,\n                                   gene_crossover_prob=0.5,\n                                   tournament_size=3,\n                                   generations_number=5,\n                                   n_jobs=4)\ncv.fit(X, y)\n```\n\nOutput:\n\n        Types [1, 2, 2] and maxint [0, 24, 24] detected\n        --- Evolve in 625 possible combinations ---\n        gen\tnevals\tavg     \tmin    \tmax\n        0  \t50    \t0.202404\t0.10128\t0.962716\n        1  \t26    \t0.383083\t0.10128\t0.962716\n        2  \t31    \t0.575214\t0.155259\t0.962716\n        3  \t29    \t0.758308\t0.105732\t0.976071\n        4  \t22    \t0.938086\t0.158041\t0.976071\n        5  \t26    \t0.934201\t0.155259\t0.976071\n        Best individual is: {'kernel': 'rbf', 'C': 31622.776601683792, 'gamma': 0.001}\n        with fitness: 0.976071229827\n\nExample for maximizing just some function:\n\n```python\nfrom evolutionary_search import maximize\n\ndef func(x, y, m=1., z=False):\n    return m * (np.exp(-(x**2 + y**2)) + float(z))\n\nparam_grid = {'x': [-1., 0., 1.], 'y': [-1., 0., 1.], 'z': [True, False]}\nargs = {'m': 1.}\nbest_params, best_score, score_results, _, _ = maximize(func, param_grid, args, verbose=False)\n```\n\nOutput:\n\n```python\nbest_params = {'x': 0.0, 'y': 0.0, 'z': True}\nbest_score  = 2.0\nscore_results = (({'x': 1.0, 'y': -1.0, 'z': True}, 1.1353352832366128),\n ({'x': -1.0, 'y': 1.0, 'z': True}, 1.3678794411714423),\n ({'x': 0.0, 'y': 1.0, 'z': True}, 1.3678794411714423),\n ({'x': -1.0, 'y': 0.0, 'z': True}, 1.3678794411714423),\n ({'x': 1.0, 'y': 1.0, 'z': True}, 1.1353352832366128),\n ({'x': 0.0, 'y': 0.0, 'z': False}, 2.0),\n ({'x': -1.0, 'y': -1.0, 'z': False}, 0.36787944117144233),\n ({'x': 1.0, 'y': 0.0, 'z': True}, 1.3678794411714423),\n ({'x': -1.0, 'y': -1.0, 'z': True}, 1.3678794411714423),\n ({'x': 0.0, 'y': -1.0, 'z': False}, 1.3678794411714423),\n ({'x': 1.0, 'y': -1.0, 'z': False}, 1.1353352832366128),\n ({'x': 0.0, 'y': 0.0, 'z': True}, 2.0),\n ({'x': 0.0, 'y': -1.0, 'z': True}, 2.0))\n```\n","funding_links":[],"categories":["The Data Science Toolbox","Optimization","Jupyter Notebook","AutoML","超参数优化和AutoML"],"sub_categories":["General Machine Learning Packages","Others","NLP"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsteca%2Fsklearn-deap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsteca%2Fsklearn-deap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsteca%2Fsklearn-deap/lists"}