r - 创建数据分区不能正常工作(插入符号包)
问题描述
我正在尝试使用 createDataPartition() 使用训练和测试集制作机器学习模型。我能够为训练集制作一个线性模型,但我似乎无法将新数据拟合到现有模型中,例如数据集的两个主要组成部分。
这是机器学习课程中的一个例子,它给出了一个错误。
library(kernlab); library(caret)
data(spam)
inTrain <- createDataPartition(y=spam$type, p =0.75, list = FALSE)
training <- spam[inTrain,]
testing <- spam[-inTrain,]
#preprocess the training data by log transform for skewed
#variables, and then extract the first two principal components
preProc <- preProcess(log10(training[,-58]+1), method = "pca", pcaComp
= 2)
preProc$rotation
#create a train-dataset based on the prediction of the two PC's
#from the training set
trainPC <- predict(preProc, log10(training[,-58]+1))
#train the 'type' versus all other variables model using a GLM,
#but based on the trainPC dataset, containing the two principal
#components
modelFit <- train(training$type ~ . , method="glm", data = trainPC)
Error in `[.data.frame`(data, , all.vars(Terms), drop = FALSE) :
undefined columns selected
预期的结果是 modelFit 针对 training$type 进行了训练,但使用了新创建的 trainPC 数据集,该数据集是根据预处理数据预测的。
我认为问题在于 trainPC 数据仅包含两台 PC,如果我是正确的,则在训练时无法引用:
train(training$type ~ .
提前致谢!
亚历山大
解决方案
推荐阅读
- stripe-payments - 如何强制 Stripe subscription.trial_will_end 事件在 7 天前而不是 3 天前触发
- c++ - 在其他自定义类的成员函数原型的参数中引用自定义类。如果变成圆形怎么办?
- php - 使用 php.ini-production 和 php.ini-development -> php.ini 会破坏 Kubernetes 环境变量
- ruby-on-rails - Heroku rails 应用程序在本地运行,但在打开时给出应用程序错误代码 H10
- python - BeautifulSoup 检测更改触发器
- python - 如何通过python程序从github检索文件
- javascript - 使用 javascript 将帐单地址复制到送货地址
- c++ - 使用 C++ 递归
- java - 如何使用一个根上下文制作两个 AbstractAnnotationConfigDispatcherServletInitializer?
- python-3.x - 使用python从类中的方法调用@class.method