Skip to main content

Traditional Machine Learning Models in PyTorch.

Project description

PyCave

PyPi License

PyCave allows you to run traditional machine learning models on CPU, GPU, and even on multiple nodes. All models are implemented in PyTorch and provide an Estimator API that is fully compatible with scikit-learn.

For Gaussian mixture model, PyCave allows for 100x speed ups when using a GPU and enables to train on markedly larger datasets via mini-batch training. The full suite of benchmarks run to compare PyCave models against scikit-learn models is available on the documentation website.

PyCave version 3 is a complete rewrite of PyCave which is tested much more rigorously, depends on well-maintained libraries and is tuned for better performance. While you are, thus, highly encouraged to upgrade, refer to pycave-v2.borchero.com for documentation on PyCave 2.

Features

  • Support for GPU and multi-node training by implementing models in PyTorch and relying on PyTorch Lightning

  • Mini-batch training for all models such that they can be used on huge datasets

  • Well-structured implementation of models

    • High-level Estimator API allows for easy usage such that models feel and behave like in scikit-learn
    • Medium-level LightingModule implements the training algorithm
    • Low-level PyTorch Module manages the model parameters

Installation

PyCave is available via pip:

pip install pycave

If you are using Poetry:

poetry add pycave

Usage

If you've ever used scikit-learn, you'll feel right at home when using PyCave. First, let's create some artificial data to work with:

import torch

X = torch.cat([
    torch.randn(10000, 8) - 5,
    torch.randn(10000, 8),
    torch.randn(10000, 8) + 5,
])

This dataset consists of three clusters with 8-dimensional datapoints. If you want to fit a K-Means model, to find the clusters' centroids, it's as easy as:

from pycave.clustering import KMeans

estimator = KMeans(3)
estimator.fit(X)

# Once the estimator is fitted, it provides various properties. One of them is
# the `model_` property which yields the PyTorch module with the fitted parameters.
print("Centroids are:")
print(estimator.model_.centroids)

Due to the high-level estimator API, the usage for all machine learning models is similar. The API documentation provides more detailed information about parameters that can be passed to estimators and which methods are available.

GPU and Multi-Node training

For GPU- and multi-node training, PyCave leverages PyTorch Lightning. The hardware that training runs on is determined by the Trainer class. It's init method provides various configuration options.

If you want to run K-Means with a GPU, you can pass the option gpus=1 to the estimator's initializer:

estimator = KMeans(3, trainer_params=dict(gpus=1))

Similarly, if you want to train on 4 nodes simultaneously where each node has one GPU available, you can specify this as follows:

estimator = KMeans(3, trainer_params=dict(num_nodes=4, gpus=1))

In fact, you do not need to change anything else in your code.

Implemented Models

Currently, PyCave implements three different models:

License

PyCave is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycave-3.0.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycave-3.0.0-py3-none-any.whl (46.0 kB view details)

Uploaded Python 3

File details

Details for the file pycave-3.0.0.tar.gz.

File metadata

  • Download URL: pycave-3.0.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.12 Linux/5.8.0-1042-azure

File hashes

Hashes for pycave-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c8b081444dac82dda987ea9298699589f7c69e0f0c3e2e79e3e545cde28bf7e3
MD5 1afd617f9544a8a9bacca6929dcd25f1
BLAKE2b-256 48ca8afb852ddb85860262f57870cdeccdc39f5686a9c310ff03deab3004b1de

See more details on using hashes here.

File details

Details for the file pycave-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycave-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 46.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.12 Linux/5.8.0-1042-azure

File hashes

Hashes for pycave-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e90f44bb9d4c31d8c2ce71fe7ab267d4f356ecdf6faace15fbeb0d841f45b6e
MD5 6ca45ca28805ac0026834895e297dcb5
BLAKE2b-256 eaddbefd53a7670122ca585f7c601b66ac27aff5bb025364ecb2d1a2e4dc5f90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page