WEKA: Creating instances from variables

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

WEKA: Creating instances from variables

David
Hi all, I want to programmatically create a dataset given some variables I
have. Specifically, in the example below, I have one real and two
categorical attributes. Could someone help me replacing my red comments, and
adjusting here and there, with the lines of code for adding my variables as
instances of a dataset?


// 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.





--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: WEKA: Creating instances from variables

Michael Hall


> On Oct 6, 2020, at 5:43 AM, David <[hidden email]> wrote:
>
> Hi all, I want to programmatically create a dataset given some variables I
> have. Specifically, in the example below, I have one real and two
> categorical attributes. Could someone help me replacing my red comments, and
> adjusting here and there, with the lines of code for adding my variables as
> instances of a dataset?
>

This might tell you what you need for this…

https://waikato.github.io/weka-wiki/use_weka_in_your_java_code/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html