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/benchmark.ipynb

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

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.2.dev0.tar.gz (121.1 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.2.dev0-py2.py3-none-any.whl (11.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for fqt-0.0.2.dev0.tar.gz
Algorithm Hash digest
SHA256 fbcb9c52f67ddfe0d43499cb70c8f8bff181942f6b64e989d34a2ac1cf7c0320
MD5 adbd69db7ae2c983633edc83aa8a4b41
BLAKE2b-256 52c2b6ab8e19b65b1d8a668e88d431a997ba2879c2436ed054cbe401af895a9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fqt-0.0.2.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.2.dev0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2151aed4cbd6d7806a05f93dd88937ff105bf92eeefe453225a5e98bb912f2e4
MD5 156acf4d1647113a3439dd08fc4d89f8
BLAKE2b-256 5e42bd6c3a9a6c43021ae03e1868edaea829bd3975ed027ed1b983e115a1b0d6

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