Options

Transforming ExampleSet into 2D double Array

milkovmilkov Member Posts: 3 Contributor I
edited November 2018 in Help
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
Tagged:

Answers

  • Options
    Marco_BoeckMarco_Boeck Administrator, Moderator, Employee, Member, University Professor Posts: 1,996 RM Engineering
    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
Sign In or Register to comment.