Java: How can I assemble/create a single instance for classification using a Weka generated model?

故事扮演 提交于 2020-01-01 19:20:15

问题


I've been searching for an answer to this for a while to no avail.

First a bit of background: I'm trying to create an AI for robocode using Weka. I'm first logging the required data from a manual robot to an ARFF file, this is working as it should.

This data is then processed this using Weka and a model created, I'm then saving this file.

I can successfully import the model and classify a dataset that has been imported from another arff file and use the results.

What I want to do now is every time the game status changes is assemble an instance and classify it, to decide for example which way to move etc. using my previously saved model.

I've tried to look it up on the wiki: http://weka.wikispaces.com/Programmatic+Use and this ibm tutorial: http://www.ibm.com/developerworks/opensource/library/os-weka3/ to name a couple, I've also been looking through the APIs but that hasn't given me much to go on.

Much of what I've tried is deprecated, for example creating a prototype with the attributes and fast vectors then creating an empty dataset. Then creating a new instance with the required values using somthing like inst.setvalue(attrib, value) and adding it to the dataset.

Also what about the class index, or the attribute I'm predicting, in the instance does it have to be null or set to missing or something, as surley I won't know that value as I'm trying to predict it?

So are there any ideas how I can go about this?

any help is greatly appreciated,

Thank you muchly.


回答1:


Managed to find the answer a while ago.

For anyone else having trouble with this basically what you have to do is in the Weka manual included with every download, (its a pdf).

Page 202 onwards in the manual - Section 16.3 "Creating datasets in memory". Follow the steps there and it works perfectly.



来源:https://stackoverflow.com/questions/16450958/java-how-can-i-assemble-create-a-single-instance-for-classification-using-a-wek

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!