** When I train my SVM models I get this warning message:
Warning message: In .local(x, ...): Variable(s) `' constant. 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)
此错误通常是由于您的训练数据中可能有一列具有常量数据(每行中的值相同),因此,如果变量是常量,则无法将其缩放到单位方差(和零均值)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.