简体   繁体   English

我在 RI 中收到一条警告消息不明白

[英]I'm getting a warning message in R I don't understand

** When I train my SVM models I get this warning message: ** 当我训练我的 SVM 模型时,我收到以下警告消息:

Warning message: In .local(x, ...): Variable(s) `' constant.警告消息:在 .local(x, ...): Variable(s) `' 常量。 Cannot scale data.无法缩放数据。

Could someone shine some light on this warning?有人可以对这个警告有所了解吗? Is this something I should be concerned with?这是我应该关心的事情吗? I was thinking the warning maybe because of my dummy variable coding I did.我在想警告可能是因为我所做的虚拟变量编码。 If so, does anyone know a way around this warning message?如果是这样,有没有人知道解决此警告消息的方法? Thanks for y'all's time!谢谢你们的时间! ** **

# importing libraries
library(tidyverse)
library(caret)

# importing the data and changing data types ----
loan <- read_csv("loan_data.csv", col_types = cols(
    credit.policy    = col_factor(),
    inq.last.6mths = col_factor(),
    delinq.2yrs    = col_factor(),
    pub.rec        = col_factor(),
    not.fully.paid = col_factor(),
    purpose        = col_factor()
))

# dummy coding purpose column for SVM models
loan_dum <- loan %>% 
    fastDummies::dummy_cols(select_columns = "purpose",
                            remove_first_dummy  = TRUE,
                            remove_selected_columns = TRUE)
loan_dum %>% View()

# Checking classes of new dummy variables 
loan_dum %>% glimpse()

# Changing the data type of new dummy variables from int to factors
loan_dum <- loan_dum %>% 
    mutate(
        purpose_credit_card      = as.factor(purpose_credit_card),
        purpose_all_other        = as.factor(purpose_all_other),
        purpose_home_improvement = as.factor(purpose_home_improvement),
        purpose_small_business   = as.factor(purpose_small_business),
        purpose_major_purchase   = as.factor(purpose_major_purchase),
        purpose_educational      = as.factor(purpose_educational)
    )
loan_dum %>% glimpse()



# standardizing continuous values
loan_dum_stand <- loan_dum %>% 
    mutate(
        int.rate          = as.vector(scale(int.rate,center = TRUE,scale = TRUE)),
        installment       = as.vector(scale(installment,center = TRUE,scale = TRUE)),
        log.annual.inc    = as.vector(scale(log.annual.inc,center = TRUE,scale = TRUE)),
        dti               = as.vector(scale(dti,center = TRUE,scale = TRUE)),
        fico              = as.vector(scale(fico,center = TRUE,scale = TRUE)),
        days.with.cr.line = as.vector(scale(days.with.cr.line,center = TRUE,scale = TRUE)),
        revol.bal         = as.vector(scale(revol.bal,center = TRUE,scale = TRUE)),
        revol.util        = as.vector(scale(revol.util,center = TRUE,scale = TRUE))
    )
loan_dum_stand %>% view()


# splitting the data into train test ----
set.seed(123)
trainIndexDum <- createDataPartition(loan_dum_stand$not.fully.paid,p = 0.70,list = FALSE,times = 1)
loan_dum_train <- loan_dum_stand[trainIndexDum,]
loan_dum_test  <- loan_dum_stand[-trainIndexDum,]

loan_dum_train %>% glimpse()



#  SVM model with default settings ----
####################################################################################
# Runing model building in parallel
cl <- makePSOCKcluster(10)
registerDoParallel(cl)


# fitting svm model with radial kernel no tuning 
set.seed(123)
svm_model_radial <- train(
    form = not.fully.paid ~.,
    data = loan_dum_train,
    method = "svmRadial"
)
svm_model_radial
plot(svm_model_radial)

此错误通常是由于您的训练数据中可能有一列具有常量数据(每行中的值相同),因此,如果变量是常量,则无法将其缩放到单位方差(和零均值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM