German Credit#

Credit applicants described by 20 attributes, to be classified as good or bad credit risks. It is the classic small dataset for cost-sensitive classification: the source gives a cost matrix in which a wrong “good” costs five times more than a wrong “bad”. It also has categorical features and unbalanced classes.

Overview#

Loader

load_german_credit()

Task

Classification

Samples

1000

Features

20

Targets

2 classes: good (0), bad (1)

Missing values

None

License

CC BY 4.0

Features#

Thirteen features are categorical and stored as integer codes: checking_status, credit_history, purpose, savings, employment_since, personal_status_sex, other_debtors, property, other_installment_plans, housing, job, telephone and foreign_worker. The names of the categories, in the order of the codes, are in data.info.categorical, and data.categorical_features gives the columns. Each name starts with the code of the source (for example A11). The codes are labels, not quantities.

The other seven features are whole numbers: duration (months), credit_amount, installment_rate (percentage of the disposable income), residence_since, age (years), existing_credits (number of credits at this bank) and people_liable (number of people the applicant has to provide maintenance for). The dataset has no missing values.

The source lists the category A47 of purpose and the category A95 of personal_status_sex, but neither occurs in the 1000 samples.

Warning

personal_status_sex mixes the sex and the marital status of the applicant, and age and foreign_worker describe the applicant as a person. Use these attributes with care: a model that decides about real people on such grounds can be unfair.

Target#

y is 0 for a good credit risk (700 applicants) and 1 for a bad one (300). The source codes the classes 1 and 2, in the same order. The classes are unbalanced, so accuracy alone is a poor measure of a model.

Cost matrix#

The source requires a cost matrix. Its rows are the actual class and its columns the predicted class. A bad customer classified as good costs 5, a good customer classified as bad costs 1, and a correct decision costs 0. With the classes of this file the matrix is [[0, 1], [5, 0]]. The package does not store it, so a user has to apply it.

Source and citation#

  • Source: UCI Machine Learning Repository

  • Obtained from: UCI Machine Learning Repository, dataset 144, downloaded with the ucimlrepo package: the original categorical/symbolic form of the data (the file german.data), all 1000 examples with 20 attributes. The numeric version of the source (german.data-numeric) is not used. The ucimlrepo version is recorded in the file.

  • Creators: Hans Hofmann

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

Please cite the dataset as:

Hofmann, H. (1994). Statlog (German Credit Data) [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C5NC77

License#

CC BY 4.0, as stated by the source. The license was checked at the source on 2026-11-03. 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. Every category name starts with the code of the source (for example A11), followed by the meaning that the source gives to the code.

  • The attributes, which the source calls Attribute1 to Attribute20, have descriptive names taken from the data description of the source, in the order of the source.

  • The target is 0 for a good and 1 for a bad credit risk. The source codes them as 1 and 2, in the same order.

Note

The source requires a cost matrix. Its rows are the actual class and its columns the predicted class, and a correct decision costs 0. Classifying a bad customer as good costs 5 and classifying a good customer as bad costs 1. With the classes of this file (0 good, 1 bad) the matrix is [[0, 1], [5, 0]]. The matrix is not stored in the file, so a user has to apply it.

Note

The classes are not balanced: 700 good and 300 bad credit risks.

Note

The integer codes of a categorical feature are labels, not quantities. Some features are ordered (for example savings), but the codes are not distances, and unordered features such as purpose have no order at all.

Note

The source lists the category A47 of purpose and the category A95 of personal_status_sex, but neither occurs in the 1000 samples. They stay in the lists of categories, so the codes keep the order of the source.

Note

personal_status_sex mixes the sex and the marital status of the applicant, and age and foreign_worker describe the applicant as a person. Use these attributes with care: a model that decides about real people on such grounds can be unfair.

Example#

>>> import numpy as np
>>> from pyml_datasets import load_german_credit
>>> data = load_german_credit()
>>> data.X.shape
(1000, 20)
>>> data.has_missing
False
>>> data.categorical_features
(0, 2, 3, 5, 6, 8, 9, 11, 13, 14, 16, 18, 19)
>>> data.info.categorical["foreign_worker"]
('A201: yes', 'A202: no')
>>> data.target_names
('good', 'bad')
>>> np.bincount(data.y)
array([700, 300])
>>> cost = np.array([[0, 1], [5, 0]])
>>> int(cost[1, 0])  # a bad customer classified as good
5