"Macro to calulate % of a value"
Anki
New Altair Community Member
Hi Matthias and all,
I want to write a macro to calulate 20% ( percent ) of a value. My problem is like this
CUST_ID TRAN_COUNT
--------------------------------------
23145 23
34562 87
I want to Iterate the process for each CUST_ID and In the inner loop I am reading data belongs to CUST_ID and I am passing it to "Outlier Analysis".
In Outlier Analysis I need to give input 'count_of_outlier' as 20% of TRAN_COUNT.
I am taking macro "extract macro" .....But How can I calulate % of that value?
Thank you
Yours
Anki
I want to write a macro to calulate 20% ( percent ) of a value. My problem is like this
CUST_ID TRAN_COUNT
--------------------------------------
23145 23
34562 87
I want to Iterate the process for each CUST_ID and In the inner loop I am reading data belongs to CUST_ID and I am passing it to "Outlier Analysis".
In Outlier Analysis I need to give input 'count_of_outlier' as 20% of TRAN_COUNT.
I am taking macro "extract macro" .....But How can I calulate % of that value?
Thank you
Yours
Anki
0
Answers
-
Hi Anki,
if you already have the value extracted as a macro, you can generate a new one using expressions via "Generate Macro". Here a small example illustrating this.<?xml version="1.0" encoding="UTF-8" standalone="no"?>
"Generate Attributes" is just used to show the computed macro value. Instead of generating output this way, you will have to use the new macro as input parameter for "Outlier Analysis". You will certainly need integer values, so you can wrap the "Generate Macro" expression included above inside the ceil() or floor() function, e.g. ceil(%{tran_count} * 0.2)
<process version="5.1.008">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.1.008" expanded="true" name="Process">
<process expanded="true" height="145" width="681">
<operator activated="true" class="generate_data" compatibility="5.1.008" 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="select_attributes" compatibility="5.1.008" expanded="true" height="76" name="Select Attributes" width="90" x="179" y="30">
<parameter key="attribute_filter_type" value="single"/>
<parameter key="attribute" value="label"/>
<parameter key="invert_selection" value="true"/>
<parameter key="include_special_attributes" value="true"/>
</operator>
<operator activated="true" class="extract_macro" compatibility="5.1.008" expanded="true" height="60" name="Extract Macro" width="90" x="313" y="30">
<parameter key="macro" value="tran_count"/>
<parameter key="macro_type" value="data_value"/>
<parameter key="attribute_name" value="att1"/>
<parameter key="example_index" value="1"/>
</operator>
<operator activated="true" class="generate_macro" compatibility="5.1.008" expanded="true" height="76" name="Generate Macro" width="90" x="447" y="30">
<list key="function_descriptions">
<parameter key="outlier_threshold" value="%{tran_count} * 0.2"/>
</list>
</operator>
<operator activated="true" class="generate_attributes" compatibility="5.1.008" expanded="true" height="76" name="Generate Attributes" width="90" x="581" y="30">
<list key="function_descriptions">
<parameter key="threshold_test" value="%{outlier_threshold}"/>
</list>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Select Attributes" to_port="example set input"/>
<connect from_op="Select Attributes" from_port="example set output" to_op="Extract Macro" to_port="example set"/>
<connect from_op="Extract Macro" from_port="example set" to_op="Generate Macro" to_port="through 1"/>
<connect from_op="Generate Macro" from_port="through 1" to_op="Generate Attributes" to_port="example set input"/>
<connect from_op="Generate Attributes" from_port="example set output" 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>
Best regards
Matthias0 -
Hi Matthias
Thanks a lot.
Yours
Anki0