Skip to main content

A Python library for skew-weighted normalization

Project description

skewnormlib

skewnormlib is an open-source Python library designed for preprocessing data using a novel method called Skew Weighted Normalization. This technique accounts for the skewness in data and applies normalization while optionally introducing a non-linear transformation. It is ideal for preparing data for machine learning models that require normalized inputs.


What is SkewWeightedNormalization?

The SkewWeightedNormalization class is a custom data transformer that normalizes data while considering its skewness. It achieves this by combining a skew-adjusted normalization term and a non-linear transformation term, making it more robust for skewed datasets.

Mathematical Formula:

The transformation is defined as:

[ \text{scaled_data} = \frac{X - \mu}{\sigma (1 + \alpha \cdot |\gamma|)} + \beta \cdot \tanh\left(\frac{X - \mu}{k \cdot \sigma}\right) ]

Where:

  • X: Input data.
  • mu: Mean of the data.
  • sigma: Standard deviation of the data.
  • gamma: Skewness of the data.
  • alpha: Skewness weighting factor (default: 1.0).
  • beta: Weighting factor for the non-linear transformation (default: 0.5).
  • k: Scaling factor for the non-linear term (default: 1.0).

How to Use

Installation

Install the library from PyPI:

pip install skewnormlib

Usage Example

import numpy as np
from skewnorm.normalization import SkewWeightedNormalization
from sklearn.model_selection import train_test_split

# Sample data
data = np.random.rand(100, 5)  # 100 samples with 5 features
X_train, X_test = train_test_split(data, test_size=0.2)

# Initialize the transformer
swn = SkewWeightedNormalization(alpha=1.0, beta=0.5, k=1.0)

# Fit and transform the training data
X_train_transformed = swn.fit_transform(X_train)

# Transform the test data
X_test_transformed = swn.transform(X_test)

# Reverse the transformation (if needed)
X_test_original = swn.inverse_transform(X_test_transformed)

print("X_train_transformed shape:", X_train_transformed.shape)
print("X_test_transformed shape:", X_test_transformed.shape)
print("Original test data recovered shape:", X_test_original.shape)

Advantages

  • Handles Skewness: Unlike traditional normalization techniques, this method adjusts for skewness, making it suitable for heavily skewed datasets.
  • Non-linear Transformation: The additional (\tanh) term helps reduce the influence of extreme outliers.
  • Scikit-learn Compatible: The class adheres to Scikit-learn's API, allowing seamless integration into pipelines.
  • Open Source: The library is open for contributions, making it a community-driven project.

Disadvantages

  • Complexity: The additional parameters ((\alpha, \beta, k)) require tuning for optimal results.
  • Performance: Slightly slower than standard normalization techniques due to the computation of skewness and the non-linear term.

When to Use It

  • Skewed Data: Use this method when the dataset has significant skewness, as it normalizes while accounting for the skew.
  • Outlier Sensitivity: When datasets contain extreme outliers that might adversely affect models, this normalization technique can help mitigate their influence.
  • Preprocessing for ML: Use this as a preprocessing step for machine learning models that perform better on normalized data (e.g., SVM, Neural Networks).

Contributing

This library is open source, and contributions are welcome! Feel free to:

  1. Submit bug reports.
  2. Suggest new features.
  3. Improve documentation.
  4. Optimize performance.

Visit the GitHub repository to contribute: GitHub Repository


License

This project is licensed under the MIT License, ensuring it remains free and open for everyone.


Contact

For questions or suggestions, contact:

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

skewnormlib-0.1.3.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

skewnormlib-0.1.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file skewnormlib-0.1.3.tar.gz.

File metadata

  • Download URL: skewnormlib-0.1.3.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for skewnormlib-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cd3fd49a0eaa9b630a5f7aefc53a49902b7e4694cb453aaf9fdea04e0a65008d
MD5 4dcb70bac769f51181c194e085f7259e
BLAKE2b-256 4b1bc061250fa9c3564d5c4d6967a36b1f00e01d84b80c7c436c51203b716e8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for skewnormlib-0.1.3.tar.gz:

Publisher: cicd.yaml on Mohdnihal03/skewnormlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file skewnormlib-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: skewnormlib-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for skewnormlib-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d5603cc971ecf4cc218f1b910199aa9266c4549d3fb14ff05ec44f13abf92aca
MD5 6d23d42050afbc942f7563e89fbb4e32
BLAKE2b-256 37aedb4ac9bb120c16822a1f59c815fa7faa17cdff31b383e67002c912637bf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for skewnormlib-0.1.3-py3-none-any.whl:

Publisher: cicd.yaml on Mohdnihal03/skewnormlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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