Options

how to construct exampleSet

happydusthappydust Member Posts: 10 Contributor II
edited November 2018 in Help
How do I construct a exampleSet instance from a data source?(either from a  table or a tree model generated from data)

Thanks!

best
Happydust
Tagged:

Answers

  • Options
    landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531 Unicorn
    Hi,
    do you mean by your own code? Then you could take a look at the "How to extend RapidMiner" tutorial available in our shop. It explains in detail how to create new ExampleSets.

    Greetings,
      Sebastian
  • Options
    GhostriderGhostrider Member Posts: 60 Contributor II
    Here's some code from the RM Tutorial 4.6:

    import com.rapidminer.example.*;
    import com.rapidminer.example.table .*;
    import com.rapidminer.example.set .*;
    import com.rapidminer.tools .Ontology;
    import java.util.*;

    public class CreatingExampleTables {
    public static void main(String [] argv) {
    // create attribute list
    List <Attribute> attributes = new LinkedList<Attribute>();
    for ( int a = 0; a < getMyNumOfAttributes(); a++) {
    attributes.add( AttributeFactory . createAttribute (”att” + a,
    Ontology.REAL));
    }
    Attribute label = AttributeFactory . createAttribute (” label ”, Ontology.NOMINAL));
    attributes.add(label);
    //create table
    MemoryExampleTable table = new MemoryExampleTable(attributes);
    // fill table (here : only real values )
    for (int d = 0; d < getMyNumOfDataRows(); d++) {
    double[] data = new double[attributes.size()];
    for (int a = 0; a < getMyNumOfAttributes(); a++) {
    //fill with proper data here
    data = getMyValue(d, a);
    }
    // maps the nominal classification to a double value
    data[data.length - 1] = label.getMapping().mapString(getMyClassification(d));
    //add data row
    table.addDataRow(new DoubleArrayDataRow(data));
    }
    // create example set
    ExampleSet exampleSet = table.createExampleSet(label);
    }
    }
  • Options
    haddockhaddock Member Posts: 849 Maven
    Hi there,

    A few weeks ago I posted a script to convert association rules to examples, but it has been removed, like a lot of my other posts, very, very, very annoying. Wessel had the same a while back, so at least it isn't personal. Anyways, here is the code, which shows that the 4.6 code for this is the same as the 5.0.
    import com.rapidminer.tools.Ontology;

    import com.rapidminer.operator.learner.associations.*;


    AssociationRules rules = input[0];



    // construct attribute set
    Attribute[] attributes= new Attribute[11];
    attributes[0] = AttributeFactory.createAttribute("Premise", Ontology.STRING);

    attributes[1] = AttributeFactory.createAttribute("Premise Items", Ontology.INTEGER);
    attributes[2] = AttributeFactory.createAttribute("Conclusion", Ontology.STRING);
    attributes[3] = AttributeFactory.createAttribute("Conclusion Items", Ontology.INTEGER);
    attributes[4] = AttributeFactory.createAttribute("Confidence", Ontology.REAL);
    attributes[5] = AttributeFactory.createAttribute("Conviction", Ontology.REAL);
    attributes[6] = AttributeFactory.createAttribute("Gain", Ontology.REAL);
    attributes[7] = AttributeFactory.createAttribute("Laplace", Ontology.REAL);

    attributes[8] = AttributeFactory.createAttribute("Lift", Ontology.REAL);
    attributes[9] = AttributeFactory.createAttribute("Ps", Ontology.REAL);


    attributes[10] = AttributeFactory.createAttribute("Total Support", Ontology.REAL);



    MemoryExampleTable table = new MemoryExampleTable(attributes);
    DataRowFactory ROW_FACTORY = new DataRowFactory(0);

    String[] strings= new String[11];

    for (AssociationRule rule : rules) {
    // construct example data
            strings[0]=rule.toPremiseString();
            strings[1]=rule.premise.size().toString();
            strings[2]=rule.toConclusionString();
            strings[3]=rule.conclusion.size().toString();
            strings[4]=rule.getConfidence().toString();
            strings[5]=rule.getConviction().toString();
            strings[6]=rule.getGain().toString();
            strings[7]=rule.getLaplace().toString();
            strings[8]=rule.getLift().toString();

            strings[9]=rule.getPs().toString();
            strings[10]=rule.getTotalSupport().toString();

            // make and add row
            DataRow row = ROW_FACTORY.create(strings, attributes);
            table.addDataRow(row);
    }

    ExampleSet exampleSet = table.createExampleSet();
    return exampleSet;

  • Options
    fischerfischer Member Posts: 439 Maven
    Hi Haddock and wessel,

    what post are you referring to that was deleted? The only posts we delete are spam posts, and we did that with a few posts that were posted recently. Wessel was one of the reporters, I believe. Maybe we deleted the entire thread rather than only the spam post. I apologize if that happened, it was definitely nothing personal :-)

    Cheers,
    Simon
Sign In or Register to comment.