按ID分类(Classification in R by ID)

出于性能RandomForestSRC ,我一直试图在R中使用RandomForestSRC软件包进行分类。

在这种特殊情况下,我有以下示例data.frame,其中Y是分类因子c(“X”,“Y”,“Z”),ID表示这些项目在同一个包中组合在一起,并且它们我有其他变量会告诉我,如果结果应该是X,Y或Z:

y    ID    x1    x2    x3    ...

X    01    AA    BB    CC    ...
X    01    AA    BB    DD    ...
X    01    AA    FF    EE    ...
Y    02    AA    BB    CC    ...
Y    02    AA    BB    EE    ...
Z    03    AA    FF    CC    ...
Z    03    AA    FF    EE    ...
...  ...   ...   ...   ...   ...

在对算法进行训练之后,它成功地给了我以下结果,每个单独项目的准确度都很高,但没有按照包ID对项目进行分组:

y    ID    x1    x2    x3    ...

Y    01    AA    BB    CC    ...
X    01    AA    BB    DD    ...
Z    01    AA    FF    EE    ...
Y    02    AA    BB    CC    ...
Y    02    AA    BB    EE    ...
Z    03    AA    FF    CC    ...
Z    03    AA    FF    EE    ...
...  ...   ...   ...   ...   ...

包裹分类的规则应该如下:

  1. 如果至少有一个项目被分类为X,那么整个包装应该是X;

  2. 如果在同一包装中只有Y和Z,应将包装分类为Y;

  3. 如果包装中只有Z件商品,则整个包装应分类为Z.

因此,为了分类目的,包装上的重量应该是X> Y> Z。

我试着用算法给出的公式,使用如下的东西:

rf <- rfsrc(y ~ ., data = model, method = "class")
rf <- rfsrc(y ~ ID %in% (x1+x2+x3+...), data = model, method = "class")
rf <- rfsrc(y ~ (x1+x2+x3+...) / ID, data = model, method = "class")

然而,似乎没有什么效果,并且有时会降低单个项目的准确性。 我曾经考虑过使用第一个结果作为算法第二次迭代的模型,但是我无法真正了解如何到达那里。

我应该放弃使用随机森林进行分类,并尝试使用其他算法? 也许nneth2o能为我工作? 我对数据挖掘和预测算法完全不熟悉,请耐心等待。


I've been trying to do some classification in R, using the RandomForestSRC package, for performance's sake.

In this particular case, I have the following example data.frame, where Y is the classification factor c("X","Y","Z"), ID means that the items are grouped together in the same package, and them I have other variables that will tell me if the result should be X, Y or Z:

y    ID    x1    x2    x3    ...

X    01    AA    BB    CC    ...
X    01    AA    BB    DD    ...
X    01    AA    FF    EE    ...
Y    02    AA    BB    CC    ...
Y    02    AA    BB    EE    ...
Z    03    AA    FF    CC    ...
Z    03    AA    FF    EE    ...
...  ...   ...   ...   ...   ...

After training the algorithm, it successfully gives me the following results, with a great % of accuracy for each individual item, but without grouping the items by package ID:

y    ID    x1    x2    x3    ...

Y    01    AA    BB    CC    ...
X    01    AA    BB    DD    ...
Z    01    AA    FF    EE    ...
Y    02    AA    BB    CC    ...
Y    02    AA    BB    EE    ...
Z    03    AA    FF    CC    ...
Z    03    AA    FF    EE    ...
...  ...   ...   ...   ...   ...

The rules for the package classification should be the following:

  1. If at least one of the items is classified as X, the whole package should be X;

  2. If there are only Y and Z in the same package, the package should be classified as Y;

  3. If there are only Z items in the package, them the whole package should be classified as Z.

Therefore, the weight on the package should be X > Y > Z for classification purpose.

I've tried fiddling with the formulae given to the algorithm, using things like:

rf <- rfsrc(y ~ ., data = model, method = "class")
rf <- rfsrc(y ~ ID %in% (x1+x2+x3+...), data = model, method = "class")
rf <- rfsrc(y ~ (x1+x2+x3+...) / ID, data = model, method = "class")

However, nothing seems to work really well, and sometimes lowering the accuracy for individual items. I've thought about predicting by layers, using the first result as the model for the second iteration of the algorithm, but I couldn't really find out how to get there.

Should I just give up using random forest for classification, and try some other algorithm altogether? Could maybe nnet, or h2o work for me? I am rather new to data mining and prediction algorithms altogether, so please bear with me.


原文:https://stackoverflow.com/questions/43696912
2023-06-02 11:06

满意答案

关于

public void PaintComponent(Graphics g){
    g.setColor(Color.BLUE);
    g.fillRect(0,0,30,30);
}

明白

PaintComponent != paintComponent

一定要使用@Override注释来让你知道你是什么时候或者不是在重写你认为你是的方法。

正确的方法看起来像这样:

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);  // don't forget this!
    g.setColor(Color.BLUE);
    g.fillRect(0, 0, 30, 30);
}

另外,如果你想替换原来的JPanel,那么使用CardLayout来帮助你轻松做到这一点。 否则,在交换容器中的组件后,必须确保自己调用revalidate()repaint()

例如,

    @Override
    public void mouseClicked(MouseEvent event) {
        statusbar.setText(String.format("Clicked at %d,%d", event.getX(), event.getY()));
        remove(mousepanel);
        DrawShapes shapes = new DrawShapes();
        getContentPane().add(shapes, BorderLayout.CENTER);
        getContentPane().revalidate();
        getContentPane().repaint();
    }

regarding

public void PaintComponent(Graphics g){
    g.setColor(Color.BLUE);
    g.fillRect(0,0,30,30);
}

Understand that

PaintComponent != paintComponent

Be sure to use the @Override annotation to let you know when you are or aren't overriding methods that you think you are.

The correct method would look something like:

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);  // don't forget this!
    g.setColor(Color.BLUE);
    g.fillRect(0, 0, 30, 30);
}

Also, if you want to replace the original JPanel, then use a CardLayout to help you easily do this. Otherwise you must be sure to call revalidate() and repaint() yourself after swapping components in a container.

e.g.,

    @Override
    public void mouseClicked(MouseEvent event) {
        statusbar.setText(String.format("Clicked at %d,%d", event.getX(), event.getY()));
        remove(mousepanel);
        DrawShapes shapes = new DrawShapes();
        getContentPane().add(shapes, BorderLayout.CENTER);
        getContentPane().revalidate();
        getContentPane().repaint();
    }

相关问答

更多

JFrame Java setColor和fillRect保持空白?(JFrame Java setColor and fillRect staying Blank?)

更换 public void run() { while(running);{ update(); render(); } 通过 public void run() { while(running){ update(); render(); } 由于while(跑步); 它没有在循环内执行其他的stetement。 replace public void run() { while(running);{ ...

帧fillRect setColor无法正常工作(Frame fillRect setColor not working)

你的方法是不可扩展的。 这是一张西蒙说的GUI,我把它放在一起。 它显示前10个计算机序列,一次一个。 首先,我创建了GUI。 我在扩展的JPanel上绘制圆弧段。 我在游戏模型中创建并保留有关游戏的信息。 通过将模型与视图和控制器分开,我可以一次关注游戏的一部分。 这是代码。 我将所有类放在一起,以便更容易粘贴代码。 您应该将类分成自己的文件。 package com.ggl.testing; import java.awt.Color; import java.awt.Dimension; ...

Java 2D图形BufferedImage FillRect问题(Java 2D Graphics BufferedImage FillRect issue)

在这里看看这个答案。 你必须把window.setResizeable(false); 在 window.pack(); 之前 window.pack(); 。 这应该解决它。 Have a look at this answer here. You have to put window.setResizeable(false); before window.pack();. This should fix it.

Java JFrame gui - 为什么不显示按钮?(Java JFrame gui - Why won't the buttons show up?)

人们告诉我使用setBounds Dont! 布局管理员是正确的选择。 你的问题是你添加你的按钮到“p”面板,但你永远不会把它添加到(p面板)到contentPane people are telling me to use setBounds Dont! Layout managers are the correct way to go. Your problem is you add your buttons to the "p" panel, but you never add it (p ...

jFrame不显示图像(jFrame doesn't show the image)

paintcomponent()没有paintcomponent()方法,因为它不是jcomponent而是容器。你可以创建一个面板并覆盖paintcomponent方法然后将setcontentpane的jframe设置为该面板 例 public class panel extends JPanel { Image img; @Override protected void paintComponent(Graphics g) { super.pain...

为什么fillRect命令不会显示在我的JFrame上?(Why won't the fillRect command show up on my JFrame?)

关于 public void PaintComponent(Graphics g){ g.setColor(Color.BLUE); g.fillRect(0,0,30,30); } 明白 PaintComponent != paintComponent 一定要使用@Override注释来让你知道你是什么时候或者不是在重写你认为你是的方法。 正确的方法看起来像这样: @Override protected void paintComponent(Graphics g) { ...

JFrame无法显示(JFrame not displaying)

我没有查看所有代码,但是您发布的类中存在一些基本缺陷: 创建b的新实例与创建空JPanel相同。 当然,由于面板是空的,你什么都看不到。 首先填充面板然后添加它。 使用单独的Thread填充b面板违反了Swing线程规则。 您应该只访问/修改/ ...在事件调度线程上摆动组件。 有关更多信息,请参阅Swing并发指南 在EDT上使用Thread.sleep将阻止您的UI。 从来没有这样做过。 如果您想要某种动画,请改用javax.swing.Timer类。 此类旨在定期更新您的UI。 不要覆盖pa...

为什么我的JFrame不会画画?(Why won't my JFrame draw?)

尝试从JFrame类而不是Canvas类扩展: public class Main extends JFrame implements ... 你还必须编辑你的构造函数,然后像: public Main() { super("Clicker"); addMouseListener(this); addKeyListener(this); setExtendedState(JFrame.MAXIMIZED_BOTH); setDefaultCloseO...

JList不会出现在JFrame上(JList won't show up on JFrame)

因为您使用BorderLayout但不设置ScrollPane 。 因此, mousePanel将位于ScrollPane 。 尝试这个 add(new JScrollPane(list), BorderLayout.WEST); Because you use BorderLayout but don't set position for ScrollPane. So, mousePanel will lie on ScrollPane. Try this add(new JScrollPan...

为什么JFrame不会显示输出?(Why won't the JFrame display the output?)

你忘了这个方法 setBounds(x,y,width,height); 实际上setBounds可以分为2种方法 setSize(w,h); setLocation(x,y); you forget the method setBounds(x,y,width,height); actually setBounds can be dividen in 2 methods setSize(w,h); setLocation(x,y);

相关文章

更多

nutch与起点R3集成之笔记(一)

百度、google帮我们找Internet的信息,但对于一个行业内部网(intranet)来说,百度、 ...

hibernate id 生成策略及主要使用方法

hibernate主键策略生成器 hibernate提供多种主键生成策略,有点是类似于JPA,有的是h ...

MongoDB _id和ObjectId详解

在创建一个文档的时候,会生成一个_id,id的默认类型是ObjectId,如: &gt; db. ...

solr required field: id

为了和以前的程序兼容,在solr建立索引的时候,将id设为gid,结果在建立索引时候出现如下错误: o ...

js 通过td的id值 如何拿到tr的id值?

有以下代码:&lt;tr id=&quot;bb&quot;&gt;&lt;td id=&quot;a ...

nutch与起点R3集成之笔记(二)

在nutch与起点R3集成之笔记(一)中介绍了在起点R3中添加nutch要用到的索引字段,上述字段建好 ...

nutch与起点R3集成之笔记(四)

通过“nutch与起点R3集成之笔记(一、二、三)”中的步骤,我们可以建立起一个行业内部网的搜索引擎, ...

html中一个div的id是“1:222”的话,怎么利用id给它定义css啊?

如 &lt;style&gt; #1:2{ height:100px; width:100px ...

mysql in根据查询id排序

mysql in根据查询时,返回结果是自行排序的​,如果要按照我们查询的ID进行排序,要用到order ...

R语言实战视频教程-尚学堂视频教程

主讲老师系985高校计算机博士,有丰富的大数据、云计算的教学和实战经验。 作为当前在世界范围内最受欢迎 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本