library(jsonlite)
library(data.table)
## 读入二维火数据
twodfile_raw <- read.csv("E:/03 工作代码/02 R project/风险定价/2dfile_features.csv", stringsAsFactors = F)
twodfile_raw <- data.table(twodfile_raw)
test_data <- read.csv("E:/boshuzhang-19-04-25-16-20-47-618.csv", stringsAsFactors = F)
test_data <- data.table(test_data)
test_data[, twodfire_score := fromJSON(ext_data)$extra_info$detail$user$twodfire_score, by = 'transport_id']
test_data[, features_card_openCards_amount_usedAmountRatioAll := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$features_card_openCards_amount_usedAmountRatioAll), by = 'transport_id']
test_data[, recent_average_customer_weighted := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$recent_average_customer_weighted), by = 'transport_id']
test_data[, gmv_3_mean := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$gmv_3_mean_mean), by = 'transport_id']
test_data[, zyd_score := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$zyd_score), by = 'transport_id']
test_data[, tongdun_score := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$tongdun_score), by = 'transport_id']
test_data[, features_loan_basicInfo_loanContractAmountMin := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$features_loan_basicInfo_loanContractAmountMin), by = 'transport_id']
test_data[, recent_average_order_num_weighted := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$recent_average_order_num_weighted), by = 'transport_id']
test_data[, deny_code_info_search_searchTimeDetails_searchTimes3M := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$deny_code_info_search_searchTimeDetails_searchTimes3M), by = 'transport_id']
test_data[, features_loan_openLoanInfo_loanCount := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$features_loan_openLoanInfo_loanCount), by = 'transport_id']
test_data[, recent3_top5_instance_rate_weighted := as.double(fromJSON(ext_data)$extra_info$detail$user$twodfire_feature$recent3_top5_instance_rate_weighted), by = 'transport_id']
twodfire_feature_names <- c('features_card_openCards_amount_usedAmountRatioAll',
'recent_average_customer_weighted',
'gmv_3_mean',
'zyd_score',
'tongdun_score',
'features_loan_basicInfo_loanContractAmountMin',
'recent_average_order_num_weighted',
'deny_code_info_search_searchTimeDetails_searchTimes3M',
'features_loan_openLoanInfo_loanCount',
'recent3_top5_instance_rate_weighted'
)
tf_input <- test_data[, c('transport_id', twodfire_feature_names), with = F]
# tf_input <- merge(test_data, mergeData_credit, by = 'transport_id')
tf_input <- merge(twodfile_raw, mergeData_credit, by = 'transport_id')
tf_input[, target := ifelse(X4mon_per_flag == 1 & mob4_ever_dpd15_flag == 0, 0, ifelse(mob4_ever_dpd15_flag == 1, 1, -1))]
input.list <- c('')
tf_model.data <- tf_input[target >= 0]
tf_model.data[, twodfire_score := NULL]
tf_model.data[, gmv_year := NULL]
tf_model.data[, limit_data_loan := NULL]
# tf_model.data[, gmv_3_mean_mean := NULL]
# tf_model.data[, recent_average_customer_weighted := NULL]
library(rpart)
library(rpart.plot)
fit_tf <- rpart(target ~ .
, data = tf_model.data[,c('target'
# , 'features_card_openCards_amount_usedAmountRatioAll'
, 'tongdun_score', 'zyd_score', 'recent_average_customer_weighted'
, 'deny_code_info_search_searchTimeDetails_searchTimes3M'
, 'recent3_top5_instance_rate_weighted'
, 'gmv_3_mean_mean'
, 'bf_app_cnt'
, 'cms_max_active_days'
), with = F]
, control=rpart.control(minsplit = 50, minbucket = 50, cp = 0.001, maxdepth = 4, surrogatestyle = 0)
, parms = list(split = 'information', prior = c(0.5, 0.5) )
)
rpart.plot(fit_tf, type = 1, extra = 1, roundint = FALSE)