6.3.13. Home Equity (HMEQ)#
6.3.13.1. Summary#
Baseline and loan performance information for 5,960 recent home equity loans, from the book Credit Risk Analytics [1]. A bank’s consumer credit department wants to automate the approval of home equity lines of credit, and the task is to predict which applicants eventually default or become seriously delinquent.
Unlike most public credit scoring data, it records the amount each applicant asked for, which is what an instance-dependent cost matrix needs. Ballegeer et al. [2] use it with the cost matrix of Bahnsen et al. [3], which Empulse follows.
Classes |
2 |
Defaulters |
1189 |
Non-defaulters |
4771 |
Samples |
5960 |
Features |
12 |
6.3.13.2. Using the Dataset#
The dataset is fetched through fetch_home_equity. It is downloaded from
OpenML on first use and cached under ~/empulse_data (override with $EMPULSE_DATA_HOME or
the data_home argument), so later calls work offline.
It returns a Dataset object with the following attributes:
data: the feature matrixtarget: the target vectorcost_matrix: aCostMatrixwith default values pre-filledinstance_costs: a dict of per-instance cost drivers ('cl','fp_cost')feature_names: the feature namestarget_names: the target namesDESCR: the full description of the dataset
import pandas as pd
from empulse.datasets import fetch_home_equity
dataset = fetch_home_equity(backend=pd)
X, y = dataset.data, dataset.target
The backend argument selects the dataframe library used for data and target.
Pass the module itself — backend=pd for pandas or backend=pl for polars.
Most variables have missing values, so the data needs imputation before a linear model can use it.
Pass the cost matrix to the model as a Metric loss, and hand it the
instance costs at fit time:
from empulse.metrics import Metric, Cost
from empulse.models import CSLogitClassifier
from sklearn.compose import ColumnTransformer
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline, make_pipeline
from sklearn.preprocessing import OneHotEncoder, StandardScaler
numeric = X.select_dtypes(include=['number']).columns
categorical = X.select_dtypes(exclude=['number']).columns
pipeline = Pipeline([
('preprocessor', ColumnTransformer([
('num', make_pipeline(SimpleImputer(strategy='median'), StandardScaler()), numeric),
('cat', make_pipeline(
SimpleImputer(strategy='constant', fill_value='missing'),
OneHotEncoder(handle_unknown='ignore', sparse_output=False),
), categorical),
])),
('model', CSLogitClassifier(loss=Metric(dataset.cost_matrix, Cost()))),
])
pipeline.fit(
X,
y,
model__cl=dataset.instance_costs['cl'],
model__fp_cost=dataset.instance_costs['fp_cost'],
)
6.3.13.3. Cost Matrix#
Actual positive \(y_i = 1\) |
Actual negative \(y_i = 0\) |
|
Predicted positive \(\hat{y}_i = 1\) |
|
|
Predicted negative \(\hat{y}_i = 0\) |
|
|
- with
\(Cl_i\) : the loan amount requested (
loan_amount)\(r_i\) : the profit lost by rejecting what would have been a good loan
\(\bar{r}\) : the average profit lost by rejecting a good loan
\(\pi_0\) : the share of non-defaulters
\(\pi_1\) : the share of defaulters
\(\bar{Cl}\) : the average loan amount
\(L_{gd}\) : the fraction of the loan amount lost when the borrower defaults
Rejecting a good applicant costs the profit their loan would have made, less what lending the money
to an average alternative applicant would have earned instead [3]. The profit is computed with an
interest rate of 4.79%, a cost of funds of 2.94% and a term of 24 months, and is baked into
'fp_cost'.
The loss given default stays symbolic, with the default \(L_{gd} = 0.75\) of Ballegeer et
al. [2]. Override it by passing its alias loss_given_default when evaluating the metric:
y_score = pipeline.predict_proba(X)[:, 1]
cost = Metric(dataset.cost_matrix, Cost())
default_lgd = cost(y, y_score, **dataset.instance_costs)
higher_lgd = cost(y, y_score, loss_given_default=0.9, **dataset.instance_costs)
6.3.13.4. Data Description#
The original column name is given in brackets.
Feature |
Description |
Type |
|---|---|---|
|
Amount of the loan requested |
numeric |
|
Amount due on the existing mortgage |
numeric |
|
Value of the current property |
numeric |
|
|
categorical |
|
Occupational category |
categorical |
|
Years at the present job |
numeric |
|
Number of major derogatory reports |
numeric |
|
Number of delinquent credit lines |
numeric |
|
Age of the oldest credit line, in months |
numeric |
|
Number of recent credit inquiries |
numeric |
|
Number of credit lines |
numeric |
|
Debt-to-income ratio |
numeric |
default (target) |
Whether the applicant defaulted or was seriously delinquent (1 = yes, 0 = no) |
binary |