Skip to main content

DenseWeight

This package implements the method for imbalanced regression DenseWeight. The corresponding paper "Density-based weighting for imbalanced regression" is available here.

The goal of DenseWeight is to allow training machine learning models for regression tasks that emphasize performance for data points with rare target values in comparison to data points with more common target values. This can be useful when rare samples are of particular interest e.g. when estimating precipitation and you are interested in estimating rare, extreme precipitation events as well as possible. The parameter alpha controls the intensity of the density-based weighting scheme (alpha = 0.0 -> uniform weighting; larger alpha -> more emphasis on rare samples).

DenseWeight judges the rarity of a target value based on its density, which is obtained through Kernel Density Estimation (KDE). This package uses the fast convolutional-based KDE implementation FFTKDE from KDEpy to allow the application of DenseWeight for large datasets.

Installation

DenseWeight is available at PyPI and can be installed via pip:

pip install denseweight

Usage

import numpy as np
from denseweight import DenseWeight

# Create toy target variable with 1000 samples
y = np.random.normal(size=1000)

# Define DenseWeight
dw = DenseWeight(alpha=1.0)

# Fit DenseWeight and get the weights for the 1000 samples
weights = dw.fit(y)

# Calculate the weight for an arbitrary target value
weights = dw([0.1206])

These weights can be used as sample weights for machine learning algorithms which support them. They can also be easily integrated into loss function for models like Neural Networks to create a cost-sensitive learning solution to data imbalance in regression tasks which we call DenseLoss (more details on this in the paper).

Metadata

Release files for denseweight 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for denseweight 0.1.2
File Size Uploaded
denseweight-0.1.2.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for denseweight 0.1.2
File Interpreter ABI Platform
denseweight-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 34.0 kB

Release files / denseweight-0.1.2.tar.gz

Download URL denseweight-0.1.2.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
281cf1fe4be364366363ee822b524620dcb629c5b9ff7852aa80f91a27c98b1e
BLAKE2b-256 checksum
How to use checksums
4a5411e7547fd4b63f36bc707ec3bd0ca97079a82621f13edff8962614104067
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release files / denseweight-0.1.2-py3-none-any.whl

Download URL denseweight-0.1.2-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d939ff5d34e31e001aa16b8f0731c33555712e0e54ca1d28eb29604d669ab2b
BLAKE2b-256 checksum
How to use checksums
b27bbdea1bf4ae7d6f2251f5ae14f701929dc6785d0c0a7a095e43bec28c75d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page