我現在跑的這支程式只能跑出sensitivity、specificity以及accuracy的結果,我想要讓他再加上ROC或AUC的數值,請問各位大神可以怎麼寫呢?謝謝幫忙~
library(xgboost)
library(caret)
library(Matrix)
getwd()
setwd("/Users/tssc7/Desktop/meeting/balance")
trainset <- read.csv("d3_dep_balance_train.csv")
testset <- read.csv("d3_dep_imb_test.csv")
#1.資料格式轉換
#1-1自變量轉為matrix
traindata1 <- data.matrix(trainset[,c(3:106)])
#1-2應變量
train_y <- trainset[,2]
#1-3自辯量、應變量組合list
traindata <- list(data = traindata1,label = trainset[,2])
#1-4建構模型需要的gb.DMatrix
dtrain <- xgb.DMatrix(data = traindata$data, label = traindata$label)
#2.測試資料同上
testset1 <- data.matrix(testset[,c(3:106)])
test_y <- testset[,2]
testset <- list(data = testset1, label = testset[,2])
dtest <- xgb.DMatrix(data = testset$data, label = testset$label)
#3.建構模型
model_xgb <- xgboost(data = dtrain,booster = 'gbtree',
max_depth = 1,
eta = 0.3,
num_class = 2,
subsample = 0.5,
nround = 20)
#4.模型預測
pre <- predict(model_xgb,newdata = dtest)
#5.模型評估
library(caret)
xgb.cf <- caret::confusionMatrix(as.factor(pre),as.factor(test_y))
xgb.cf