{"id":28538179,"url":"https://github.com/arrayfire/af-sklearn-monkeypatch","last_synced_at":"2025-09-14T18:40:06.964Z","repository":{"id":46858859,"uuid":"351890822","full_name":"arrayfire/af-sklearn-monkeypatch","owner":"arrayfire","description":"Monkey-patch for scikit-learn with accelerated ArrayFire components.","archived":false,"fork":false,"pushed_at":"2021-09-23T20:38:27.000Z","size":318,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-09T18:12:16.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arrayfire.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-26T19:27:49.000Z","updated_at":"2023-07-25T14:44:42.000Z","dependencies_parsed_at":"2022-09-23T05:40:26.642Z","dependency_job_id":null,"html_url":"https://github.com/arrayfire/af-sklearn-monkeypatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arrayfire/af-sklearn-monkeypatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Faf-sklearn-monkeypatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Faf-sklearn-monkeypatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Faf-sklearn-monkeypatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Faf-sklearn-monkeypatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arrayfire","download_url":"https://codeload.github.com/arrayfire/af-sklearn-monkeypatch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Faf-sklearn-monkeypatch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264231700,"owners_count":23576677,"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":"2025-06-09T18:11:36.785Z","updated_at":"2025-07-08T08:31:54.850Z","avatar_url":"https://github.com/arrayfire.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ArrayFire SKlearn MonkeyPatch\n\nMonkeyPatch scikit-learn with ArrayFire accelerated variants. Tested classifiers match sklearn interface and pass sklearn tests. Currently targeting scikit-learn 0.22.\nPatching sklearn components can be done explicitly with the Patcher class as follows:\n```\nimport sklearn\nfrom sklearn.neural_network import MLPClassifier\n\nfrom afsklearn.patcher import Patcher\nPatcher.patch(\"mlp_classifier\") # patches MLPClassifier with accelerated variant\n\nclf = MLPClassifier(random_state=1, max_iter=300) # accelerated arrayfire classifier\n\nPatcher.rollback(\"mlp_classifier\")\n# returns sklearn package to default state w/o arrayfire\n```\nInstead of manually replacing individual classifiers, all possible components can be replaced at once:\n```\nimport sklearn\nfrom afsklearn.patcher import Patcher\n\nPatcher.patch_all() # patches scikit-learn with all accelerated classifiers\n# sklearn functions here\nPatcher.rollback_all() #returns sklearn package to default state w/o arrayfire\n```\nIn the case that no code modification is desired, see installation instructions below for the [Autowrapt](https://github.com/syurkevi/autowrapt) package.\n\n## Installation\n\n```console\npip install -r requirements.txt\n```\nThe [Autowrapt](https://github.com/syurkevi/autowrapt) package can be used to globally and automatically replace sklearn during python's import. After installing the linked autowrapt package, set the `AUTOWRAPT_BOOTSTRAP=afsklearn` environment variable to enable the import hooks.\n\nIf packaging the af-sklearn-monkeypatch into a docker image of a larger system such as AutoML(https://gitlab.com/sray/cmu-ta2) or [AlphaD3M](https://gitlab.com/ViDA-NYU/d3m/alphad3m) the following commands can be added to the Dockerfile to include the required dependencies and permannently enable the patch:\n```\nRUN pip3 install arrayfire==3.8.0+cu102 -f https://repo.arrayfire.com/python/wheels/3.8.0/\n\nRUN pip3 install git+https://github.com/arrayfire/af-sklearn-monkeypatch \u0026\u0026 \\\n    pip3 install git+https://github.com/syurkevi/autowrapt.git\n\nENV AUTOWRAPT_BOOTSTRAP=afsklearn\n```\n\n## Tests\n\nTo run all tests\n\n```console\npytest .\n```\n\nTo run specific test\n\n```console\npytest tests/test_mlp.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farrayfire%2Faf-sklearn-monkeypatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farrayfire%2Faf-sklearn-monkeypatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farrayfire%2Faf-sklearn-monkeypatch/lists"}