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
df1 <- read.table("credit_count.txt", header = T, sep = ",") | |
df2 <- df1[which(df1$CARDHLDR == 1), ] | |
Y <- df2$DEFAULT | |
X <- scale(df2[, 3:ncol(df2)]) | |
i <- sample(seq(length(Y)), length(Y) / 2) | |
# WITHOUT BINNING | |
Y1 <- Y[i] | |
Y2 <- Y[-i] | |
X1 <- X[i, ] |
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
source("yager.R") | |
df <- read.table("lgd", header = T)[, 1:8] | |
Y <- 1 - df$rr | |
X <- scale(df[, 2:8]) | |
pre.N <- 1000 | |
trn.N <- 100 | |
try.N <- 100 | |
seeds <- floor(with(set.seed(2020), runif(try.N) * 1e8)) | |
test_glm <- function(seed) { |
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
data(kyphosis, package = "gam") | |
y <- ifelse(kyphosis$Kyphosis == "present", 1, 0) | |
x <- scale(kyphosis[, -1]) | |
### FIT A GRNN | |
net1 <- grnn.fit(x = x, y = y) | |
test <- grnn.search_auc(net1, sigmas = gen_sobol(min = 0.5, max = 1.5, n = 50), nfolds = 20) | |
net2 <- grnn.fit(x = x, y = y, sigma = min(test$best$sigma)) | |
### FIT A GAM | |
library(gam) | |
gam1 <- gam(y~ Age + Number + Start, data = data.frame(y, x), family = binomial) |
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 |
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
from numpy.random import seed | |
from pandas import read_csv, DataFrame | |
from sklearn.preprocessing import scale | |
from keras.layers.convolutional import Conv1D, MaxPooling1D | |
from keras.layers.merge import average | |
from keras.layers import Input, Dense, Flatten, Reshape, Dropout, SpatialDropout1D | |
from keras.models import Model | |
from keras.optimizers import SGD | |
from keras.utils import plot_model |
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
library(keras) | |
df <- read.csv("credit_count.txt") | |
Y <- matrix(df[df$CARDHLDR == 1, ]$DEFAULT) | |
X <- scale(df[df$CARDHLDR == 1, ][3:14]) | |
inputs <- layer_input(shape = c(ncol(X))) | |
mlp <- inputs %>% | |
layer_dense(units = 64, activation = 'relu', kernel_initializer = 'he_uniform') %>% | |
layer_dropout(rate = 0.2, seed = 1) %>% |
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
Y <- df$bad | |
X <- scale(df_woe$df[, -1]) | |
set.seed(2019) | |
i <- sample(seq(length(Y)), length(Y) / 4) | |
Y1 <- Y[i] | |
Y2 <- Y[-i] | |
X1 <- X[i, ] | |
X2 <- X[-i, ] | |
net1 <- grnn.fit(x = X1, y = Y1) | |
rst <- grnn.optmiz_auc(net1, lower = 1, upper = 3) |
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
df <- readRDS("df.rds") | |
source("mob.R") | |
source("grnnet.R") | |
bin_out <- batch_bin(df, 3) | |
df_woe <- batch_woe(df, bin_out$BinLst) | |
Y <- df$bad | |
X <- scale(df_woe$df[, -1]) | |
set.seed(2019) | |
i <- sample(seq(length(Y)), length(Y) / 4) | |
Y1 <- Y[i] |
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
Modeling Loss / Average Loss | |
| | |
|-- Loss without Zeroes | |
| | | |
| |-- Gamma | |
| | | |
| `-- Inverse Gaussian | |
| | |
|-- Loss with Some Zeros | |
| | |
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
Modeling Frequency | |
| | |
|-- Equi-Dispersion (Baseline) | |
| | | |
| `-- Standard Poisson | |
| | |
|-- Over-Dispersion | |
| | | |
| |-- Negative Binomial | |
| | |
NewerOlder