Adult#
Census records of people from the 1994 Census database. Each sample is a person, and the task is to predict whether the yearly income is above 50000 dollars. It is a good dataset for practising with categorical features, missing values and unbalanced classes.
Overview#
Loader |
|
Task |
Classification |
Samples |
48842 |
Features |
14 |
Targets |
2 classes: |
Missing values |
6465 values in 3 columns, stored as |
License |
CC BY 4.0 |
Features#
Eight features are categorical and stored as integer codes: workclass, education,
marital_status, occupation, relationship, race, sex and
native_country. The names of the categories, in the order of the codes, are in
data.info.categorical, and data.categorical_features gives the columns. The categories
of education are in the order of the education level, so its code is education_num - 1.
The other six features are whole numbers: age, fnlwgt, education_num (the
education level from 1, Preschool, to 16, Doctorate), capital_gain, capital_loss and
hours_per_week. fnlwgt is the final weight of the record in the census sample. The
documentation of the source explains that people with similar demographic characteristics
should have similar weights, and that this holds only within one state.
workclass, occupation and native_country have missing entries, marked with ?
in the source: 6465 values in 3620 rows. They are stored as NaN, so data.has_missing
is True. Fill or drop them before fitting a model that cannot handle NaN.
The source comes in two files, a training part and a test part. The dataset holds both: the first 32561 rows are the training part and the last 16281 rows are the test part.
Target#
y is 0 if the yearly income is at most 50K (37155 people) and 1 if it is above 50K
(11687). The classes are unbalanced, so accuracy alone is a poor measure of a model.
Source and citation#
Source: UCI Machine Learning Repository
Obtained from: UCI Machine Learning Repository, dataset 2, downloaded with the ucimlrepo package: all 48842 examples with 14 inputs, the training part of the source (adult.data, 32561 rows) followed by its test part (adult.test, 16281 rows). The ucimlrepo version is recorded in the file.
Creators: Barry Becker, Ronny Kohavi
Please cite the dataset as:
Becker, B. & Kohavi, R. (1996). Adult [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C5XW20
See also:
Kohavi, R. (1996). Scaling Up the Accuracy of Naive-Bayes Classifiers: a Decision-Tree Hybrid. Proceedings of the Second International Conference on Knowledge Discovery and Data Mining.
License#
CC BY 4.0, as stated by the source. The license was checked at the source on 2026-11-08. See License and citation.
Changes made#
Converted to the NumPy NPZ format. Numeric features are stored as float64 and the target as int64 labels.
Categorical features are stored as integer codes, in the order of the category names listed for each feature. The categories are in alphabetical order, except those of education, which are in the order of the education level, so its code is education_num minus one. The target is 0 for <=50K and 1 for >50K.
The training part and the test part of the source are stored together, the training part first. The test part writes the target with a trailing dot (<=50K. and >50K.). The dot is dropped, so both parts use the same two classes.
Entries of workclass, occupation and native_country that the source marks as missing are stored as NaN. UCI delivers some of them as the text ? and some as empty cells, both become NaN.
The hyphens in the column names are replaced with underscores, for example marital-status becomes marital_status.
Note
Missing entries, the text ? in the source, occur in workclass, occupation and native_country: 6465 values in 3620 rows, which leaves 45222 complete rows, the number that the source documentation gives. The missing entries are NaN, so fill or drop them before fitting a model that cannot handle NaN.
Note
The first 32561 rows are the training part of the source and the last 16281 rows are its test part, so slicing the rows gives back the split of the source.
Note
The classes are not balanced: 11687 of the 48842 people, 23.93 percent, are in the class above 50K, as the source documentation states.
Note
education_num is the education level as a number. It holds the same information as education, because every education has exactly one education_num in the source.
Note
Rows that repeat an earlier row are kept as they are in the source.
Note
race and sex are features of the dataset, and the UCI variables table marks them as demographic variables. A model that uses them can reproduce social bias, so check its fairness before it is used for decisions about people.
Example#
>>> import numpy as np
>>> from pyml_datasets import load_adult
>>> data = load_adult()
>>> data.X.shape
(48842, 14)
>>> data.has_missing
True
>>> int(np.isnan(data.X).sum())
6465
>>> data.categorical_features
(1, 3, 5, 6, 7, 8, 9, 13)
>>> data.info.categorical["sex"]
('Female', 'Male')
>>> data.target_names
('<=50K', '>50K')
>>> np.bincount(data.y)
array([37155, 11687])