微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WEKA:从变量创建实例

如何解决WEKA:从变量创建实例

我想以编程方式创建一个数据集,并提供一些变量。具体来说,在下面的示例中,我有一个实数属性和两个分类属性。有人可以帮我替换我的注释,并在其中添加将变量添加为数据集实例的代码行吗?

// Now I do standard setup procedure.
ArrayList<Attribute> attributes = new ArrayList<Attribute>();
attributes.add(new Attribute("age "));  // @ATTRIBUTE age   REAL
attributes.add(new Attribute("gender ")); // @attribute gender {F,M}
attributes.add(new Attribute("class ")); // @ATTRIBUTE class {True,False}

Instances dataset = new Instances("TestInstances",attributes,1000);
dataset.setClassIndex(dataset.numAttributes() - 1);



//Now I want to add instances of my variables
int age1=1;
String gender1= "F";
String class1= "True";
//what shall I write here to add age1,gender1 and class1 to dataset

int age2=10;
String gender2= "M";
String class2= "True";
// what shall I write here to add age2,gender2 and class2 to dataset

int age3=20;
String gender3= "F";
String class3= "False";
// what shall I write here to add age3,gender3 and class3 to dataset

// Now I kNow how to use dataset … e.g.,RandomForest tree = new RandomForest();    tree.buildClassifier(dataset); etc. etc.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。