Income Level Prediction Using R

An R classification study comparing four model families against a majority baseline on historical UCI Adult records, with grouped cross-validation, uncertainty analysis, and ggplot2 results.

Why it matters

Accuracy alone can conceal missed positive cases, weak ranking, or poor probability estimates. Comparing these properties separately makes the strengths and limits of a classifier easier to understand.

My contribution

I built the original project to learn classification in R, then revised it into a reproducible, inspectable study. I made data handling explicit, grouped matching predictor profiles during model selection, compared fixed-threshold errors and probability scores, and used R visualizations to communicate uncertainty and descriptive subgroup differences.

Result

The decision tree made fewer classification errors on the reused test sample, while the forest provided stronger ranking and lower aggregate probability errors. The value is the reproducible comparison and transparent interpretation, not a universal best model.

Tools

  • R
  • ggplot2
  • glmnet
  • rpart
  • ranger
  • e1071
  • renv
  • Automated checks

Historical data, unweighted results, and a reused test sample limit generalization. This is an educational study, not a deployed or contemporary income estimator.

Results on the reused benchmark

Version 2 retains 32,537 training records and 16,255 test records. Of the test records, 3,840 are >50K, a 23.62% positive-class share. All metrics are unweighted.

Reused test sample. The test file was examined in the earlier project iteration. These results evaluate a reused benchmark and do not provide fresh independent confirmation.

Fixed-threshold classification and ranking scores
ModelAccuracyBalanced accuracyROC AUCAverage precision
Majority baseline76.38%50.00%0.50000.2362
Ridge logistic regression84.66%75.79%0.89800.7354
Decision tree86.42%77.92%0.89100.7615
Probability random forest86.04%77.88%0.90900.7933
Linear SVM84.80%75.94%0.89680.7357

Balanced accuracy averages recall and specificity. Accuracy columns are percentages; ROC AUC and average precision are ranking scores. Scroll the table horizontally to read every metric.

Selection and classification

Training cross-validation preferred the forest: 78.32% mean balanced accuracy versus 78.23% for the tree. These are model-selection scores. On the reused test sample, the tree had the highest observed accuracy and made 2,208 errors, versus 2,270 for the forest. Its error count was 42.5% lower than the majority baseline, a relative error reduction rather than a percentage-point accuracy gain.

Ranking and probability quality

The forest led ranking with ROC AUC 0.9090 and average precision 0.7933. It also had the lowest observed Brier score (0.0971) and log loss (0.3137) among probability-producing models. Log loss uses numerical clipping; these scores do not establish perfect calibration. SVM margins are excluded from probability comparisons.

Errors at the fixed threshold

The forest detected 2,397 of 3,840 positive records and missed 1,443, giving 62.42% recall. Compared with the tree, it found 23 additional positives but produced 85 additional false positives.

A small, uncertain difference

The tree-minus-forest balanced-accuracy difference was +0.043 percentage points. Its conditional 95% interval ran from -0.523 to 0.626 points. Including zero establishes neither a clear advantage nor equivalence.

How to read uncertainty and subgroup differences

The 1,000 paired cluster-bootstrap draws condition on the fitted models and reused test sample. They exclude training and model-selection variability, so they are not fresh independent confirmation.

Subgroup charts describe historical recorded categories, with metric-specific denominators and Wilson intervals. Sex and race remain predictors. These estimates do not certify fairness or establish causal discrimination. Profile comparisons have different case mixes and do not identify people.

Reports and supporting data

The completed technical report, current 16-slide presentation, and chart book are separate documents.

Inspect the eleven aggregate summary tables (CSV)

Model scores, counts, settings, and descriptive summaries. No raw records or individual predictions are published here.

Data: Becker, B. and Kohavi, R. (1996), Adult, UCI Machine Learning Repository (opens in a new tab or window). DOI 10.24432/C5XW20 (opens in a new tab or window). Dataset license: CC BY 4.0 (opens in a new tab or window). Analysis and chart presentation by Esad Kopru. The dataset license does not grant a license to the repository code.

Technical details

Independent learning project · Reproducible classification study

Classify the historical income categories >50K and <=50K while comparing model behavior on the same records.

  • Remove identical full training records. Exclude test records whose raw predictor signature appears in the original training file, without consulting test labels. Matching profiles are not verified person identities; conflicting-label training profiles are retained.
  • Keep matching profiles together across five training folds, grouped by all 14 raw predictor fields. Learn imputation, category encoding, and scaling within each training fold. Select settings by mean fold balanced accuracy, the average of recall and specificity.
  • Compare ridge logistic regression, a decision tree, a 500-tree probability random forest, a linear SVM, and a majority baseline. Thresholds remain fixed: probabilities above 0.5 or oriented SVM margins above zero predict >50K; ties predict <=50K.
  • The code audit corrected record alignment, evaluation leakage in the historical script, score-threshold interpretation, and ROC inputs. Several methods changed together, so score changes cannot be attributed to one correction.
  • Preserve source and aggregate evidence, locked package versions, and automated checks. The ten results-summary charts redraw saved aggregates; they do not represent another model run, threshold search, recalibration, or new bootstrap calculation.

Image viewer

100%