A phishing classifier reports 99% accuracy. That sounds impressive until you learn that only 1% of the evaluation set is phishing. A classifier that marks every example as benign also reaches 99%, while catching no attacks at all.
The question is more specific than whether the model is “accurate.” How many harmful URLs does it catch? How many legitimate links does it interrupt? Were the test examples actually new? This walkthrough uses hypothetical numbers to explain the method; it reports no measured result from a deployed detector.
Start with the four counts
Call phishing the positive class. A true positive is a phishing example correctly flagged; a false positive is a benign example flagged by mistake. A false negative is a missed phishing example, and a true negative is a benign example correctly left alone.
| Actual label | Flagged | Allowed |
|---|---|---|
| Phishing | 80 true positives | 20 false negatives |
| Benign | 99 false positives | 9,801 true negatives |
Precision is TP / (TP + FP): here, about 44.7% of flagged URLs are phishing. Recall is TP / (TP + FN): the detector finds 80% of phishing URLs. The false-positive rate is FP / (FP + TN), or 1%. Accuracy is still 98.81%. See the scikit-learn metric definitions for these measures and precision-recall curves.
That 1% false-positive rate creates 99 incorrect flags because benign traffic dominates. A test set with artificially balanced classes can hide this workload. Keep the expected deployment prevalence visible, and report raw counts so someone can translate rates into the number of users affected.
A split that resembles the future
Use the diagram to follow the evaluation gates. Choosing the partition is part of the experiment, not a housekeeping task after training.
Audit data
Record collection times, label provenance, and duplicate or campaign relationships. Use only features that would have existed when a real prediction was made.
1. Separate time from randomness
A random split can place near-identical URLs from the same campaign in both training and testing. It may also let the model learn from tomorrow’s examples to predict yesterday’s. For a detector that will score future traffic, reserve a later collection window as the final test set and validate on a window before it.
The cross-validation guide explains why ordinary shuffled folds can be unsuitable for time-dependent data, and describes group-aware evaluation. My recommendation for phishing data is to audit both time and campaign relationships: they answer different generalization questions.
Report performance on all future traffic and, when useful, a separate slice of previously unseen domains or campaigns. Do not quietly remove familiar domains and describe that result as ordinary traffic performance. If a group crosses the time boundary, make your handling explicit and preserve chronological order.
2. Use features that existed at prediction time
A domain’s reputation from a threat feed collected a week after the attack may almost reveal the answer. A label embedded in the source filename is an even simpler leak. For every feature, ask when it became available and whether the production service can obtain it before making the decision.
Keep timestamps for both observations and labels. A phishing label discovered later may be valid ground truth, but a later reputation value cannot be smuggled into an earlier prediction. Audit label provenance, conflicting labels, repeated URLs, and source-specific collection artifacts before comparing algorithms.
3. Fit preprocessing inside the boundary
Fit imputers, scalers, text vocabularies, feature selectors, and any resampling only on training data. Apply the fitted transformations to validation and testing. Scikit-learn’s data-leakage guidance recommends pipelines to keep learned preprocessing attached to the model during evaluation.
1from sklearn.pipeline import make_pipeline2from sklearn.impute import SimpleImputer3from sklearn.ensemble import RandomForestClassifier4from sklearn.metrics import confusion_matrix, precision_score, recall_score56# X_* contain numeric features available at observation time.7# Partitions are already chronological and audited for duplicates.8pipeline = make_pipeline(9 SimpleImputer(strategy="median"),10 RandomForestClassifier(n_estimators=200, random_state=42),11)12pipeline.fit(X_train, y_train)1314# Choose this value using validation data, then freeze it.15threshold = selected_validation_threshold16positive_column = list(pipeline.classes_).index(1)17scores = pipeline.predict_proba(X_test)[:, positive_column]18predictions = (scores >= threshold).astype(int)19print(confusion_matrix(y_test, predictions, labels=[0, 1]))20print(precision_score(y_test, predictions, zero_division=0))21print(recall_score(y_test, predictions, zero_division=0))
The variable names represent partitions prepared before this snippet. This is an evaluation skeleton, not a dataset loader or a claim that random forests are the best detector. Compare it against a simple baseline using the same partitions and operating constraint.
The threshold is a product choice
Analyst review
- Prioritize useful findings per reviewer hour
- Track daily alert volume
- Measure precision among reviewed alerts
- Account for delayed and incomplete labels
Automatic blocking
- Set a strict false-positive budget
- Check impact on legitimate users
- Provide an appeal or override path
- Consider a separate uncertain/review band
Choose the threshold on validation data using an explicit constraint, such as a maximum benign-block rate. Then freeze both the model and threshold before evaluating the final test window. If you change either after seeing the result, you have used the test set for selection and need a fresh holdout.
Make the result useful after deployment
Publish the dates, class counts, collection sources, positive-label definition, threshold, confusion matrix, precision, recall, and false-positive rate. Include uncertainty intervals where the sample supports them; correlated campaign examples should not be treated as thousands of independent observations.
- Slice the errors: inspect new domains, shortened URLs, languages, sources, and missing-feature cases. A good average can hide a poor experience for one traffic segment.
- Measure the whole service: latency and feature-extraction failures affect real coverage. A URL that times out is not a confirmed benign URL.
- Keep learning from later windows: track alert volume and labeled outcomes over time. Reevaluate a replacement model on a new holdout before changing the blocking policy.
A credible detector report explains what the system caught, what it missed, and what the mistakes cost. That is a stronger engineering result than a large accuracy percentage without a defensible experiment behind it.