任何人都知道我收到此错误的原因?属性“Kön”实际上在训练文件中称为“Kön”。我没有在培训文件中列出名称训练的专栏。
ctrl <- trainControl(method = "repeatedcv", number = 10, savePredictions =
TRUE)
mod_fit <- train(as.factor(training$Riskdrickare)~., data=training, method="glm",family="binomial", trControl = ctrl, tuneLength = 5)
Error: Unknown columns 'training', '<U+FEFF>Kön'
In addition: There were 11 warnings (use warnings() to see them)
我想在之后运行此代码:
pred = predict(mod_fit, newdata=test)
confusionMatrix(data=pred, as.factor(test$Riskdrickare))
警告声明:
Warning messages:
1: In train.default(x, y, weights = w, ...) :
You are trying to do regression and your outcome only has two possible values Are you trying to do classification? If so, use a 2 level factor as your outcome column.
2: glm.fit: fitted probabilities numerically 0 or 1 occurred
3: glm.fit: fitted probabilities numerically 0 or 1 occurred
4: glm.fit: fitted probabilities numerically 0 or 1 occurred
5: glm.fit: fitted probabilities numerically 0 or 1 occurred
6: glm.fit: fitted probabilities numerically 0 or 1 occurred
7: glm.fit: fitted probabilities numerically 0 or 1 occurred
8: glm.fit: fitted probabilities numerically 0 or 1 occurred
9: glm.fit: fitted probabilities numerically 0 or 1 occurred
10: glm.fit: fitted probabilities numerically 0 or 1 occurred
11: glm.fit: fitted probabilities numerically 0 or 1 occurred
12: glm.fit: fitted probabilities numerically 0 or 1 occurred
列名是:
KönÅlderFationalitetFakultet Riskdrickare Terminer Omtenta SektionsaktivstudieTimTräningFrysmatFrukostVeganSömnIcondator dAlc wAlc FamRel fHealth mhealth smoke fSize fTog pStudEvent schemUnd drickStudenEvenfritidVänFritidTid
它们包括数值和分类值。
可重现的示例是此分配的等效数据集。
如果我申请as.factor(Riskdrickare)
,那么第一个错误就会消失,但其余错误仍然存在。
解决: 通过将编码设置为Ansi并删除所有字母'å'。 colummn名称中的'ä'和'ö'删除了错误消息。