Hopsworks User Defined Functions - Common utilities for feature engineering
Project description
HUDF - Hopsworks User Defined Functions
Common utilities and functions for feature engineering in Hopsworks.
Installation
pip install hudf
Modules
Time Operations (hudf.time)
Functions for handling datetime conversions and timezone operations.
from hudf.time import to_epoch, from_epoch
# Convert timestamps to epoch
df = pd.DataFrame({
'timestamp': pd.date_range('2024-01-01', periods=3),
'str_date': ['2024-01-01', '2024-01-02', '2024-01-03']
})
df = to_epoch(df, ['timestamp', 'str_date'], unit='s')
Transformations (hudf.transforms)
Time-series and group-based transformations for feature engineering.
from hudf.transforms import rolling_aggs, lag_features, diff_features
# Calculate 7-day and 30-day rolling averages and std
df = rolling_aggs(
df,
value_col='amount',
time_col='timestamp',
windows=['7d', '30d'],
aggs=['mean', 'std']
)
# Create lagged features by group
df = lag_features(
df,
cols=['price', 'volume'],
lags=[1, 7, 30],
group_by='stock_id'
)
# Calculate price changes
df = diff_features(
df,
cols='price',
periods=[1, 5],
pct=True # for percentage changes
)
Statistics (hudf.stats)
Statistical operations for both rolling windows and grouped data.
from hudf.stats import rolling_stats, grouped_stats
# Calculate multiple rolling statistics
df = rolling_stats(
df,
columns='value',
window='24H',
stats=['mean', 'std', 'skew'],
on='timestamp'
)
# Calculate group-based statistics
df = grouped_stats(
df,
columns='amount',
by='category',
stats=['mean', 'median', 'nunique']
)
Function Reference
Time Operations
to_epoch(df, columns, unit='us', inplace=False, errors='raise'): Convert datetime columns to epoch timestampsfrom_epoch(df, columns, unit='us', tz='UTC'): Convert epoch timestamps back to datetime
Transformations
rolling_aggs(df, value_col, time_col, windows, aggs=['mean']): Calculate multiple rolling window aggregationslag_features(df, cols, lags, group_by=None): Create lagged features with optional groupingdiff_features(df, cols, periods=[1], pct=False): Calculate differences or percentage changes
Statistics
rolling_stats(df, columns, window, stats=['mean', 'std', 'min', 'max']): Comprehensive rolling window statisticsgrouped_stats(df, columns, by, stats=['mean', 'std', 'min', 'max']): Group-based statistical calculations
Examples
Time-Series Feature Engineering
import pandas as pd
from hudf.transforms import rolling_aggs, lag_features
from hudf.time import to_epoch
# Sample data
df = pd.DataFrame({
'timestamp': pd.date_range('2024-01-01', periods=100, freq='1H'),
'value': np.random.randn(100)
})
# Create time-based features
df = rolling_aggs(
df,
value_col='value',
time_col='timestamp',
windows=['1d', '7d'],
aggs=['mean', 'std']
)
# Add lagged features
df = lag_features(
df,
cols='value',
lags=[1, 24, 168] # 1 hour, 1 day, 1 week
)
Group-Based Features
from hudf.stats import grouped_stats
# Calculate statistics by group
df = grouped_stats(
df,
columns=['amount', 'quantity'],
by='category',
stats=['mean', 'median', 'std']
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hudf-0.0.3.tar.gz.
File metadata
- Download URL: hudf-0.0.3.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd396222e7f17e24c7bd79ddb4033d244d5b87fdb51ea9831d0a70f2bbdb9bbd
|
|
| MD5 |
86e524450ab14b19a5689a80eb3c521c
|
|
| BLAKE2b-256 |
9609fb1a60900bde64d416bc50ae0d7de820d43d394b48996159649929d9eca3
|
File details
Details for the file hudf-0.0.3-py3-none-any.whl.
File metadata
- Download URL: hudf-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df1aaebcbd5630d786330e702e5f1b20ae3422e674994c06355a99080770dfa5
|
|
| MD5 |
f4b675932f92a39689c1b7ff90cc8b92
|
|
| BLAKE2b-256 |
bfcef9a20aaa73b6d087e66e41212d02dd8347f1e340261325e8ff581c9ed8a1
|