Data & Machine LearningJune 2026Status: Complete

Federalist Papers Authorship Attribution

Applying NLP and Machine Learning to Identify Writing Patterns and Disputed Authorship

At a glance

Problem
Twelve Federalist Papers have disputed authorship between Madison and Hamilton.
My role
Engineered the stylometric features, trained and evaluated the classifiers, and interpreted the results.
Key decision
Compare three classifiers on TF-IDF and word-count features, alongside an interpretable stylometric analysis, rather than trusting a single model.
Result
98.5% cross-validated accuracy on known papers (SVM); all three models agree on 8 of the 12 disputed papers, all attributed to Madison, but with low confidence on several.
Proof
65 known-author papers (51 Hamilton, 14 Madison)3 classifiers compared12 disputed papers attributed
Built with
Text processing
  • spaCy
Modeling
  • scikit-learn
Data
  • pandas
Notebook
  • Jupyter

In Practice

1 of 3

Context

I wanted to see how machine learning extracts patterns from unstructured text, where writing style has to be turned into measurable features before any model can use it. The Federalist Papers are a classic test: a question of authorship that can only be answered from style.

Who wrote the disputed Federalist Papers?

Authorship attribution requires identifying subtle and consistent linguistic patterns across documents written by different authors. The Federalist Papers provide a well-established benchmark because several essays have disputed authorship associated with James Madison and Alexander Hamilton. The challenge is to determine whether measurable differences in writing style can reliably distinguish the authors and support attribution of the disputed essays.

Approach

The corpus was split into individual essays, restricted to papers by Madison or Hamilton, cleaned and processed with spaCy. Stylometric features (word, sentence, paragraph, punctuation and function-word measures) were used to analyze and explain stylistic differences between the authors. For classification, Logistic Regression and a linear SVM were trained on TF-IDF features and Multinomial Naive Bayes on word counts, evaluated with cross-validation on the 65 known papers, then applied to the 12 disputed essays and compared for agreement.

Data sources

  • Federalist Papers Corpus

    Publicly available Federalist Papers text collected from Project Gutenberg and structured into individual essays containing paper number, cleaned text, and known author labels. Papers with established authorship were used for model training, while disputed papers 49-58 and 62-63 were held out for authorship attribution.

Solution

Corpus

  1. Corpus. Collected and structured Federalist Papers into a labeled document corpus

  2. Text cleaning. Cleaned and normalized historical text while preserving meaningful linguistic patterns

Features

  1. Stylometric features. Extracted stylometric features including vocabulary size, sentence structure, punctuation usage and function-word frequency

  2. TF-IDF features. Built TF-IDF feature representations for supervised machine learning classification

Models and evaluation

  1. Three classifiers. Compared Multinomial Naive Bayes, Logistic Regression and Support Vector Machine models

  2. Evaluation. Evaluated models using cross-validation, accuracy, precision, recall, F1-score, ROC-AUC and log-loss metrics

  3. Disputed papers. Applied trained models to disputed Federalist Papers and compared attribution consistency across models

Architecture

The pipeline transforms historical documents into two complementary representations of writing style. Stylometric features capture interpretable linguistic characteristics, while TF-IDF represents patterns in word usage. These representations feed supervised classification models trained on known-authorship papers, with the resulting predictions applied to the disputed essays.

Authorship attribution pipeline: the Federalist Papers corpus is preprocessed into stylometric features and TF-IDF representations, which feed classifiers trained on known papers and applied to the disputed essays.
Hover to magnify · click to open full sizeTap to open full size

Components

  • Federalist Papers corpus extraction and preprocessing
  • Text normalization and linguistic feature extraction
  • Stylometric feature engineering
  • TF-IDF text vectorization
  • Classification model comparison
  • Disputed authorship inference

Outcome

On the 65 known papers, cross-validated accuracy reached 98.5% for the linear SVM, 95.4% for Logistic Regression (both with ROC-AUC of 1.00) and 87.7% for Naive Bayes. On the 12 disputed papers, all three models agree on 8, all attributed to Madison; the SVM attributes all 12 to Madison, Logistic Regression 11 and Naive Bayes 9. Confidence is the caveat: Logistic Regression's Madison probabilities range only from 0.498 to 0.548, the SVM's margins on papers 55 and 56 are close to zero, and Naive Bayes reported near-100% certainty while disagreeing on three papers. The style analysis shows why the task is possible at all: Hamilton uses "upon" about 20 times as often as Madison, while "whilst" appears almost only in Madison.

Scope and limits

A binary Hamilton-vs-Madison comparison: Jay's papers and the joint papers are excluded, and only 14 Madison papers are available for training. The models line up with the established Madison attribution rather than adding a new historical finding, and their confidence on several disputed papers is low.

Lessons Learned

  • Text classification requires careful feature engineering to convert language into measurable signals

  • Interpretable stylometric analysis explains what the classifiers can only predict, such as Hamilton's habitual "upon"

  • Model agreement and confidence analysis are important when applying classification to ambiguous cases

  • High accuracy on known cases is not confidence on the cases that matter; check calibration and agreement before trusting an attribution

  • With 51 Hamilton and 14 Madison papers, class imbalance shapes the results: Naive Bayes recognized fewer than half of Madison's papers

What's next

  • Expand the analysis to include additional historical authors
  • Compare classical models against transformer-based language models
  • Incorporate word embeddings and contextual language representations
  • Explore larger historical text collections for broader authorship attribution tasks