skills/cv/centroid-distance-anomaly-score/SKILL.md
Score each face in a video as anomalous by computing L2 distance from the embedding centroid of all faces, then convert to probability via logistic function
npx skillsauth add wenmin-wu/ds-skills cv-centroid-distance-anomaly-scoreInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
In a real video, all face embeddings should cluster tightly (same person, consistent appearance). Deepfakes introduce subtle inconsistencies that push some embeddings away from the centroid. Computing the L2 distance from each frame's face embedding to the mean embedding, then averaging and passing through a logistic function, produces a calibrated deepfake probability without needing labeled training data.
import numpy as np
def centroid_anomaly_score(embeddings, bias=-0.3, weight=0.7):
centroid = embeddings.mean(axis=0)
distances = np.linalg.norm(embeddings - centroid, axis=1)
mean_dist = distances.mean()
prob = 1.0 / (1.0 + np.exp(-(bias + weight * mean_dist)))
return prob
# embeddings: (N_frames, 512) from a pretrained face model
prob_fake = centroid_anomaly_score(face_embeddings)
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF