Pages: [1]
  Print  
Author Topic: Problem with the Execute-Script-Operator  (Read 387 times)
Thrhw31
Newbie
*
Posts: 2


« on: October 02, 2013, 08:32:30 AM »

Hey,

I'm trying to generate an attribute Y in a moving sum from another attribute X:

Y(1) = X(1)

for i = 2 ... length(X) {

Y(i) = X(i) + Y(i-1)

}

The Result should look like this:

XY
11
01
01
12
02

I do not found a possibility to do this in Rapidminer and therefore I used the Execute-Script-Operator. Unfortunately I have nearly no experience in Java/Groovy Sad The problem with my script is that it overwrites my input attribute X. I would be very grateful if someone have a look on the code below.

Greetings from Germany

Code:
import com.rapidminer.example.table.NumericalAttribute;
import com.rapidminer.tools.Ontology;

ExampleSet input= input[0];
Attributes all_attributes = input.getAttributes();
Attribute bool_attrib = all_attributes.get("X");
Attribute target = AttributeFactory.createAttribute("Y", Ontology.INTEGER)

target.setTableIndex(bool_attrib.getTableIndex());
all_attributes.addRegular(target);
ExampleTable bool_tbl = input.getExampleTable();

for (int i = 0; i < bool_tbl.size(); i++) {

DataRow tmp_DataRow = bool_tbl.getDataRow(i);
if (i == 0)
{
tmp_DataRow.set(target, tmp_DataRow.get(bool_attrib));
}

if (i != 0)
{
tmp_DataRow.set(target, tmp_DataRow.get(bool_attrib) + bool_tbl.getDataRow(i-1).get(target));
}
}
return (input);
« Last Edit: October 02, 2013, 08:41:15 AM by Thrhw31 » Logged
Marius
Administrator
Hero Member
*****
Posts: 1794



WWW
« Reply #1 on: October 02, 2013, 01:41:19 PM »

Hi,

what you need is the Integrate operator from the Value Series extension. This will get the job done without any coding Smiley

Best regards,
Marius
Logged

Please add [SOLVED] to the topic title when your problem has been solved! (do so by editing the first post in the thread and modifying the title)
Please click here before posting.
Pages: [1]
  Print  
 
Jump to: