Transforming ExampleSet into 2D double Array

milkov
milkov New Altair Community Member
edited November 5 in Community Q&A
Hello,

I have a question that you will not probably like to hear, but it would really help me with my work. I'm transforming a feature selection method into a RapidMiner operator and right now I have about 3,5k lines of code. The problem is, that this method expects a 2D double array input.

My question is - is there an easy way to transform ExampleSet into 2D double array and vica versa?

Thank you for your help,
Milan

Answers

  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    one possible way:

    ExampleSet resultSet = (ExampleSet) result.getElementAt(0);

    Attributes attributes = resultSet.getAttributes();
    Iterator<Attribute> attrIterator = attributes.allAttributes();
    double[][] array2D = new double[attributes.allSize()][resultSet.getExampleTable().size()];
    int attrIndex = 0;
    int exaIndex = 0;
    while (attrIterator.hasNext()) {
    Attribute att = attrIterator.next();
    ExampleReader exampleReader = new SimpleExampleReader(resultSet.getExampleTable().getDataRowReader(), resultSet);
    exaIndex = 0;
    while (exampleReader.hasNext()) {
    array2D[attrIndex][exaIndex] = exampleReader.next().getValue(att);
    exaIndex++;
    }
    attrIndex++;
    }
    Regards,
    Marco