Skip to content
Back to skills

Content Difficulty Features

ASecurity

Precomputes item/content difficulty as historical mean accuracy, merged as a static feature for user-item prediction tasks.

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
datapython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill content-difficulty-features --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Content Difficulty Features?

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

Security grade badge for Content Difficulty Features
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-content-difficulty-features/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-content-difficulty-features)

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-content-difficulty-features
description: >
  Precomputes item/content difficulty as historical mean accuracy, merged as a static feature for user-item prediction tasks.
---
# Content Difficulty Features

## Overview

For recommendation or knowledge tracing tasks, compute each item's historical difficulty (mean success rate) from training data and merge as a static feature. This gives the model a strong prior: some questions are inherently harder. Works for any user-item interaction dataset.

## Quick Start

```python
import pandas as pd

def add_content_features(train_df, content_col='content_id', target_col='answered_correctly'):
    """Compute and merge content-level difficulty features."""
    content_stats = (
        train_df.groupby(content_col)[target_col]
        .agg(['mean', 'count', 'std'])
        .reset_index()
    )
    content_stats.columns = [content_col, 'content_mean', 'content_count', 'content_std']

    # Fill NaN std for items with single interaction
    content_stats['content_std'] = content_stats['content_std'].fillna(0)

    return train_df.merge(content_stats, on=content_col, how='left')

# Usage
train = add_content_features(train, 'content_id', 'answered_correctly')
# For test: merge same content_stats (computed from train only)
```

## Workflow

1. Group training data by content/item ID
2. Compute mean (difficulty), count (popularity), std (consistency)
3. Merge back as static features via left join
4. For test data, use the same content_stats from training
5. Handle unseen items with global mean imputation

## Key Decisions

- **Train-only stats**: Never include test outcomes in difficulty computation
- **Smoothing**: For rare items, blend with global mean: `(count*mean + prior*global) / (count + prior)`
- **Multiple levels**: Compute difficulty per content, per tag, per bundle for different granularities
- **Temporal decay**: Optionally weight recent interactions higher for drifting difficulty

## References

- Riiid Answer Correctness Prediction (Kaggle)
- Source: [riiid-comprehensive-eda-baseline](https://www.kaggle.com/code/erikbruin/riiid-comprehensive-eda-baseline)

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…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.