Skip to content

Commit 829c6be

Browse files
committed
update readme and demo file
1 parent 5985e4a commit 829c6be

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This package depends on 'smbinning' prior to version 0.4, so you have to install
1818

1919

2020
## Usage
21-
The following is a demo for illustrating how to use this package to establish a credit scoring model from beginning to end. You can run the following codes manually, or use 'demo(scoremodel,package="scoremodel")' directly.
21+
The following is a demo for illustrating how to use this package to establish a credit scoring model from beginning to end. You can run the following codes manually, or use demo(scoremodel,package="scoremodel") directly.
2222

2323
```R
2424
library(scoremodel)

demo/scoremodel.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,53 @@
22
## Demo file for scoremodel; start with 'demo(scoremodel)'
33
## -----------------------------------------------------------------------------------
44

5-
devAskNewPage(ask = FALSE)
5+
devAskNewPage(ask = FALSE)
66
library(scoremodel)
77
data(CreditData)
88
#convert character variables to factors
9+
910
mysample <- convertType(CreditData, toType = "fac", vars = -1)
1011
#homogeneity exclusion
12+
1113
mysample <- delNArate(mysample, narate_critical = 0.9)[[3]]
1214
mysample <- delFewValues(mysample, minN = 5, minF = 2, exclude = "target")
1315
mysample <- delSinvalPercent(mysample, percent = 0.9, exclude = "target")
1416
#split dataset to train and test
17+
1518
set.seed(21)
1619
splitresult <- splitData(mysample, size = 0.7, ifpercent = TRUE)
1720
train <- splitresult[[1]]
1821
test <- splitresult[[2]]
1922
#optimal binning and generate woe configuration list
23+
2024
configlist <- dfBinningFun(train, binMethod = 1, p = 0.05, maxcat = 10, aliquots = 5)
2125
#woe encoding
26+
2227
x_train_encoding <- woeEncodeFun_df(train[-length(train)], config_list = configlist)
2328
x_test_encoding <- woeEncodeFun_df(test[-length(test)], config_list = configlist)
2429
train_encoding <- cbind(x_train_encoding, train["target"])
2530
#collinear elimination
31+
2632
train_encoding_red <- collElimination(train_encoding, cor_critical = 0.8)
2733
#model training
34+
2835
fit <- LRfit(train_encoding_red, sig = 0.05)
2936
summary(fit)
3037
#prediction
38+
3139
p_train <- LRpredict(fit)
3240
p_test <- LRpredict(fit, newdata = x_test_encoding)
3341
#calculate KS of model
42+
3443
myks(train[,"target"], p_train)
3544
myks(test[,"target"], p_test)
3645
#calculate PSI of model
46+
3747
psi(p_train, p_test, bins = 10, binMethod = "EF")
3848
#model performance visualization
49+
3950
myCurves(train[,"target"], p_train, test[,"target"], p_test, ontest = FALSE,
4051
lift_bins = 10, P0 = 600, PDO = 50, color_scheme = 1, ifsave = FALSE)
4152
myCurves(train[,"target"], p_train, test[,"target"], p_test, ontest = TRUE,
4253
lift_bins = 10, P0 = 600, PDO = 50, color_scheme = 1, ifsave = FALSE)
43-
devAskNewPage(ask = TRUE)
54+
devAskNewPage(ask = TRUE)

0 commit comments

Comments
 (0)