Skip to content
Back to skills

Synthetic Sample Detection

ASecurity

Detects synthetic/fake test samples by checking whether each row has at least one unique value across all features — real samples do, synthetic ones don't.

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

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill synthetic-sample-detection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Synthetic Sample Detection?

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

Security grade badge for Synthetic Sample Detection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-synthetic-sample-detection/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-synthetic-sample-detection)

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-synthetic-sample-detection
description: >
  Detects synthetic/fake test samples by checking whether each row has at least one unique value across all features — real samples do, synthetic ones don't.
---
# Synthetic Sample Detection

## Overview

Some competitions inject synthetic rows into the test set to prevent probing or inflate leaderboard noise. A reliable signal: real data points almost always have at least one feature value that appears only once across the entire dataset, while synthetic rows (generated by sampling from existing value distributions) lack any truly unique values. Flag rows with zero unique values as synthetic and exclude them from frequency-based feature engineering.

## Quick Start

```python
import numpy as np

df_test = test_df.drop("ID_code", axis=1).values

unique_count = np.zeros_like(df_test)
for col in range(df_test.shape[1]):
    _, idx, counts = np.unique(df_test[:, col], return_index=True, return_counts=True)
    unique_count[idx[counts == 1], col] += 1

has_unique = np.sum(unique_count, axis=1) > 0
real_idx = np.argwhere(has_unique)[:, 0]
fake_idx = np.argwhere(~has_unique)[:, 0]

print(f"Real: {len(real_idx)}, Synthetic: {len(fake_idx)}")
```

## Workflow

1. For each feature column, find values that appear exactly once
2. Mark which rows contain those unique values
3. Sum unique-value flags per row: rows with sum > 0 are real
4. Rows with zero unique values are synthetic
5. Use only real test rows when computing frequency-based features

## Key Decisions

- **Threshold**: Sum > 0 is the standard cutoff; more lenient thresholds catch edge cases
- **Use case**: Frequency encoding, count-based features should exclude synthetic rows
- **Prediction**: Still predict on all test rows (real + synthetic) for submission
- **Generality**: Works when synthetics are generated by independent column sampling

## References

- [List of Fake Samples and Public/Private LB split](https://www.kaggle.com/code/yag320/list-of-fake-samples-and-public-private-lb-split)
- [200 Magical Models - Santander - [0.920]](https://www.kaggle.com/code/cdeotte/200-magical-models-santander-0-920)

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…