Synthetic sample detection

From wenmin-wu/ds-skills · View interactive version

Synthetic sample detection is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. 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.

How to use this skill

Skill file

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

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

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.