fetch_give_me_some_credit#
- empulse.datasets.fetch_give_me_some_credit(*, backend, data_home=None, download_if_missing=True)[source]#
Fetch the “Give Me Some Credit” dataset from OpenML (binary classification).
The goal is to predict whether a customer will default on a loan in the next two years. Target variable: 1 = defaulted, 0 = no default.
Downloads data directly from OpenML without requiring scikit-learn. Downloaded data is cached locally.
Only customers with positive monthly income and a debt ratio below 1 are kept.
For a full data description and additional information about the dataset, consult the User Guide.
Classes
2
Defaulters
7616
Non-defaulters
105299
Samples
112915
Features
10
- Parameters:
- backendmodule
Dataframe library to use for
dataandtarget. Pass the library module directly, e.g.backend=polarsorbackend=pandas.- data_homestr or Path, optional
Directory used for caching downloaded data. Defaults to
~/empulse_data(or$EMPULSE_DATA_HOME).- download_if_missingbool, default=True
If False, raise an
OSErrorwhen the data is not cached locally.
- Returns:
- dataset
Dataset instance_costscontains:'cl': estimated credit line per client.'fp_cost': precomputed FP cost per client.
- dataset
Notes
Cost matrix
Actual positive \(y_i = 1\)
Actual negative \(y_i = 0\)
Predicted positive \(\hat{y}_i = 1\)
tp_cost\(= 0\)fp_cost(precomputed, depends on dataset-level statistics)Predicted negative \(\hat{y}_i = 0\)
fn_cost\(= Cl_i \cdot L_{gd}\)tn_cost\(= 0\)The cost matrix uses symbolic parameters with the following defaults:
loss_given_default(\(L_{gd}\)) = 0.75
The following parameters are used to precompute per-instance credit lines and
fp_costvalues stored ininstance_costs:interest_rate= 0.0479 (annual)fund_cost= 0.0294 (annual)max_credit_line= 25000term_length_months= 24loan_to_income_ratio= 3
To override the symbolic default, pass the desired value when evaluating the metric:
metric(dataset.target, y_score, loss_given_default=0.6, **dataset.instance_costs)
References
[1]A. Correa Bahnsen, D.Aouada, B, Ottersten, “Example-Dependent Cost-Sensitive Logistic Regression for Credit Scoring”, in Proceedings of the International Conference on Machine Learning and Applications, 2014.
Examples
import numpy as np import pandas as pd from empulse.datasets import fetch_give_me_some_credit from empulse.metrics import Metric, Cost dataset = fetch_give_me_some_credit(backend=pd) # replace with your own model's predicted probabilities y_score = np.random.default_rng(0).uniform(size=len(dataset.target)) metric = Metric(dataset.cost_matrix, Cost()) score = metric(dataset.target, y_score, **dataset.instance_costs)