Skip to content
Back to skills

Next Click Time Delta

ASecurity

Computes seconds until the next event within a group using diff().shift(-1) on sorted timestamps, capturing user behavior velocity.

  • 61 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 12, 2026
databasespythontesting

Works with

  • cli

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill next-click-time-delta --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Next Click Time Delta?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Next Click Time Delta
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-next-click-time-delta/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-next-click-time-delta)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tabular-next-click-time-delta
description: >
  Computes seconds until the next event within a group using diff().shift(-1) on sorted timestamps, capturing user behavior velocity.
---
# Next-Click Time Delta

## Overview

In click-stream, transaction, and event-log data, the time gap between consecutive events from the same entity (user, IP, device) is a powerful behavioral signal. Short gaps indicate bots or burst activity; long gaps indicate re-engagement. This technique computes forward-looking time deltas via `groupby().transform(lambda x: x.diff().shift(-1))` — no join needed, stays aligned with the original index. Can be computed for multiple group granularities (IP only, IP+app, IP+app+device+os).

## Quick Start

```python
import pandas as pd

NEXT_CLICK_GROUPS = [
    {'groupby': ['ip']},
    {'groupby': ['ip', 'app']},
    {'groupby': ['ip', 'app', 'device', 'os', 'channel']},
]

for spec in NEXT_CLICK_GROUPS:
    feature_name = '{}_nextClick'.format('_'.join(spec['groupby']))
    df[feature_name] = (
        df.groupby(spec['groupby'])['click_time']
        .transform(lambda x: x.diff().shift(-1))
        .dt.seconds
    )

# Previous click (backward-looking)
for spec in NEXT_CLICK_GROUPS:
    feature_name = '{}_prevClick'.format('_'.join(spec['groupby']))
    df[feature_name] = (
        df.groupby(spec['groupby'])['click_time']
        .transform(lambda x: x.diff())
        .dt.seconds
    )
```

## Workflow

1. Sort DataFrame by timestamp (usually already sorted in event logs)
2. Define group granularities from broad (IP) to narrow (IP+app+device+os+channel)
3. Compute forward delta: `diff().shift(-1)` gives time to next event
4. Compute backward delta: `diff()` gives time since previous event
5. Extract `.dt.seconds` for numeric feature; NaN for first/last in group

## Key Decisions

- **Forward vs backward**: Both are useful — forward predicts intent, backward measures recency
- **Granularity**: Broader groups (IP only) capture overall velocity; narrow groups capture specific behavior
- **NaN handling**: First/last rows per group are NaN — fill with -1 or large value, or let tree models handle
- **Memory**: `.transform()` avoids merge; for very large data, compute per-group in chunks

## References

- [Feature Engineering & Importance Testing](https://www.kaggle.com/code/nanomathias/feature-engineering-importance-testing)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…