首页 \ 问答 \ 按ID分类(Classification in R by ID)

按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();
    }

相关问答

更多
  • 更换 public void run() { while(running);{ update(); render(); } 通过 public void run() { while(running){ update(); render(); } 由于while(跑步); 它没有在循环内执行其他的stetement。 replace public void run() { while(running);{ ...
  • 你的方法是不可扩展的。 这是一张西蒙说的GUI,我把它放在一起。 它显示前10个计算机序列,一次一个。 首先,我创建了GUI。 我在扩展的JPanel上绘制圆弧段。 我在游戏模型中创建并保留有关游戏的信息。 通过将模型与视图和控制器分开,我可以一次关注游戏的一部分。 这是代码。 我将所有类放在一起,以便更容易粘贴代码。 您应该将类分成自己的文件。 package com.ggl.testing; import java.awt.Color; import java.awt.Dimension; impor ...
  • 在这里看看这个答案。 你必须把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.
  • 人们告诉我使用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 panel ...
  • paintcomponent()没有paintcomponent()方法,因为它不是jcomponent而是容器。你可以创建一个面板并覆盖paintcomponent方法然后将setcontentpane的jframe设置为该面板 例 public class panel extends JPanel { Image img; @Override protected void paintComponent(Graphics g) { super.paintComp ...
  • 关于 public void PaintComponent(Graphics g){ g.setColor(Color.BLUE); g.fillRect(0,0,30,30); } 明白 PaintComponent != paintComponent 一定要使用@Override注释来让你知道你是什么时候或者不是在重写你认为你是的方法。 正确的方法看起来像这样: @Override protected void paintComponent(Graphics g) { sup ...
  • 我没有查看所有代码,但是您发布的类中存在一些基本缺陷: 创建b的新实例与创建空JPanel相同。 当然,由于面板是空的,你什么都看不到。 首先填充面板然后添加它。 使用单独的Thread填充b面板违反了Swing线程规则。 您应该只访问/修改/ ...在事件调度线程上摆动组件。 有关更多信息,请参阅Swing并发指南 在EDT上使用Thread.sleep将阻止您的UI。 从来没有这样做过。 如果您想要某种动画,请改用javax.swing.Timer类。 此类旨在定期更新您的UI。 不要覆盖paint方法 ...
  • 尝试从JFrame类而不是Canvas类扩展: public class Main extends JFrame implements ... 你还必须编辑你的构造函数,然后像: public Main() { super("Clicker"); addMouseListener(this); addKeyListener(this); setExtendedState(JFrame.MAXIMIZED_BOTH); setDefaultCloseOperat ...
  • 因为您使用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 JScrollPane(lis ...
  • 你忘了这个方法 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);

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)