在R中:is.data.frame(data)中的错误:找不到对象”,C5.0图 [英] in R: Error in is.data.frame(data) : object '' not found, C5.0 plot

查看:1793
本文介绍了在R中:is.data.frame(data)中的错误:找不到对象”,C5.0图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题类似于Stackoverflow上的其他一些问题(此处此处此处),但又相差太大,因此我无法推断这些我的情况的答案。

This question is similar to some other questions on Stackoverflow (here, here and here), but different enough so that I cannot extrapolate those answers to my case.

我有一个函数可以拟合C5.0模型,然后尝试绘制模型。

I have a function in which I fit a C5.0 model and than try to plot the model.

train_d <- globald[train_ind,c(features,21)]
model <- C5.0(binclass ~ .,data=train_d,trials=10)

binclass 是一列我的训练/测试数据中的名称(globald是一个数据框,我在该数据框中用 _ind 索引和列 c(3:12,21),其中列21名为 bin类)。拟合效果很好。但是,当我同时添加行

binclass is a column name in my training/test data (globald is a dataframe from which I subset rows with _ind indices and columns c(3:12,21), where column 21 is named binclass). Fitting works well. However, when I also add the line

plot(model,trial=0)

然后出现以下错误: is.data.frame(data)中的错误:找不到对象'train_d'

then I get the following error: Error in is.data.frame(data) : object 'train_d' not found.

在拟合模型时,如何找到并正确使用 train_d ,但是在绘制时, train_d 找不到地方了吗?并且,关于如何解决此问题的任何建议。

How is it possible that when fitting the model, train_d is found and used correctly, but while plotting, train_d is nowhere to be found? And, any suggestion of how to solve this issue. Namespaces in [r] remain a mystery to me.

一个最小的运行示例如下:

A minimal running example is the following:

f <- function(){
    library(C50)
    set.seed(1)
    class = c(1,2)
    d <- data.frame(feature1 = sample(1:10,10,replace=TRUE), feature2 = 1:10, binclass = class)
    d$binclass <- as.factor(d$binclass)
    model <- C5.0(binclass ~ ., data=d)
    plot(model)   
}

调用 f()会导致以下错误: is.data.frame(data)中的错误:找不到对象'd'

Calling f() results in the following error: Error in is.data.frame(data) : object 'd' not found

编辑:
根据MrFlick的回答,似乎是导致此问题的原因是C5.0代码中的错误。 Pascal和MrFlick指出了一些解决方法。

As per the answer from MrFlick, it seems that the cause of this problem is a bug in the C5.0 code. There are some workarounds are indicated by Pascal and MrFlick.

推荐答案

涉及到代码中似乎确实存在错误。在适当的环境中评估命令。问题似乎出在 C50 :: model.frame.C5.0 函数中。我能找到的最干净的解决方法是在模型中添加 terms 属性。这将有助于封装函数环境。

There does appear to be a bug in the code when it comes to evaluating the command in the proper environment. The problem appears to be in the C50::model.frame.C5.0 function. The "cleanest" work around I could find was to add a terms property to your model. This will help encapsulate the function environment.

f <- function(){
    library(C50)
    set.seed(1)
    class = c(1,2)
    d <- data.frame(feature1 = sample(1:10,10,replace=TRUE), feature2 = 1:10, binclass = class)
    d$binclass <- as.factor(d$binclass)
    model <- C5.0(binclass ~ ., data=d)
    model$terms <- eval(model$call$formula)   #<---- Added line
    plot(model)   
}

这篇关于在R中:is.data.frame(data)中的错误:找不到对象”,C5.0图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆