"[Solved] Set Macro dynamically based on Dataset"

aryan_hosseinzaaryan_hosseinza MemberPosts:74Contributor II
edited June 2019 inHelp
Hi ,

I am doing a down sampling by use of clustering , it's an imbalanced dataset which the number of example with 'f' label is about 6 times more than the number of examples with 't' label,

I want to set the K in clustering module equals to number of 't' examples in the dataset ,

How can I do that ?

Thanks








<运营商激活d="true" class="process" compatibility="5.2.008" expanded="true" name="Process">

<运营商激活d="true" class="retrieve" compatibility="5.2.008" expanded="true" height="60" name="Retrieve" width="90" x="45" y="75">


<运营商激活d="true" class="sample_stratified" compatibility="5.2.008" expanded="true" height="76" name="Sample (Stratified)" width="90" x="112" y="210">


<运营商激活d="true" class="nominal_to_numerical" compatibility="5.2.008" expanded="true" height="94" name="Nominal to Numerical" width="90" x="246" y="75">




<运营商激活d="true" class="normalize" compatibility="5.2.008" expanded="true" height="94" name="Normalize" width="90" x="380" y="75"/>
<运营商激活d="false" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes" width="90" x="179" y="345">




<运营商激活= " true "类=“乘”兼容ibility="5.2.008" expanded="true" height="94" name="Multiply" width="90" x="581" y="75"/>
<运营商激活d="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples (2)" width="90" x="782" y="255">



<运营商激活d="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples" width="90" x="782" y="30">



<运营商激活= " true "类=“乘”兼容ibility="5.2.008" expanded="true" height="94" name="Multiply (2)" width="90" x="916" y="30"/>
<运营商激活d="true" class="k_means" compatibility="5.2.008" expanded="true" height="76" name="Clustering" width="90" x="1117" y="30">




<运营商激活d="true" class="apply_model" compatibility="5.2.008" expanded="true" height="76" name="Apply Model" width="90" x="1117" y="165">


<运营商激活d="true" class="remove_duplicates" compatibility="5.2.008" expanded="true" height="76" name="Remove Duplicates" width="90" x="1452" y="165">




<运营商激活d="true" class="union" compatibility="5.2.008" expanded="true" height="76" name="Union" width="90" x="1720" y="210"/>
<运营商激活d="true" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes (3)" width="90" x="1921" y="210">





<运营商激活d="true" class="shuffle" compatibility="5.2.008" expanded="true" height="76" name="Shuffle" width="90" x="2055" y="210"/>



<连接from_op = "正常化" from_port = "的例子t output" to_op="Multiply" to_port="input"/>

















Tagged:

Answers

  • awchisholmawchisholm RapidMiner Certified Expert, MemberPosts:458Unicorn
    Hello,

    One approach is to set a macro equal to the number of rows where the label is 't'. This can be done using the "Extract Macro" operator.

    Then you need to use this macro as a parameter to the k-means operator.

    It's very important to make sure the extraction happens before the k-means otherwise you will get an error.

    I don't have your data so I can't test it but here's an example







    <运营商激活d="true" class="process" compatibility="5.2.008" expanded="true" name="Process">

    <运营商激活d="true" class="retrieve" compatibility="5.2.008" expanded="true" height="60" name="Retrieve" width="90" x="45" y="30">


    <运营商激活d="true" class="sample_stratified" compatibility="5.2.008" expanded="true" height="76" name="Sample (Stratified)" width="90" x="45" y="120">


    <运营商激活d="true" class="nominal_to_numerical" compatibility="5.2.008" expanded="true" height="94" name="Nominal to Numerical" width="90" x="179" y="30">




    <运营商激活d="true" class="normalize" compatibility="5.2.008" expanded="true" height="94" name="Normalize" width="90" x="179" y="165"/>
    <运营商激活d="false" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes" width="90" x="45" y="300">




    <运营商激活= " true "类=“乘”兼容ibility="5.2.008" expanded="true" height="94" name="Multiply" width="90" x="179" y="300"/>
    <运营商激活d="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples (2)" width="90" x="313" y="300">



    <运营商激活d="true" class="extract_macro" compatibility="5.2.008" expanded="true" height="60" name="Extract Macro" width="90" x="313" y="390">


    <运营商激活d="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples" width="90" x="313" y="30">



    <运营商激活= " true "类=“乘”兼容ibility="5.2.008" expanded="true" height="94" name="Multiply (2)" width="90" x="313" y="120"/>
    <运营商激活d="true" class="k_means" compatibility="5.2.008" expanded="true" height="76" name="Clustering" width="90" x="447" y="30">




    <运营商激活d="true" class="apply_model" compatibility="5.2.008" expanded="true" height="76" name="Apply Model" width="90" x="447" y="120">


    <运营商激活d="true" class="remove_duplicates" compatibility="5.2.008" expanded="true" height="76" name="Remove Duplicates" width="90" x="447" y="210">




    <运营商激活d="true" class="union" compatibility="5.2.008" expanded="true" height="76" name="Union" width="90" x="581" y="255"/>
    <运营商激活d="true" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes (3)" width="90" x="581" y="345">





    <运营商激活d="true" class="shuffle" compatibility="5.2.008" expanded="true" height="76" name="Shuffle" width="90" x="581" y="435"/>



    <连接from_op = "正常化" from_port = "的例子t output" to_op="Multiply" to_port="input"/>



















    regards

    Andrew
  • aryan_hosseinzaaryan_hosseinza MemberPosts:74Contributor II
    It returns error : A value for the parameter 'k' must be specified , but I already set 'k' before reaching the clustering , Should we refer to macro with %{} ?









    <运营商激活d="true" class="process" compatibility="5.2.008" expanded="true" name="Process">

    <运营商激活d="true" class="retrieve" compatibility="5.2.008" expanded="true" height="60" name="Retrieve" width="90" x="45" y="75">


    <运营商激活d="false" class="sample_stratified" compatibility="5.2.008" expanded="true" height="76" name="Sample (Stratified)" width="90" x="179" y="210">


    <运营商激活d="true" class="nominal_to_numerical" compatibility="5.2.008" expanded="true" height="94" name="Nominal to Numerical" width="90" x="179" y="75">




    <运营商激活d="true" class="normalize" compatibility="5.2.008" expanded="true" height="94" name="Normalize" width="90" x="313" y="75"/>
    <运营商激活d="false" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes" width="90" x="179" y="345">




    <运营商激活= " true "类=“乘”兼容ibility="5.2.008" expanded="true" height="94" name="Multiply (3)" width="90" x="447" y="75"/>
    <运营商激活d="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples (3)" width="90" x="581" y="30">



    <运营商激活= " true "类=“乘”兼容ibility="5.2.008" expanded="true" height="94" name="Multiply" width="90" x="715" y="165"/>
    <运营商激活d="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples (4)" width="90" x="849" y="300">



    <运营商激活d="false" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples (2)" width="90" x="648" y="480">



    <运营商激活d="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples" width="90" x="849" y="30">



    <运营商激活= " true "类=“乘”兼容ibility="5.2.008" expanded="true" height="94" name="Multiply (2)" width="90" x="983" y="165"/>
    <运营商激活d="true" class="k_means" compatibility="5.2.008" expanded="true" height="76" name="Clustering" width="90" x="1117" y="30">



    <运营商激活d="true" class="apply_model" compatibility="5.2.008" expanded="true" height="76" name="Apply Model" width="90" x="1251" y="165">


    <运营商激活d="true" class="remove_duplicates" compatibility="5.2.008" expanded="true" height="76" name="Remove Duplicates" width="90" x="1452" y="165">




    <运营商激活d="true" class="extract_macro" compatibility="5.2.008" expanded="true" height="60" name="Extract Macro" width="90" x="715" y="30">



    <运营商激活d="true" class="union" compatibility="5.2.008" expanded="true" height="76" name="Union" width="90" x="1854" y="255"/>
    <运营商激活d="true" class="select_attributes" compatibility="5.2.008" expanded="true" height="76" name="Select Attributes (3)" width="90" x="1988" y="255">





    <运营商激活d="true" class="shuffle" compatibility="5.2.008" expanded="true" height="76" name="Shuffle" width="90" x="2122" y="255"/>


    <连接from_op = "正常化" from_port = "的例子t output" to_op="Multiply (3)" to_port="input"/>





















  • awchisholmawchisholm RapidMiner Certified Expert, MemberPosts:458Unicorn
    Hello

    The calculation of the macro is happening after it is being used. Change the ordering from the GUI using Process->Operator Execution Order->Order Execution.

    regards

    Andrew
  • aryan_hosseinzaaryan_hosseinza MemberPosts:74Contributor II
    Thanks for your help, it works.
Sign InorRegisterto comment.