r - 我在 RI 中收到警告消息不理解
问题描述
** 当我训练我的 SVM 模型时,我收到以下警告消息:
警告信息:在 .local(x, ...): Variable(s) `' 常量。无法缩放数据。
有人可以对这个警告有所了解吗?这是我应该关心的事情吗?我在想这个警告可能是因为我做了虚拟变量编码。如果是这样,有人知道解决此警告消息的方法吗?谢谢大家的时间!**
# 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)
解决方案
此错误通常是由于您的训练数据中可能有一列具有恒定数据(每行中的值相同),因此,如果变量是恒定的,则无法将其缩放为单位方差(和零均值)。
推荐阅读
- python - 在堆积条形图中显示每个部分的边界
- java - 带有 Tesseract 的 Tess4j:需要设置哪个参数才能从数字中删除空格
- android-ndk - 使用android opencv4.2.0链接错误ANDROID NDK r18b build lib
- sql - 在每个字符的前面和末尾添加字符
- django - 使用 uWSGI 和 Nginx 在 Django 中的缓冲区大小
- php - 如何发送博览会推送通知以使用 PHP 做出本机反应
- c# - Linux Docker 容器中的退出代码 131
- linux - 无法在 Fedora 上启动机器人 Karel
- python - 如何修改适用于 RGB 图像的函数以使其适用于单色图像?
- azure - 如何从通过代理连接到服务器的逻辑应用程序进行 http 调用