【问题标题】:How to fix "$ operator is invalid for atomic vectors" error in RStudio如何修复 RStudio 中的“$ 运算符对原子向量无效”错误
【发布时间】:2019-05-01 07:07:39
【问题描述】:

我正在尝试在我的平衡(使用 SMOTE)训练数据集上运行广义线性模型,但是当我运行以下 R 代码时,我收到一条错误消息

“错误:$ 运算符对原子向量无效”

真的不知道是什么意思。任何帮助将不胜感激!

model.glm<- train(Accident_Severity ~ ., data= smote_train, 
                  method = "glm",metric = RMSE, trControl= "ctrl")

【问题讨论】:

  • smote_train的结构是什么?
  • 这是一个包含1个因子变量(2个级别)和45个数值变量的数据框。
  • 抱歉 - 我的意思是请通过显示 str() 函数的输出来向我们展示 smote_train 的结构。不显示所有变量的截断输出是可以的,但不是首选。

标签: r glm


【解决方案1】:

您错误地指定了train 函数的选项。这可能对你有用:

model.glm <- train(Accident_Severity ~ ., data = smote_train, 
                   method = "glm", metric = "Kappa", trControl= trainControl())

在您的原始函数调用中,选项 trControl = "ctrl" 导致您收到错误消息。但是,选项 metric = "RMSE" 也可能不适用于您的数据(我假设您的变量 Accident_Severity 是一个因子变量,并且您正在尝试拟合分类模型)。

【讨论】:

    猜你喜欢
    • 2015-10-02
    • 1970-01-01
    • 2020-06-21
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多