当我将数据加载到rds模型中时,它不会将二进制变量转换为因数

时间:2019-04-16 00:44:49

标签: r

  

错误:变量'Same_State','Agent_RegisteredOnWeb','Agent_EnrolledInEForms','Agent_PendingPolicyRequestEForm','Agent_RegisteredForCancelListRep','Agent_EnrolledInCreditProgram','Agent_DownPaymentVorCC','B'

我制作了一个RDS文件,并试图将新数据加载到其中,但是即使代码中包含类转换器,它也不会将新数据转换为因子。

#MODEL
data <- read.csv(file.choose(), header=T)

#Converts cancelled into Y vs N
data[data$Cancelled == 0,]$Cancelled <- "N"
$data[data$Cancelled == 1,]$Cancelled <- "Y"
data$Cancelled <- as.factor(data$Cancelled)

#Cleans up data and formats data into desired class
data$Agent_ID <- as.factor(data$Agent_ID)
data$Borrower_ID  <- as.factor(data$Borrower_ID )
data$Same_State  <- as.factor(data$Same_State )
data$Borrower_EnrolledInEForms <- 
as.factor(data$Borrower_EnrolledInEForms)


#GRADING RUBRIC
df_test <- read.csv(file.choose(), header = T)
target_test <- as.factor(df_test$Cancelled)

# 2) Load model from .rds file
model <- readRDS(file = "my_model.rds")

# 3) Fit model to your test data for prediction
pred <- predict(model, df_test, type = 'response')
  

错误:变量'Same_State','Agent_RegisteredOnWeb','Agent_EnrolledInEForms','Agent_PendingPolicyRequestEForm','Agent_RegisteredForCancelListRep','Agent_EnrolledInCreditProgram','Agent_DownPaymentViaCC','Borrower_RegisteredEd','Borrower_Registereded'

我希望将数据转换为因子。

0 个答案:

没有答案