liveBook · Manning

F-test

As explained in Fight Fraud with Machine Learning

An ANOVA F-test is a statistical test that compares between-group variability with within-group variability to assess whether group means differ.

An ANOVA F-test ranks numerical features when the fraud label is binary and the feature values are not directly comparable with labels 0 and 1. It compares variability between the genuine and fraudulent group means with variability within those groups. A larger between-group component relative to within-group variation indicates clearer separation and makes the feature a candidate for rule-based fraud detection. section 2.1.2

Use the F-test as part of a practical numerical-feature workflow:

  • Fit f_classif through SelectKBest on the numerical columns and the fraud label. section 2.1.2
  • Sort the resulting F-statistics in decreasing order to identify candidate features. section 2.1.2
  • Inspect high-ranking features with countplots, stripplots, or histplots rather than relying on the score alone. section 2.1.2
  • Account for real-time availability and missing values before turning feature importance into production rules. section 2.1.2

Phishing-feature ranking

For a phishing dataset, the F-test ranks features such as NumDash, NumNumericChars, and PctExtResourceUrls by their ability to separate genuine webpages from fraudulent webpages. PctExtNullSelfRedirectHyperlinksRT requires additional inspection: its possible values are -1, 0, and 1, and a countplot shows a high fraud likelihood at -1, while a stripplot suffers from severe point overlap. section 2.1.2

Equation 2.1 Formula for one-way ANOVA F-test statistic
F = between-group variability / within-group variability

The statistic is summarized as F = between-group variability / within-group variability. section 2.1.2

from sklearn.feature_selection import f_classif, SelectKBest
plt.figure(figsize=(10,8))
 
fs = SelectKBest(score_func=f_classif)
fs.fit(df[numerical_features], df.CLASS_LABEL)
 
scores = zip(numerical_features, fs.scores_)
scores = sorted(scores, key=lambda c: c[1], reverse=True)
 
sns.barplot( x=[c[1] for c in scores], y=[c[0] for c in scores]);

The supplied scikit-learn listing computes F-test scores for numerical features and plots them in descending order. section 2.1.2

How Fight Fraud with Machine Learning covers it

How deep it goes
Defines the variance ratio and demonstrates scikit-learn ranking, then defers final selection to visualization and operational checks.
Examples
Uses phishing features including NumDash, NumNumericChars, PctExtResourceUrls, and PctExtNullSelfRedirectHyperlinksRT.
What it assumes
Assumes numerical features and a binary fraud label while explaining why their values cannot be compared directly.
What you can do after
Apply it via scikit-learn to rank numerical features and guide subsequent fraud-rule analysis.
How it connects
Connects ANOVA, feature importance, binary classification, visualization, and rule-based fraud detection.

Also explained in

Compare how 2 books explain f-test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fight Fraud with Machine Learning. The section links point to the parts of the book it draws on.