Getting the type of Attribute
seshadotcom
New Altair Community Member
Hi Guys,
I want to write a generic workflow which can discover the type of attributes and change them accordingly on a case by case basis so that I deliver one big chunk of dataset of binomial values to my FP Growth. I did see an operator called GuessTypes but how do I get the related type of an attribute? It seems not to be delivering this in the output port.
Any Idea?
I want to write a generic workflow which can discover the type of attributes and change them accordingly on a case by case basis so that I deliver one big chunk of dataset of binomial values to my FP Growth. I did see an operator called GuessTypes but how do I get the related type of an attribute? It seems not to be delivering this in the output port.
Any Idea?
Tagged:
0
Answers
-
That is not possible out of the box. You can probably get the types via the scripting interface in the Execute Script operator.
Best regards,
Marius0 -
Hi,
you can use the "Execute Script" operator for that. I created an example process for you which you can extend and modifiy. For further information on how to convert various attributes, have a look at the RM sourcecode of the Type Conversion operators like com.rapidminer.operator.preprocessing.filter.NominalToBinominal.
Regards,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.009">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.3.009" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="generate_data" compatibility="5.3.009" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30">
<parameter key="number_examples" value="1"/>
<parameter key="number_of_attributes" value="1"/>
</operator>
<operator activated="true" class="execute_script" compatibility="5.3.009" expanded="true" height="76" name="Execute Script" width="90" x="179" y="30">
<parameter key="script" value="import java.util.Map; import java.util.Map.Entry; import java.util.Iterator; import java.util.LinkedHashMap; import com.rapidminer.example.Attribute; import com.rapidminer.example.Example; import com.rapidminer.example.ExampleSet; import com.rapidminer.example.table.AttributeFactory; import com.rapidminer.tools.Ontology; ExampleSet exampleSet = input[0]; Map<Attribute, Attribute> translationMap = new LinkedHashMap<Attribute, Attribute>(); Iterator<Attribute> iterator = exampleSet.getAttributes().iterator(); while (iterator.hasNext()) { 	Attribute oldAtt = iterator.next(); 	if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(oldAtt.getValueType(), Ontology.NUMERICAL)) { 		Attribute newAtt = AttributeFactory.createAttribute(Ontology.BINOMINAL); 		translationMap.put(oldAtt, newAtt); 	} 	// your other conditions here } // adding to table and exampleSet for (Entry<Attribute, Attribute> replacement: translationMap.entrySet()) { 	Attribute newAttribute = replacement.getValue(); 	exampleSet.getExampleTable().addAttribute(newAttribute); 	exampleSet.getAttributes().addRegular(newAttribute); } 		 // over all examples change attribute values for(Example example : exampleSet) { 	for(Entry<Attribute, Attribute> replacement: translationMap.entrySet()) { 		Attribute oldAttribute = replacement.getKey(); 		Attribute newAttribute = replacement.getValue(); 		double oldValue = example.getValue(oldAttribute); 		if (Double.isNaN(oldValue)) { 			example.setValue(newAttribute, Double.NaN); 		} else { // your conditions here 			example.setValue(newAttribute, newAttribute.getMapping().mapString("yourString")); 		} 	} } 		 // removing old attributes for (Map.Entry<Attribute,Attribute> entry : translationMap.entrySet()) { 	Attribute originalAttribute = entry.getKey(); 	exampleSet.getAttributes().remove(originalAttribute); 	entry.getValue().setName(originalAttribute.getName()); } return exampleSet;"/>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Execute Script" to_port="input 1"/>
<connect from_op="Execute Script" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
Marco0