Mushroom#

Descriptions of mushrooms from a field guide, to be classified as edible or poisonous. All 22 features are categorical, so the dataset is a good one for practising with categories, with one feature that has missing values, and with classes that are nearly balanced. The classic use is decision trees and rule learning, because a few of the features already separate the classes almost perfectly.

Overview#

Loader

load_mushroom()

Task

Classification

Samples

8124

Features

22

Targets

2 classes: edible (0), poisonous (1)

Missing values

2480 values in 1 columns, stored as NaN

License

CC BY 4.0

Features#

All 22 features are categorical and stored as integer codes. The categories are the one-letter codes of the source that occur in the data, in alphabetical order, so the code of a letter is its position in data.info.categorical[feature]. data.categorical_features gives the columns, which here are all of them. The table lists the letters of every feature in the order of the codes, with the meaning that the documentation of the source gives them.

Feature

Codes, in the order of the integer codes 0, 1, 2, …

cap_shape

b = bell, c = conical, f = flat, k = knobbed, s = sunken, x = convex

cap_surface

f = fibrous, g = grooves, s = smooth, y = scaly

cap_color

b = buff, c = cinnamon, e = red, g = gray, n = brown, p = pink, r = green, u = purple, w = white, y = yellow

bruises

f = no, t = bruises

odor

a = almond, c = creosote, f = foul, l = anise, m = musty, n = none, p = pungent, s = spicy, y = fishy

gill_attachment

a = attached, f = free

gill_spacing

c = close, w = crowded

gill_size

b = broad, n = narrow

gill_color

b = buff, e = red, g = gray, h = chocolate, k = black, n = brown, o = orange, p = pink, r = green, u = purple, w = white, y = yellow

stalk_shape

e = enlarging, t = tapering

stalk_root

b = bulbous, c = club, e = equal, r = rooted

stalk_surface_above_ring

f = fibrous, k = silky, s = smooth, y = scaly

stalk_surface_below_ring

f = fibrous, k = silky, s = smooth, y = scaly

stalk_color_above_ring

b = buff, c = cinnamon, e = red, g = gray, n = brown, o = orange, p = pink, w = white, y = yellow

stalk_color_below_ring

b = buff, c = cinnamon, e = red, g = gray, n = brown, o = orange, p = pink, w = white, y = yellow

veil_type

p = partial

veil_color

n = brown, o = orange, w = white, y = yellow

ring_number

n = none, o = one, t = two

ring_type

e = evanescent, f = flaring, l = large, n = none, p = pendant

spore_print_color

b = buff, h = chocolate, k = black, n = brown, o = orange, r = green, u = purple, w = white, y = yellow

population

a = abundant, c = clustered, n = numerous, s = scattered, v = several, y = solitary

habitat

d = woods, g = grasses, l = leaves, m = meadows, p = paths, u = urban, w = waste

stalk_root has missing entries, marked with ? in the source: 2480 values in the 8124 rows, which is the only feature with missing values. They are stored as NaN, so data.has_missing is True. Fill or drop them before fitting a model that cannot handle NaN.

veil_type has the value p (partial) in every sample, so it carries no information. It is kept as it is in the source.

The documentation of the source lists codes that never occur in the data. They are not categories here and get no integer code:

gill_attachment: d (descending), n (notched); gill_spacing: d (distant); stalk_root: u (cup), z (rhizomorphs); veil_type: u (universal); ring_type: c (cobwebby), s (sheathing), z (zone)

Target#

y is 0 if the mushroom is edible (4208 samples, 51.8 percent) and 1 if it is poisonous (3916, 48.2 percent). The source describes hypothetical samples that correspond to 23 species of the Agaricus and Lepiota family, and it combined the species of unknown edibility with the poisonous class, so the class poisonous also holds mushrooms whose edibility is unknown.

A model trained on this dataset must not be used to decide whether a real mushroom is safe to eat. The field guide itself states that there is no simple rule for determining the edibility of a mushroom.

Source and citation#

  • Source: UCI Machine Learning Repository

  • Obtained from: UCI Machine Learning Repository, dataset 73, downloaded with the ucimlrepo package: all 8124 examples with 22 inputs and the target. The ucimlrepo version is recorded in the file.

  • Creators: Jeff Schlimmer (donor), G. H. Lincoff (The Audubon Society Field Guide to North American Mushrooms, 1981)

  • DOI: https://doi.org/10.24432/C5959T

Please cite the dataset as:

Mushroom [Dataset]. (1981). UCI Machine Learning Repository. https://doi.org/10.24432/C5959T.

See also:

  • Lincoff, G. H. (Pres.) (1981). The Audubon Society Field Guide to North American Mushrooms. New York: Alfred A. Knopf.

  • Schlimmer, J. S. (1987). Concept Acquisition Through Representational Adjustment (Technical Report 87-19). Doctoral dissertation, Department of Information and Computer Science, University of California, Irvine.

License#

CC BY 4.0, as stated by the source. The license was checked at the source on 2026-11-10. See License and citation.

Changes made#

  • Converted to the NumPy NPZ format. The features are stored as float64 and the target as int64 labels.

  • Categorical features are stored as integer codes. The categories are the one-letter codes of the source that occur in the data, in alphabetical order, and the code of a category is its position in the list of the feature. The target is 0 for e (edible) and 1 for p (poisonous).

  • Entries of stalk_root that the source marks as missing (the text ?) are stored as NaN.

  • The hyphens in the column names are replaced with underscores, for example cap-shape becomes cap_shape.

Note

The samples are descriptions of hypothetical mushrooms that correspond to 23 species (pages 500 to 525 of the Guide). The Guide says that each species is definitely edible, definitely poisonous, or of unknown edibility and not recommended, and the source combined the last class with the poisonous one. So the class poisonous also holds mushrooms whose edibility is unknown.

Note

A model trained on this dataset must not be used to decide whether a real mushroom is safe to eat. The Guide itself states that there is no simple rule for determining the edibility of a mushroom.

Note

The UCI page and ucimlrepo list no creators. The creators above are the donor and the origin of the records, as the file agaricus-lepiota.names of the source gives them.

Note

The meaning of the one-letter codes is in the file agaricus-lepiota.names of the source and in the documentation page of this dataset.

Note

stalk_root has 2480 missing entries, the text ? in the source, which are NaN. The source documentation says that all 2480 missing entries are in this feature, so fill or drop them before fitting a model that cannot handle NaN.

Note

veil_type has the same value, p (partial), in all 8124 samples, so it carries no information. It is kept as it is in the source.

Note

The source documentation lists codes that never occur in the data, so they are not categories here: gill_attachment (d, n), gill_spacing (d), stalk_root (u, z), veil_type (u) and ring_type (c, s, z).

Note

The classes are nearly balanced: 4208 samples, 51.8 percent, are edible and 3916, 48.2 percent, are poisonous, as the source documentation states.

Example#

>>> import numpy as np
>>> from pyml_datasets import load_mushroom
>>> data = load_mushroom()
>>> data.X.shape
(8124, 22)
>>> data.has_missing
True
>>> int(np.isnan(data.X).sum())
2480
>>> data.categorical_features == tuple(range(22))
True
>>> data.info.categorical["odor"]
('a', 'c', 'f', 'l', 'm', 'n', 'p', 's', 'y')
>>> data.target_names
('edible', 'poisonous')
>>> np.bincount(data.y)
array([4208, 3916])