【问题标题】:Trouble creating Naive Bayes classifier using RWeka使用 RWeka 创建朴素贝叶斯分类器时遇到问题
【发布时间】:2019-09-03 09:57:48
【问题描述】:

我正在尝试通过 RWeka 创建一个 NB 分类器,它返回一个变量类型错误。

我有以下变量:

dtm_df.train 作为包含以下内容的data.frame

      ask check state
1_10    0     1   bad
1_100   1     0   bad
1_11    2     1  good
1_13    0     0   bad
1_14    0     0  good
1_15    0     1   bad
1_16    0     1  good
1_17    0     0   bad
1_19    0     0   bad
1_2     2     0   bad

class.formula 的公式包含:state ~ ask + check

使用时

NB <- make_Weka_classifier("weka/classifiers/bayes/NaiveBayes")
classifier <- NB(class.formula ~ ., dtm_df.train)

返回:

Error in model.frame.default(formula = class.formula ~ ., data = dtm_df.train) : object is not a matrix

将数据参数dtm_df.train 转换为矩阵不起作用,因为它需要一个data.frame。

尝试时:

classifier <- NB(class.formula ~ ., dtm_df.train)

返回

Error in .jcall(o, "Ljava/lang/Class;", "getClass") : 
  weka.core.UnsupportedAttributeTypeException: weka.classifiers.bayes.NaiveBayes: Cannot handle string class!

【问题讨论】:

    标签: r dataframe matrix formula rweka


    【解决方案1】:

    发现原因其实是train setdtm_df.train中state列的格式。

    解决方案是通过以下方式将该列转换为因子:

    dtm_df.train$state &lt;- as.factor(dtm_df.train$state)

    【讨论】:

      猜你喜欢
      • 2017-01-10
      • 2017-08-30
      • 2012-04-01
      • 2013-12-02
      • 2015-08-27
      • 2018-02-06
      • 2016-08-25
      • 2017-04-19
      相关资源
      最近更新 更多