按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 ... ... ... ... ... ... ...
包裹分类的规则应该如下:
如果至少有一个项目被分类为X,那么整个包装应该是X;
如果在同一包装中只有Y和Z,应将包装分类为Y;
如果包装中只有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")
然而,似乎没有什么效果,并且有时会降低单个项目的准确性。 我曾经考虑过使用第一个结果作为算法第二次迭代的模型,但是我无法真正了解如何到达那里。
我应该放弃使用随机森林进行分类,并尝试使用其他算法? 也许
nnet
或h2o
能为我工作? 我对数据挖掘和预测算法完全不熟悉,请耐心等待。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:
If at least one of the items is classified as X, the whole package should be X;
If there are only Y and Z in the same package, the package should be classified as Y;
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
, orh2o
work for me? I am rather new to data mining and prediction algorithms altogether, so please bear with me.
原文:https://stackoverflow.com/questions/43696912
最满意答案
关于
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()
andrepaint()
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 ...
-
jFrame不显示图像(jFrame doesn't show the image)[2023-05-08]
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 ...
-
JFrame无法显示(JFrame not displaying)[2021-07-08]
我没有查看所有代码,但是您发布的类中存在一些基本缺陷: 创建b的新实例与创建空JPanel相同。 当然,由于面板是空的,你什么都看不到。 首先填充面板然后添加它。 使用单独的Thread填充b面板违反了Swing线程规则。 您应该只访问/修改/ ...在事件调度线程上摆动组件。 有关更多信息,请参阅Swing并发指南 在EDT上使用Thread.sleep将阻止您的UI。 从来没有这样做过。 如果您想要某种动画,请改用javax.swing.Timer类。 此类旨在定期更新您的UI。 不要覆盖paint方法 ... -
为什么我的JFrame不会画画?(Why won't my JFrame draw?)[2022-09-25]
尝试从JFrame类而不是Canvas类扩展: public class Main extends JFrame implements ... 你还必须编辑你的构造函数,然后像: public Main() { super("Clicker"); addMouseListener(this); addKeyListener(this); setExtendedState(JFrame.MAXIMIZED_BOTH); setDefaultCloseOperat ... -
JList不会出现在JFrame上(JList won't show up on JFrame)[2022-07-24]
因为您使用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);