Skip to main content

Fast Quantile Transformer

Project description

Fast Quantile Transformer

PyPI - Version

Most of the code from this project was taken and modified from scikit-learn package. Credits to sklearn.

Improved version of Quantile Transfomer from scikit-learn package which provides ability to work with torch tensors on CUDA and other minor improvements.

Documentation

[!WARNING] Note that FastQuantileTransformer may not work on scikit-learn version 1.6.0 with numpy.ndarray. It is caused by this bug.

Current version provides same features as the original one, but also three more atributes which are replace_subsamples, noise_distribution, epsilon.

By default, Fast Quantile Transformer works almost the same as Quantile Transformer from sklearn:

>>> a = torch.tensor([[1, 2], [3, 4]])
>>> type(FastQuantileTransformer().fit_transform(a))
<class 'numpy.ndarray'>

However, if array_api_dispatch is set True, then transformer will work with object in their own namespace:

>>> a = torch.tensor([[1, 2], [3, 4]])
>>> sklearn.set_config(array_api_dispatch=True)
>>> type(FastQuantileTransformer().fit_transform(a))
<class 'torch.Tensor'>

[!NOTE] Due to unavailability of quantile function at array api standart, it is guaranted to work properly only with numpy, scipy and torch.

  • replace_subsamples: bool, default is True, specify the policy of samping subsample for quantile selection. If set to True, some objects may occur multiple times in subsample. Otherwise, if set to False, one object may occur only one time in subsample.

QuantileTrensformer from sklearn by default follows replace_subsamples=False strategy. However, it seems overkilling, because it makes noticable effect only when subsample almost equal n_samples, but takes a lot of time (check Benchmark section).

  • noise_distribution: Optional[Literal['uniform']], default is None, describes the noise property that is added to the data:
    • normal is normal distribution with loc=0.0, scale=epsilon
    • uniform is uniform distribution in range [-epsilon, epsilon]
    • deterministic, changes the distribution of border values. For more details see examples/noise_policy.ipynb.

By default epsilon=1e-5. However, you can specify it in arguments of FastQuantileTransformer.

Quantile transform from sklearn performs interpolations among quantiles twice due to case of repeating values (however, it's not actually helping, see add link), but when you're using noise provided in FastQuantileTransformer it's absolutely useless. That's why FastQuantileTransformer with noise works noticably faster even on numpy.ndarray.

[!NOTE] By paying attention to the description of the parameters you can note that FastQuantileTransformer(replace_subsamples=False) is absolutely the same as QuantileTrensformer()

Benchmarks

All the tests are performed with array of 1000000 samples and 100 features. For more details please pay attention to examples/benchmarks.ipynb

All the tests are performed using kaggle settings with single GPU T4.

attributes\transformer sklearn fqt numpy fqt torch fqt torch + cuda
standard 22.3s 22.2s 22.3s 3.7s
subsamples=100000 23.1s 23.0s 23.2s 3.7s
noise_distribution='uniform' - 14.5s 14.6s 4.7s

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

fqt-0.0.3.dev0.tar.gz (124.9 kB view details)

Uploaded Source

Built Distribution

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

fqt-0.0.3.dev0-py2.py3-none-any.whl (11.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file fqt-0.0.3.dev0.tar.gz.

File metadata

  • Download URL: fqt-0.0.3.dev0.tar.gz
  • Upload date:
  • Size: 124.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for fqt-0.0.3.dev0.tar.gz
Algorithm Hash digest
SHA256 4425ddc626341c43e9a4f49642e6af4b1f2996692d126207ca55ae6cb036f013
MD5 af2fbb441759fc16822fc1dea9c3daab
BLAKE2b-256 e49efe99caf85b89cdb95e30e22aa66472c1f9a41bfa2808037d08d883e26c5a

See more details on using hashes here.

File details

Details for the file fqt-0.0.3.dev0-py2.py3-none-any.whl.

File metadata

  • Download URL: fqt-0.0.3.dev0-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for fqt-0.0.3.dev0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d7c7deb76b06c3281b411db11184fe9e299dce1eb03f55f9f7e0394556c64a7b
MD5 9301476b552d36ee464914c9aff5d934
BLAKE2b-256 b22979b4bea0c30c2dd3cc2712582b407aa0d3b24ae6542cb7a76a4e78b73ca9

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