按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(); }
相关问答
更多JFrame Java setColor和fillRect保持空白?(JFrame Java setColor and fillRect staying Blank?)
帧fillRect setColor无法正常工作(Frame fillRect setColor not working)
Java 2D图形BufferedImage FillRect问题(Java 2D Graphics BufferedImage FillRect issue)
Java JFrame gui - 为什么不显示按钮?(Java JFrame gui - Why won't the buttons show up?)
jFrame不显示图像(jFrame doesn't show the image)
为什么fillRect命令不会显示在我的JFrame上?(Why won't the fillRect command show up on my JFrame?)
JFrame无法显示(JFrame not displaying)
为什么我的JFrame不会画画?(Why won't my JFrame draw?)
JList不会出现在JFrame上(JList won't show up on JFrame)
为什么JFrame不会显示输出?(Why won't the JFrame display the output?)
相关文章
更多nutch与起点R3集成之笔记(一)
hibernate id 生成策略及主要使用方法
MongoDB _id和ObjectId详解
solr required field: id
js 通过td的id值 如何拿到tr的id值?
nutch与起点R3集成之笔记(二)
nutch与起点R3集成之笔记(四)
html中一个div的id是“1:222”的话,怎么利用id给它定义css啊?
mysql in根据查询id排序
R语言实战视频教程-尚学堂视频教程
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!