【问题标题】:How to convert classification results into a leveled factor如何将分类结果转换为水平因子
【发布时间】:2017-03-20 21:51:50
【问题描述】:

我有一个由 0 和 1 组成的“label.csv”文件。

y = read.csv("./data/labels.csv", stringsAsFactors = T)

当我cbindy用数据做分类训练时,出现如下警告:

Warning message:
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.

我想将y 转换为水平因子并将其与特征数据进行cbind 以进行分类。

但是,使用as.factor(y) 会产生以下错误:

Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?

我是否在正确的轨道上解决这个问题?

谢谢。

【问题讨论】:

    标签: r classification type-conversion


    【解决方案1】:

    您的y 变量是一个data.frame。在转换为因子数据类型之前,您需要使用 [[ 将数据框中的第一列作为子集(即使可能只有一列)。

    # convert y to a factor
    y <- as.factor(y[[1]])
    

    然后您应该能够运行您的模型。

    【讨论】:

      猜你喜欢
      • 2015-01-27
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      • 2014-11-14
      相关资源
      最近更新 更多