Spotting Automated Accounts from a Comment Event Log
Statistics & ExperimentsModel answerLast updated
Design behavioral features from a comment log to flag automated accounts, choose a classification cutoff without clean labels, and check that heavy human users are not unfairly caught.
Scenario
You work as a data scientist at a large social platform. Popular public posts are being flooded with low-value comments, and you suspect that a portion of the accounts behind them are automated. You have one event table, comments_log, with these columns:
| Column | Meaning |
|---|---|
comment_id | Unique ID of the comment |
user_id | Account that wrote the comment |
post_id | Public post that was commented on |
created_at | Time the comment was posted |
content_length | Number of characters in the comment |
is_reported | Whether other users flagged the comment |
There are no trusted bot/human labels available up front.
What to answer
- Features. Propose three distinct behavioral metrics, computed per account from this table, that would help separate automated accounts from people. Explain why each one should differ between the two groups.
- Cutoffs. Describe the statistical method you would use to turn those metrics into a rule that labels an account as a bot, given that you lack ground truth.
- Fairness check. Explain how you would verify that the system is not wrongly flagging legitimate heavy users such as power users or celebrities.
A strong answer addresses data volume per account, the role of is_reported, and how you would measure errors, not just overall accuracy.
Hints
Hint 1
Think about features that describe the shape of an account's behavior (timing regularity, variety, targeting) rather than how much it posts, since volume is exactly what legitimate heavy users also have.
Hint 2
With no labels, look at feature distributions for a second mode or a clear tail, use robust statistics (median/MAD, percentiles), and require several signals to agree. Then calibrate the cutoff on a stratified sample reviewed by humans, weighing the cost of false positives against false negatives.
Hint 3
For the fairness check, slice false positive rate by segment (activity level, account age, verified status), deliberately oversample high-activity and verified accounts in the review set, use known-good accounts as a negative control, and run in shadow mode before enforcing.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
The task has three parts: build features that are hard to fake, set thresholds without clean labels, and prove the system is fair to heavy human users before enforcing anything. The recurring theme is to prefer volume-invariant features, use robust statistics, and evaluate per segment.
Compute features per user over a fixed window (for example 7 days) and require a minimum activity floor (say at least 20 comments), so that estimates are not dominated by noise.
1. Three behavioral metrics
a) Timing regularity: coefficient of variation of inter-comment gaps. For each user, take the gaps between consecutive comments and compute CV = std / mean.
- Humans are bursty: sessions, breaks, sleep. CV is typically well above 1.
- Scripts often post on a near-fixed schedule (CV near 0) or at superhuman speed.
- Companion features: share of gaps under about 3 seconds, and median gap.
b) Content homogeneity: entropy of comment length.
Bucket content_length and compute Shannon entropy, or use the share of comments at the user's modal length.
- Templated bots concentrate on one or a few lengths, so entropy is low.
- Humans mix short replies and long comments, so entropy is high.
- Length is only a proxy; in production you would add text hashes or embeddings.
c) Targeting and reaction speed: latency to first comment and distinct posts per active hour. For each comment, compute the time since the earliest comment on that post (a proxy for post age). Bots that watch trending posts are repeatedly among the first responders across many unrelated posts. Hour-of-day entropy is a useful extra: people sleep, while bots spread activity evenly across 24 hours.
About is_reported: do not put it in the feature set. It is noisy (controversial humans get reported), delayed, and using it both as a feature and as a validation label leaks information. Treat it as a weak label for sanity checks.
WITH gaps AS (
SELECT user_id, content_length, is_reported, created_at,
EXTRACT(EPOCH FROM created_at - LAG(created_at)
OVER (PARTITION BY user_id ORDER BY created_at)) AS gap_s
FROM comments_log
WHERE created_at >= CURRENT_DATE - INTERVAL '7 days'
)
SELECT user_id,
COUNT(*) AS n_comments,
STDDEV(gap_s) / NULLIF(AVG(gap_s), 0) AS gap_cv,
AVG(CASE WHEN gap_s < 3 THEN 1 ELSE 0 END) AS frac_fast_gaps,
COUNT(DISTINCT content_length) * 1.0 / COUNT(*) AS len_distinct_ratio,
AVG(is_reported::int) AS report_rate -- weak label only
FROM gaps
GROUP BY user_id
HAVING COUNT(*) >= 20;
2. Choosing thresholds without ground truth
Build the cutoff in layers.
- Robust standardization. Features are heavy-tailed, so log-transform where sensible and use robust z-scores: z = (x - median) / (1.4826 * MAD). Means and standard deviations get distorted by the very bots you are hunting.
- Use the distribution's shape. Plot each feature and look for a second mode (for example a cluster at CV near 0.1). Fit a two-component Gaussian mixture on the log-feature and cut where the posterior probability of the bot component passes a chosen level. If there is no clear mode, start from an extreme percentile such as the 99.5th.
- Combine signals. Require at least 2 of 3 metrics to be anomalous, or build one anomaly score (Isolation Forest or summed z-scores). If features were roughly independent with a 1% tail each, a human tripping two would be about 0.03%, a large drop in false positives.
- Calibrate with human review. Sample accounts stratified by score band, have trust-and-safety reviewers label them, and compute precision and recall at each candidate cutoff. Choose the cutoff minimizing expected cost C_FP * FP + C_FN * FN. Because the sample is stratified, reweight to population rates before reporting precision and recall.
- Small-sample care. A user with 20 comments has a noisy CV. Apply empirical-Bayes shrinkage toward the population value, or require a lower confidence bound to cross the threshold.
3. Making sure heavy human users are not over-flagged
- Volume-invariant features. CV, entropy, and ratios do not scale with comment count by construction; raw counts do. Verify empirically by plotting flag rate against activity decile; it should be flat.
- Segmented error analysis. Report flag rate and labeled precision by activity decile, account age, verified status, follower count, and region/language. The key number is the false positive rate within each segment. A 2% flag rate among verified accounts is a red flag because almost all of them are human.
- Oversample at-risk segments for labeling. A random sample contains almost no top-1% users or verified accounts, so you could not tell whether precision is poor there. Deliberately include enough of them to get tight confidence intervals.
- Negative-control anchor set. Long-tenure, verified, or payment-verified accounts are almost certainly human; anything flagged there is likely a false positive.
- Shadow mode. Score without enforcing for 2 to 4 weeks, audit the flags, then after launch monitor appeal and reinstatement rates by segment.
Trade-offs
- Stricter thresholds protect legitimate users but let sophisticated bots through; the right balance depends on the relative cost of a wrongful ban versus leftover spam.
- Multi-signal rules are more precise but slower to catch bots that only trip one metric. A tiered response (rate-limit or CAPTCHA at moderate scores, suspension at high scores) softens this.
Common mistakes
- Using raw comment counts as the main signal, which targets exactly the power users you want to protect.
- Mean/standard-deviation cutoffs on heavy-tailed, bot-contaminated data.
- Treating
is_reportedas ground truth, or using it as both feature and label. - Reporting only overall precision, which can hide very poor precision in small segments.
- No minimum-activity floor, so low-volume scores are mostly noise.
Follow-up: adversaries who add random delays
Jitter defeats a pure CV check but leaves other fingerprints. Test the shape of the gap distribution rather than just its spread: programmatic jitter tends to be uniform or exponential, while human gaps are heavy-tailed with session structure, so a KS or similar test against a human reference can separate them. Also add longer-horizon features such as hour-of-day entropy, cross-account coordination (many accounts hitting the same posts at the same moments), and text similarity. Retrain and re-threshold regularly, since the adversary adapts to whatever is published or inferred.