A machine learning library written from scratch - with runtime switchable backend!
Provides a single interface to interact with single-core CPU operations (with NumPy backend), as well as thousands of cores on a GPU (with CuPy backend), in runtime!
NOTE: This is NOT an alternative to libraries like scikit-learn and cuML. Their interfaces are complete on their own!
swi-ml is built on bare Python and NumPy backbones, all other dependencies are optional!
- NumPy
- CuPy (Optional)
- Matplotlib (Optional)
- (Optional) Setup a virtual environment using
virtualenv
oranaconda
. - Install NumPy by following their insallation guide or simply via
pip
:pip install numpy
- (Optional) For GPU-supported backend, setup a working installation of CuPy by following their installation guide.
python -c 'import cupy; cupy.show_config()'
- (Optional) Install Matplotlib to plot specific curves. (via their installation guide)
- Install
swi-ml
:pip install swi-ml # from PyPI pip install git+https://github.com/aitikgupta/swi-ml # from GitHub
- (Optional) To run the pre-defined tests, install pytest by following their installation guide or simply via
pip
:pip install pytest
from swi_ml import set_backend
# numpy backend (CPU)
set_backend("numpy")
# cupy backend (GPU)
set_backend("cupy")
Don't have a physical GPU, or don't know if you have a proper setup for a GPU-enabled backend?
Set automatic fallback (to NumPy - the only hard dependency):
from swi_ml import set_automatic_fallback
# this has been enabled by default for tests
# see https://github.com/aitikgupta/swi-ml/blob/master/tests/__init__.py
set_automatic_fallback(True)
from swi_ml.regression import LinearRegressionGD
data = [[1], [2], [3]]
labels = [2, 4, 6]
model = LinearRegressionGD(
num_iterations=3,
learning_rate=0.1,
normalize=False,
initialiser="uniform",
verbose="DEBUG",
)
model.fit(data, labels)
print("Current MSE:", model.curr_loss)
INFO: Backend is not set, using default `numpy`
INFO: Setting backend: numpy
INFO: MSE (1/3): 13.93602
INFO: MSE (2/3): 0.22120
INFO: MSE (3/3): 0.05478
INFO: Training time: 0.00035 seconds
Current MSE: 0.054780625247184585
For more concrete examples, please refer to examples directory.
To run the testing suite, execute the following command in the root directory:
python -mpytest # run the whole suite
python -mpytest tests/test_module.py # run the specific test module
Contributions are what makes the open source community such an amazing place to learn, inspire, and create. Any contributions are much appreciated!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
- Logo created at LogoMakr.com
- Img Shields
- Choose an Open Source License
Aitik Gupta - Personal Website