{"id":23136731,"url":"https://github.com/aitikgupta/swi-ml","last_synced_at":"2025-08-17T10:32:23.392Z","repository":{"id":57472734,"uuid":"323213052","full_name":"aitikgupta/swi-ml","owner":"aitikgupta","description":"A machine learning library written from scratch - with a runtime switchable backend!","archived":false,"fork":false,"pushed_at":"2021-01-30T19:10:42.000Z","size":87,"stargazers_count":14,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-20T09:23:18.162Z","etag":null,"topics":["cupy","hacktoberfest","library","machine-learning","numpy","python3","switchable-backend"],"latest_commit_sha":null,"homepage":"https://aitikgupta.github.io/swi-ml/","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/aitikgupta.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":"2020-12-21T02:43:21.000Z","updated_at":"2021-11-16T11:49:30.000Z","dependencies_parsed_at":"2022-09-17T16:12:08.584Z","dependency_job_id":null,"html_url":"https://github.com/aitikgupta/swi-ml","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitikgupta%2Fswi-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitikgupta%2Fswi-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitikgupta%2Fswi-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitikgupta%2Fswi-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aitikgupta","download_url":"https://codeload.github.com/aitikgupta/swi-ml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230116049,"owners_count":18175683,"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":["cupy","hacktoberfest","library","machine-learning","numpy","python3","switchable-backend"],"created_at":"2024-12-17T12:25:36.797Z","updated_at":"2024-12-17T12:25:37.302Z","avatar_url":"https://github.com/aitikgupta.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swi-ml\nA machine learning library written from scratch - with runtime switchable backend!\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/aitikgupta/swi-ml\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/aitikgupta/swi-ml/master/logo/swi-ml.png\" alt=\"Logo\" width=\"200\" height=\"100\"\u003e\n  \u003c/a\u003e\n  \u003cp align=\"center\"\u003e\n    Provides a single interface to interact with single-core CPU operations (with \u003ca href=\"https://numpy.org/\"\u003eNumPy\u003c/a\u003e backend), as well as thousands of cores on a GPU (with \u003ca href=\"https://cupy.dev/\"\u003eCuPy\u003c/a\u003e backend), in runtime!\n  \u003c/p\u003e\n\u003c/p\u003e\n\n[![Python][python-shield]][python-url]\n[![PyPI][pypi-shield]][pypi-url]\n[![Code style][black-shield]][black-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Codecov][codecov-shield]][codecov-url]\n[![Personal Website][website-shield]][website-url]\n[![MIT License][license-shield]][license-url]\n\nNOTE: This is NOT an alternative to libraries like [scikit-learn](https://scikit-learn.org/) and [cuML](https://docs.rapids.ai/api/cuml/stable/). Their interfaces are complete on their own!\n\n\n### Prerequsites\n\n[swi-ml](https://github.com/aitikgupta/swi-ml) is built on bare Python and NumPy backbones, all other dependencies are optional!\n* [NumPy](https://numpy.org/)\n* [CuPy](https://cupy.dev/) _(Optional)_\n* [Matplotlib](https://matplotlib.org) _(Optional)_\n\n### Installation\n\n1. _(Optional)_ Setup a virtual environment using `virtualenv` or `anaconda`.\n2. Install [NumPy](https://numpy.org/) by following their [insallation guide](https://numpy.org/install/) or simply via `pip`:\n    ```console\n    pip install numpy\n    ```\n3. _(Optional)_ For GPU-supported backend, setup a working installation of [CuPy](https://cupy.dev/) by following their [installation guide](https://docs.cupy.dev/en/stable/install.html#install-cupy).\n    ```console\n    python -c 'import cupy; cupy.show_config()'\n    ```\n4. _(Optional)_ Install [Matplotlib](https://matplotlib.org) to plot specific curves. (via their [installation guide](https://matplotlib.org/users/installing.html))\n5. Install `swi-ml`:\n   ```console\n   pip install swi-ml  # from PyPI\n   pip install git+https://github.com/aitikgupta/swi-ml  # from GitHub\n   ```\n6. _(Optional)_ To run the pre-defined tests, install [pytest](https://docs.pytest.org/en/stable/) by following their [installation guide](https://docs.pytest.org/en/stable/getting-started.html) or simply via `pip`:\n   ```console\n   pip install pytest\n   ```\n\n## Usage\n\n### Switching backend\n```python\nfrom swi_ml import set_backend\n\n# numpy backend (CPU)\nset_backend(\"numpy\")\n\n# cupy backend (GPU)\nset_backend(\"cupy\")\n```\n\n### Automatic fallback\nDon't have a physical GPU, or don't know if you have a proper setup for a [GPU-enabled backend](https://github.com/aitikgupta/swi-ml#installation)?\n\nSet automatic fallback (to [NumPy](https://github.com/aitikgupta/swi-ml#installation) - the only hard dependency):\n```python\nfrom swi_ml import set_automatic_fallback\n\n# this has been enabled by default for tests\n# see https://github.com/aitikgupta/swi-ml/blob/master/tests/__init__.py\nset_automatic_fallback(True)\n```\n\n### A simple Linear Regression with Gradient Descent\n```python\nfrom swi_ml.regression import LinearRegressionGD\n\ndata = [[1], [2], [3]]\nlabels = [2, 4, 6]\n\nmodel = LinearRegressionGD(\n    num_iterations=3,\n    learning_rate=0.1,\n    normalize=False,\n    initialiser=\"uniform\",\n    verbose=\"DEBUG\",\n)\n\nmodel.fit(data, labels)\n\nprint(\"Current MSE:\", model.curr_loss)\n```\n\n#### Output:\n```console\nINFO: Backend is not set, using default `numpy`\nINFO: Setting backend: numpy\nINFO: MSE (1/3): 13.93602\nINFO: MSE (2/3): 0.22120\nINFO: MSE (3/3): 0.05478\nINFO: Training time: 0.00035 seconds\nCurrent MSE: 0.054780625247184585\n```\n\n_For more concrete examples, please refer to [examples directory](https://github.com/aitikgupta/swi-ml/tree/master/examples)._\n\n### Running the tests\n\nTo run the testing suite, execute the following command in the root directory:\n```console\npython -mpytest  # run the whole suite\npython -mpytest tests/test_module.py  # run the specific test module\n```\n\n## Contributing\n\nContributions are what makes the open source community such an amazing place to learn, inspire, and create. Any contributions are _much appreciated!_\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n\n## Acknowledgements\n\n* Logo created at [LogoMakr.com](https://logomakr.com/9smwTn)\n* [Img Shields](https://shields.io)\n* [Choose an Open Source License](https://choosealicense.com)\n\n## About\n\nAitik Gupta - [Personal Website][website-url]\n\n[black-shield]: https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square\n[black-url]: https://github.com/psf/black\n[contributors-shield]: https://img.shields.io/github/contributors/aitikgupta/swi-ml.svg?style=flat-square\n[contributors-url]: https://github.com/aitikgupta/swi-ml/graphs/contributors\n[codecov-shield]: https://img.shields.io/codecov/c/gh/aitikgupta/swi-ml?style=flat-square\n[codecov-url]: https://codecov.io/gh/aitikgupta/swi-ml\n[forks-shield]: https://img.shields.io/github/forks/aitikgupta/swi-ml.svg?style=flat-square\n[forks-url]: https://github.com/aitikgupta/swi-ml/network/members\n[stars-shield]: https://img.shields.io/github/stars/aitikgupta/swi-ml.svg?style=flat-square\n[stars-url]: https://github.com/aitikgupta/swi-ml/stargazers\n[issues-shield]: https://img.shields.io/github/issues/aitikgupta/swi-ml.svg?style=flat-square\n[issues-url]: https://github.com/aitikgupta/swi-ml/issues\n[license-shield]: https://img.shields.io/github/license/aitikgupta/swi-ml.svg?style=flat-square\n[license-url]: https://github.com/aitikgupta/swi-ml/blob/master/LICENSE\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square\u0026logo=linkedin\u0026colorB=555\n[linkedin-url]: https://linkedin.com/in/aitik-gupta\n[product-screenshot]: images/screenshot.png\n[pypi-shield]: https://img.shields.io/pypi/v/swi-ml?style=flat-square\n[pypi-url]: https://pypi.org/project/swi-ml/\n[python-shield]: https://img.shields.io/badge/python-3.6+-blue.svg\n[python-url]: https://www.python.org/\n[website-shield]: https://img.shields.io/badge/website-aitikgupta.ml-blue?style=flat-square\n[website-url]: https://aitikgupta.github.io/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faitikgupta%2Fswi-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faitikgupta%2Fswi-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faitikgupta%2Fswi-ml/lists"}