Created
October 20, 2019 03:13
-
-
Save statcompute/d12625cc4cb8bfbe46bc14c314bb24b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### INITIATE A GRNN | |
net1 <- grnn.fit(x = X1, y = Y1) | |
### FIND THE OPTIMIZED PARAMETER | |
best <- grnn.optmiz_auc(net1, lower = 1, upper = 3) | |
### FIT A GRNN WITH THE OPTIMIZED PARAMETER | |
net2 <- grnn.fit(x = X1, y = Y1, sigma = best$sigma) | |
### CALCULATE PFI BY TRYING 1000 RANDOM PERMUTATIONS | |
pfi_rank <- grnn.pfi(net2, ntry = 1000) | |
# idx var pfi | |
# 9 woe.bureau_score 0.06821683 | |
# 8 woe.rev_util 0.03277195 | |
# 1 woe.tot_derog 0.02845173 | |
# 7 woe.tot_rev_line 0.01680968 | |
# 10 woe.ltv 0.01416647 | |
# 2 woe.tot_tr 0.00610415 | |
# 11 woe.tot_income 0.00595962 | |
# 4 woe.tot_open_tr 0.00561115 | |
# 3 woe.age_oldest_tr 0.00508052 | |
# 5 woe.tot_rev_tr 0.00000000 | |
# 6 woe.tot_rev_debt 0.00000000 | |
### PLOT PFI | |
barplot(pfi_rank$pfi, beside = TRUE, col = heat.colors(nrow(pfi_rank)), border = NA, yaxt = "n", | |
names.arg = substring(pfi_rank$var, 5), main = "Permutation Feature Importance") | |
### EXTRACT VARIABLES WITH 0 PFI | |
excol <- pfi_rank[pfi_rank$pfi == 0, ]$idx | |
# 5 6 | |
### AUC FOR HOLD-OUT SAMPLE WITH ALL VARIABLES | |
MLmetrics::AUC(y_pred = grnn.parpred(grnn.fit(x = X1, y = Y1, sigma = best$sigma), X2), y_true = Y2) | |
# 0.7584476 | |
### AUC FOR HOLD-OUT SAMPLE WITH PFI > 0 VARIABLES | |
MLmetrics::AUC(y_pred = grnn.parpred(grnn.fit(x = X1[, -excol], y = Y1, sigma = best$sigma), X2[, -excol]), y_true = Y2) | |
# 0.7622679 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment