Income Level Prediction Using R

In short

Background
An R learning project that compares four families of classification models with a simple baseline on historical UCI Adult income records.
My contribution
I built the original project to learn classification in R, then revised it into a reproducible study with explicit data handling and more transparent reporting of uncertainty.
Result
On the reused test sample, the decision tree produced fewer classification errors, whereas the random forest ranked cases better and had lower probability errors.

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. In a third version, declared before its run, I widened every tuning grid to test whether the settings selected in version 2 sat inside their grids.

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. A third version, declared before it ran, widened every tuning grid and selected the same tree and forest settings.

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, and version 3 below evaluates it a third time. 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.

Reports and supporting data

The technical report, 16-slide presentation, chart book, and summary tables describe version 2. Version 3 is documented in the repository.

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.

Read more Results in detail · Original historical presentation · Technical details

Results in detail

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.

Version 3: wider tuning grids

A third version, declared before it ran, widened every tuning grid to test whether the settings selected in version 2 sat inside their grids. It used the same records, cross-validation folds, and seed, with 25 tuning candidates instead of 14, and completed on November 14, 2026. It evaluates the same test file a third time, so it adds no independent confirmation.

Selected settings in versions 2 and 3
ModelVersion 2 selectionVersion 3 selectionPosition in the wider grid
Ridge logistic regressionlambda = 0.0001lambda = 0.00001Interior, on a plateau on both sides
Decision treecp = 0.0005cp = 0.0005Interior, separated on both sides
Probability random forest28 candidate columns28 candidate columnsInterior, separated on both sides
Linear SVMcost = 10cost = 30Grid edge: not bracketed, on a plateau

Scroll the table horizontally to read every column.

The tree and forest selections did not move, so their results above are unchanged; the version 2 tree setting proved to be the peak of the wider curve. Ridge moved one step along a flat curve. The SVM moved to the new last candidate for a gain of about 0.01 percentage points in mean fold balanced accuracy, and its grid could not be widened further because the solver does not finish at cost = 100. Training cross-validation again preferred the forest.

On the test sample, ridge has one more false positive (918, previously 917) and the SVM one fewer (900, previously 901); their true-positive and false-negative counts are unchanged. Ridge balanced accuracy is 75.78% (previously 75.79%). SVM accuracy and balanced accuracy are 84.81% and 75.95% (previously 84.80% and 75.94%).

Four grids changed at once, so no difference between the versions can be attributed to one change. A net difference of one false positive on a test file evaluated three times is not evidence that wider grids help or harm, and neither version is preferred because of its test scores.

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.
  • Version 3 repeats this design on the same records, folds, and seed with 25 tuning candidates in place of 14, keeping every version 2 candidate. Its protocol was committed before the run, after version 2 results had been inspected, and states in advance how each selection's position in its grid is reported.
  • 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%