Kredietrisicomodellering in Python
Michael Crabtree
Data Scientist, Ford Motor Company
loan_status zijn de klassen01y_train['loan_status'].value_counts()
| loan_status | Aantal in training | Percentage van totaal |
|---|---|---|
| 0 | 13,798 | 78% |
| 1 | 3,877 | 22% |
xgboost gebruiken log‑loss als verliesfunctie| Werkelijke status | Voorspelde kans | Log‑loss |
|---|---|---|
| 1 | 0.1 | 2.3 |
| 0 | 0.9 | 2.3 |
| Persoon | Leenbedrag | Potentiële winst | Voorspelde status | Werkelijke status | Verlies |
|---|---|---|---|---|---|
| A | $1,000 | $10 | Default | Niet‑default | -$10 |
| B | $1,000 | $10 | Niet‑default | Default | -$1,000 |
| Methode | Pluspunten | Minpunten |
|---|---|---|
| Meer data verzamelen | Meer defaults in absolute zin | Percentage defaults verandert misschien niet |
| Modellen straffen | Verhoogt recall voor defaults | Meer afstemming en onderhoud nodig |
| Anders samplen | Minst technische aanpassing | Minder defaults in data |
loan_status# Concat the training sets
X_y_train = pd.concat([X_train.reset_index(drop = True),
y_train.reset_index(drop = True)], axis = 1)
# Get the counts of defaults and non-defaults
count_nondefault, count_default = X_y_train['loan_status'].value_counts()
# Separate nondefaults and defaults
nondefaults = X_y_train[X_y_train['loan_status'] == 0]
defaults = X_y_train[X_y_train['loan_status'] == 1]
# Undersample the non-defaults using sample() in pandas
nondefaults_under = nondefaults.sample(count_default)
# Concat the undersampled non-defaults with the defaults
X_y_train_under = pd.concat([nondefaults_under.reset_index(drop = True),
defaults.reset_index(drop = True)], axis=0)
Kredietrisicomodellering in Python