Can I use the 'Model Simulator' operator using a model from the 'Multi Label Modeling' operator?

kimjk3559
kimjk3559 Altair Community Member
edited November 5 in Community Q&A
We were able to successfully obtain predicted values for data with two labels (labels independent of each other) using the 'Multi Label Modeling' operator.
However, when I connect to ‘mod’ of ‘Model Simulator’, a ‘Wrong Model Type’ error message appears.
Ultimately, I wanted to set specific target values for the two labels and check the values of the remaining variables. Is there another way?

Best Answer

  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓
    Hi,
    the model simulator was build to only show one model, it does not work with a multi-label one.

    There is actualy no operator to extract a single model from the multi-label one which you can then use. I've created a small script which does it for you. I hope that helps!

    Best,
    Martin

    <?xml version="1.0" encoding="UTF-8"?><process version="10.2.000">
    
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="10.2.000" expanded="true" name="Process" origin="GENERATED_TUTORIAL">
    <parameter key="logverbosity" value="init"/>
    <parameter key="random_seed" value="2001"/>
    <parameter key="send_mail" value="never"/>
    <parameter key="notification_email" value=""/>
    <parameter key="process_duration_for_mail" value="30"/>
    <parameter key="encoding" value="SYSTEM"/>
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="10.2.000" expanded="true" height="68" name="Retrieve Titanic" origin="GENERATED_TUTORIAL" width="90" x="45" y="187">
    <parameter key="repository_entry" value="//Samples/data/Titanic"/>
    </operator>
    <operator activated="true" class="replace_missing_values" compatibility="10.2.000" expanded="true" height="103" name="Replace Missing Values" width="90" x="179" y="187">
    <parameter key="return_preprocessing_model" value="false"/>
    <parameter key="attribute_filter_type" value="all"/>
    <parameter key="attribute" value=""/>
    <parameter key="attributes" value=""/>
    <parameter key="use_except_expression" value="false"/>
    <parameter key="value_type" value="attribute_value"/>
    <parameter key="use_value_type_exception" value="false"/>
    <parameter key="except_value_type" value="time"/>
    <parameter key="block_type" value="attribute_block"/>
    <parameter key="use_block_type_exception" value="false"/>
    <parameter key="except_block_type" value="value_matrix_row_start"/>
    <parameter key="invert_selection" value="false"/>
    <parameter key="include_special_attributes" value="false"/>
    <parameter key="default" value="average"/>
    <list key="columns"/>
    </operator>
    <operator activated="true" class="blending:set_role" compatibility="10.2.000" expanded="true" height="82" name="Set Role" origin="GENERATED_TUTORIAL" width="90" x="313" y="187">
    <list key="set_roles">
    <parameter key="Port of Embarkation" value="metadata"/>
    <parameter key="Survived" value="metadata"/>
    </list>
    </operator>
    <operator activated="true" class="split_data" compatibility="10.1.003" expanded="true" height="103" name="Split Data" origin="GENERATED_TUTORIAL" width="90" x="447" y="187">
    <enumeration key="partitions">
    <parameter key="ratio" value="0.7"/>
    <parameter key="ratio" value="0.3"/>
    </enumeration>
    <parameter key="sampling_type" value="automatic"/>
    <parameter key="use_local_random_seed" value="false"/>
    <parameter key="local_random_seed" value="1992"/>
    </operator>
    <operator activated="true" class="time_series:multi_label_model_learner" compatibility="10.1.000" expanded="true" height="82" name="Multi Label Modeling" origin="GENERATED_TUTORIAL" width="90" x="648" y="34">
    <parameter key="attribute_filter_type" value="subset"/>
    <parameter key="attribute" value=""/>
    <parameter key="attributes" value="Port of Embarkation|Survived|Age"/>
    <parameter key="use_except_expression" value="false"/>
    <parameter key="value_type" value="attribute_value"/>
    <parameter key="use_value_type_exception" value="false"/>
    <parameter key="except_value_type" value="time"/>
    <parameter key="block_type" value="attribute_block"/>
    <parameter key="use_block_type_exception" value="false"/>
    <parameter key="except_block_type" value="value_matrix_row_start"/>
    <parameter key="invert_selection" value="false"/>
    <parameter key="include_special_attributes" value="true"/>
    <parameter key="add_macros" value="true"/>
    <parameter key="current_label_name_macro" value="current_label_attribute"/>
    <parameter key="current_label_type_macro" value="current_label_type"/>
    <parameter key="enable_parallel_execution" value="true"/>
    <process expanded="true">
    <operator activated="true" class="h2o:gradient_boosted_trees" compatibility="10.2.000" expanded="true" height="103" name="Gradient Boosted Trees" width="90" x="246" y="34">
    <parameter key="number_of_trees" value="3"/>
    <parameter key="reproducible" value="false"/>
    <parameter key="maximum_number_of_threads" value="4"/>
    <parameter key="use_local_random_seed" value="false"/>
    <parameter key="local_random_seed" value="1992"/>
    <parameter key="maximal_depth" value="5"/>
    <parameter key="min_rows" value="10.0"/>
    <parameter key="min_split_improvement" value="1.0E-5"/>
    <parameter key="number_of_bins" value="20"/>
    <parameter key="learning_rate" value="0.01"/>
    <parameter key="sample_rate" value="1.0"/>
    <parameter key="distribution" value="AUTO"/>
    <parameter key="early_stopping" value="false"/>
    <parameter key="stopping_rounds" value="1"/>
    <parameter key="stopping_metric" value="AUTO"/>
    <parameter key="stopping_tolerance" value="0.001"/>
    <list key="monotone_constraints"/>
    <parameter key="max_runtime_seconds" value="0"/>
    <list key="expert_parameters"/>
    </operator>
    <connect from_port="training set" to_op="Gradient Boosted Trees" to_port="training set"/>
    <connect from_op="Gradient Boosted Trees" from_port="model" to_port="model"/>
    <portSpacing port="source_training set" spacing="0"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_model" spacing="0"/>
    <portSpacing port="sink_output 1" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="execute_script" compatibility="10.2.000" expanded="true" height="82" name="Execute Script" width="90" x="782" y="34">
    <parameter key="script" value="&#10;import java.util.HashMap;&#10;&#10;import com.rapidminer.operator.IOObjectCollection;&#10;import com.rapidminer.operator.learner.PredictionModel;&#10;import com.rapidminer.extension.timeseries.operator.multi_label_model.MultiLabelModel;&#10;&#10;MultiLabelModel model = input[0];&#10;HashMap&lt;String,PredictionModel&gt; map = model.labelModelMap;&#10;IOObjectCollection&lt;PredictionModel&gt; col = new IOObjectCollection&lt;&gt;();&#10;for(String key : map.keySet()){&#10;&#9;&#9;col.add(map.get(key));&#10;}&#10;&#9;&#9;&#10;&#10;return col;"/>
    <parameter key="standard_imports" value="true"/>
    </operator>
    <operator activated="true" class="select" compatibility="10.2.000" expanded="true" height="68" name="Select" width="90" x="916" y="34">
    <parameter key="index" value="1"/>
    <parameter key="unfold" value="false"/>
    </operator>
    <operator activated="true" class="model_simulator:model_simulator" compatibility="10.2.000" expanded="true" height="103" name="Model Simulator" width="90" x="1117" y="187"/>
    <connect from_op="Retrieve Titanic" from_port="output" to_op="Replace Missing Values" to_port="example set input"/>
    <connect from_op="Replace Missing Values" from_port="example set output" to_op="Set Role" to_port="example set input"/>
    <connect from_op="Set Role" from_port="example set output" to_op="Split Data" to_port="example set"/>
    <connect from_op="Split Data" from_port="partition 1" to_op="Multi Label Modeling" to_port="training set"/>
    <connect from_op="Split Data" from_port="partition 2" to_op="Model Simulator" to_port="training data"/>
    <connect from_op="Multi Label Modeling" from_port="model" to_op="Execute Script" to_port="input 1"/>
    <connect from_op="Execute Script" from_port="output 1" to_op="Select" to_port="collection"/>
    <connect from_op="Select" from_port="selected" to_op="Model Simulator" to_port="model"/>
    <connect from_op="Model Simulator" from_port="simulator 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>



Answers

  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓
    Hi,
    the model simulator was build to only show one model, it does not work with a multi-label one.

    There is actualy no operator to extract a single model from the multi-label one which you can then use. I've created a small script which does it for you. I hope that helps!

    Best,
    Martin

    <?xml version="1.0" encoding="UTF-8"?><process version="10.2.000">
    
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="10.2.000" expanded="true" name="Process" origin="GENERATED_TUTORIAL">
    <parameter key="logverbosity" value="init"/>
    <parameter key="random_seed" value="2001"/>
    <parameter key="send_mail" value="never"/>
    <parameter key="notification_email" value=""/>
    <parameter key="process_duration_for_mail" value="30"/>
    <parameter key="encoding" value="SYSTEM"/>
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="10.2.000" expanded="true" height="68" name="Retrieve Titanic" origin="GENERATED_TUTORIAL" width="90" x="45" y="187">
    <parameter key="repository_entry" value="//Samples/data/Titanic"/>
    </operator>
    <operator activated="true" class="replace_missing_values" compatibility="10.2.000" expanded="true" height="103" name="Replace Missing Values" width="90" x="179" y="187">
    <parameter key="return_preprocessing_model" value="false"/>
    <parameter key="attribute_filter_type" value="all"/>
    <parameter key="attribute" value=""/>
    <parameter key="attributes" value=""/>
    <parameter key="use_except_expression" value="false"/>
    <parameter key="value_type" value="attribute_value"/>
    <parameter key="use_value_type_exception" value="false"/>
    <parameter key="except_value_type" value="time"/>
    <parameter key="block_type" value="attribute_block"/>
    <parameter key="use_block_type_exception" value="false"/>
    <parameter key="except_block_type" value="value_matrix_row_start"/>
    <parameter key="invert_selection" value="false"/>
    <parameter key="include_special_attributes" value="false"/>
    <parameter key="default" value="average"/>
    <list key="columns"/>
    </operator>
    <operator activated="true" class="blending:set_role" compatibility="10.2.000" expanded="true" height="82" name="Set Role" origin="GENERATED_TUTORIAL" width="90" x="313" y="187">
    <list key="set_roles">
    <parameter key="Port of Embarkation" value="metadata"/>
    <parameter key="Survived" value="metadata"/>
    </list>
    </operator>
    <operator activated="true" class="split_data" compatibility="10.1.003" expanded="true" height="103" name="Split Data" origin="GENERATED_TUTORIAL" width="90" x="447" y="187">
    <enumeration key="partitions">
    <parameter key="ratio" value="0.7"/>
    <parameter key="ratio" value="0.3"/>
    </enumeration>
    <parameter key="sampling_type" value="automatic"/>
    <parameter key="use_local_random_seed" value="false"/>
    <parameter key="local_random_seed" value="1992"/>
    </operator>
    <operator activated="true" class="time_series:multi_label_model_learner" compatibility="10.1.000" expanded="true" height="82" name="Multi Label Modeling" origin="GENERATED_TUTORIAL" width="90" x="648" y="34">
    <parameter key="attribute_filter_type" value="subset"/>
    <parameter key="attribute" value=""/>
    <parameter key="attributes" value="Port of Embarkation|Survived|Age"/>
    <parameter key="use_except_expression" value="false"/>
    <parameter key="value_type" value="attribute_value"/>
    <parameter key="use_value_type_exception" value="false"/>
    <parameter key="except_value_type" value="time"/>
    <parameter key="block_type" value="attribute_block"/>
    <parameter key="use_block_type_exception" value="false"/>
    <parameter key="except_block_type" value="value_matrix_row_start"/>
    <parameter key="invert_selection" value="false"/>
    <parameter key="include_special_attributes" value="true"/>
    <parameter key="add_macros" value="true"/>
    <parameter key="current_label_name_macro" value="current_label_attribute"/>
    <parameter key="current_label_type_macro" value="current_label_type"/>
    <parameter key="enable_parallel_execution" value="true"/>
    <process expanded="true">
    <operator activated="true" class="h2o:gradient_boosted_trees" compatibility="10.2.000" expanded="true" height="103" name="Gradient Boosted Trees" width="90" x="246" y="34">
    <parameter key="number_of_trees" value="3"/>
    <parameter key="reproducible" value="false"/>
    <parameter key="maximum_number_of_threads" value="4"/>
    <parameter key="use_local_random_seed" value="false"/>
    <parameter key="local_random_seed" value="1992"/>
    <parameter key="maximal_depth" value="5"/>
    <parameter key="min_rows" value="10.0"/>
    <parameter key="min_split_improvement" value="1.0E-5"/>
    <parameter key="number_of_bins" value="20"/>
    <parameter key="learning_rate" value="0.01"/>
    <parameter key="sample_rate" value="1.0"/>
    <parameter key="distribution" value="AUTO"/>
    <parameter key="early_stopping" value="false"/>
    <parameter key="stopping_rounds" value="1"/>
    <parameter key="stopping_metric" value="AUTO"/>
    <parameter key="stopping_tolerance" value="0.001"/>
    <list key="monotone_constraints"/>
    <parameter key="max_runtime_seconds" value="0"/>
    <list key="expert_parameters"/>
    </operator>
    <connect from_port="training set" to_op="Gradient Boosted Trees" to_port="training set"/>
    <connect from_op="Gradient Boosted Trees" from_port="model" to_port="model"/>
    <portSpacing port="source_training set" spacing="0"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_model" spacing="0"/>
    <portSpacing port="sink_output 1" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="execute_script" compatibility="10.2.000" expanded="true" height="82" name="Execute Script" width="90" x="782" y="34">
    <parameter key="script" value="&#10;import java.util.HashMap;&#10;&#10;import com.rapidminer.operator.IOObjectCollection;&#10;import com.rapidminer.operator.learner.PredictionModel;&#10;import com.rapidminer.extension.timeseries.operator.multi_label_model.MultiLabelModel;&#10;&#10;MultiLabelModel model = input[0];&#10;HashMap&lt;String,PredictionModel&gt; map = model.labelModelMap;&#10;IOObjectCollection&lt;PredictionModel&gt; col = new IOObjectCollection&lt;&gt;();&#10;for(String key : map.keySet()){&#10;&#9;&#9;col.add(map.get(key));&#10;}&#10;&#9;&#9;&#10;&#10;return col;"/>
    <parameter key="standard_imports" value="true"/>
    </operator>
    <operator activated="true" class="select" compatibility="10.2.000" expanded="true" height="68" name="Select" width="90" x="916" y="34">
    <parameter key="index" value="1"/>
    <parameter key="unfold" value="false"/>
    </operator>
    <operator activated="true" class="model_simulator:model_simulator" compatibility="10.2.000" expanded="true" height="103" name="Model Simulator" width="90" x="1117" y="187"/>
    <connect from_op="Retrieve Titanic" from_port="output" to_op="Replace Missing Values" to_port="example set input"/>
    <connect from_op="Replace Missing Values" from_port="example set output" to_op="Set Role" to_port="example set input"/>
    <connect from_op="Set Role" from_port="example set output" to_op="Split Data" to_port="example set"/>
    <connect from_op="Split Data" from_port="partition 1" to_op="Multi Label Modeling" to_port="training set"/>
    <connect from_op="Split Data" from_port="partition 2" to_op="Model Simulator" to_port="training data"/>
    <connect from_op="Multi Label Modeling" from_port="model" to_op="Execute Script" to_port="input 1"/>
    <connect from_op="Execute Script" from_port="output 1" to_op="Select" to_port="collection"/>
    <connect from_op="Select" from_port="selected" to_op="Model Simulator" to_port="model"/>
    <connect from_op="Model Simulator" from_port="simulator 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>