[SOLVED] Generate Report for Naive Bayes result with Loop operator

vvoss
vvoss New Altair Community Member
edited November 5 in Community Q&A
Hello,

I want to generate a report containing the result of a Naïve Bayes operator. Since the number of attributes varied for each process run, I want the automate the report generation for each attribute with a loop operator. The “Loop Attributes” operator however seems not to be able to handle this report generation. There is an error message “Expected ExampleSet but received KernelDistributionModel”.

Can any of the available loop operators handle the KernelDistributionModel?

Is there an alternate approach to implement a report generation for each attribute in the KernelDistributionModel with some kind of loop operation?

Best Regards,
Volker Voß

Example process:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.2.001">
 <context>
   <input/>
   <output/>
   <macros/>
 </context>
 <operator activated="true" class="process" compatibility="5.2.001" expanded="true" name="Process">
   <process expanded="true" height="541" width="922">
     <operator activated="true" class="generate_data" compatibility="5.2.001" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30"/>
     <operator activated="true" class="generate_attributes" compatibility="5.2.001" expanded="true" height="76" name="Generate Attributes" width="90" x="45" y="120">
       <list key="function_descriptions">
         <parameter key="label" value="if(label&lt;0.5,&quot;klein&quot;,&quot;groß&quot;)"/>
       </list>
     </operator>
     <operator activated="true" class="set_role" compatibility="5.2.001" expanded="true" height="76" name="Set Role" width="90" x="45" y="210">
       <parameter key="name" value="label"/>
       <parameter key="target_role" value="label"/>
       <list key="set_additional_roles"/>
     </operator>
     <operator activated="true" class="naive_bayes_kernel" compatibility="5.2.001" expanded="true" height="76" name="Naive Bayes (Kernel)" width="90" x="45" y="300"/>
     <operator activated="true" class="multiply" compatibility="5.2.001" expanded="true" height="94" name="Multiply" width="90" x="179" y="30"/>
     <operator activated="true" class="reporting:generate_report" compatibility="5.1.000" expanded="true" height="76" name="Generate Report (2)" width="90" x="313" y="120">
       <parameter key="report_name" value="Test Report 2"/>
       <parameter key="pdf_output_file" value="C:\Test_Report2.pdf"/>
     </operator>
     <operator activated="true" class="reporting:add_section" compatibility="5.1.000" expanded="true" height="76" name="Add Section (2)" width="90" x="447" y="120">
       <parameter key="report_name" value="Test Report 2"/>
       <parameter key="report_section_name" value="Naive Bayes"/>
     </operator>
     <operator activated="true" class="loop_attributes" compatibility="5.2.001" expanded="true" height="60" name="Does not work Loop Attributes" width="90" x="581" y="120">
       <process expanded="true" height="559" width="940">
         <operator activated="true" class="reporting:report" compatibility="5.1.000" expanded="true" height="60" name="Report (2)" width="90" x="45" y="30">
           <parameter key="report_name" value="Test Report 2"/>
           <parameter key="report_item_header" value="%{loop_attribute}"/>
           <parameter key="specified" value="true"/>
           <parameter key="reportable_type" value="Kernel Bayes Model"/>
           <parameter key="renderer_name" value="Plot View"/>
           <list key="parameters">
             <parameter key="attribute_name" value="%{loop_attribute}"/>
             <parameter key="range_" value="."/>
             <parameter key="rotate_labels" value="false"/>
           </list>
         </operator>
         <connect from_port="example set" to_op="Report (2)" to_port="reportable in"/>
         <connect from_op="Report (2)" from_port="reportable out" to_port="example set"/>
         <portSpacing port="source_example set" spacing="0"/>
         <portSpacing port="sink_example set" spacing="0"/>
       </process>
     </operator>
     <operator activated="true" class="reporting:generate_report" compatibility="5.1.000" expanded="true" height="76" name="Generate Report" width="90" x="313" y="30">
       <parameter key="report_name" value="Test Report"/>
       <parameter key="pdf_output_file" value="C:\Test_Report.pdf"/>
     </operator>
     <operator activated="true" class="reporting:add_section" compatibility="5.1.000" expanded="true" height="76" name="Add Section" width="90" x="447" y="30">
       <parameter key="report_name" value="Test Report"/>
       <parameter key="report_section_name" value="Naive Bayes"/>
     </operator>
     <operator activated="true" class="reporting:report" compatibility="5.1.000" expanded="true" height="60" name="Working Report" width="90" x="581" y="30">
       <parameter key="report_name" value="Test Report"/>
       <parameter key="report_item_header" value="atr1"/>
       <parameter key="specified" value="true"/>
       <parameter key="reportable_type" value="Kernel Bayes Model"/>
       <parameter key="renderer_name" value="Plot View"/>
       <list key="parameters">
         <parameter key="attribute_name" value="att1"/>
         <parameter key="range_" value="."/>
         <parameter key="rotate_labels" value="false"/>
       </list>
       <parameter key="image_height" value="800"/>
     </operator>
     <connect from_op="Generate Data" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
     <connect from_op="Generate Attributes" 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="Naive Bayes (Kernel)" to_port="training set"/>
     <connect from_op="Naive Bayes (Kernel)" from_port="model" to_op="Multiply" to_port="input"/>
     <connect from_op="Multiply" from_port="output 1" to_op="Generate Report" to_port="through 1"/>
     <connect from_op="Multiply" from_port="output 2" to_op="Generate Report (2)" to_port="through 1"/>
     <connect from_op="Generate Report (2)" from_port="through 1" to_op="Add Section (2)" to_port="through 1"/>
     <connect from_op="Add Section (2)" from_port="through 1" to_op="Does not work Loop Attributes" to_port="example set"/>
     <connect from_op="Does not work Loop Attributes" from_port="example set" to_port="result 2"/>
     <connect from_op="Generate Report" from_port="through 1" to_op="Add Section" to_port="through 1"/>
     <connect from_op="Add Section" from_port="through 1" to_op="Working Report" to_port="reportable in"/>
     <connect from_op="Working Report" from_port="reportable out" 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"/>
     <portSpacing port="sink_result 3" spacing="0"/>
   </process>
 </operator>
</process>
[ /code]

Tagged:

Answers

  • Nils_Woehler
    Nils_Woehler New Altair Community Member
    Hey,

    instead of looping the naive bayes model you can loop the example set on which the model is created.

    Here is the corret process:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.2.001">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.2.001" expanded="true" name="Process">
        <process expanded="true" height="674" width="1092">
          <operator activated="true" class="generate_data" compatibility="5.2.001" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30"/>
          <operator activated="true" class="generate_attributes" compatibility="5.2.001" expanded="true" height="76" name="Generate Attributes" width="90" x="180" y="30">
            <list key="function_descriptions">
              <parameter key="label" value="if(label&lt;0.5,&quot;klein&quot;,&quot;groß&quot;)"/>
            </list>
          </operator>
          <operator activated="true" class="set_role" compatibility="5.2.001" expanded="true" height="76" name="Set Role" width="90" x="315" y="30">
            <parameter key="name" value="label"/>
            <parameter key="target_role" value="label"/>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="naive_bayes_kernel" compatibility="5.2.001" expanded="true" height="76" name="Naive Bayes (Kernel)" width="90" x="450" y="30"/>
          <operator activated="true" class="remember" compatibility="5.2.001" expanded="true" height="60" name="Remember" width="90" x="648" y="30">
            <parameter key="name" value="naiveBayes"/>
            <parameter key="io_object" value="Model"/>
          </operator>
          <operator activated="true" class="reporting:generate_report" compatibility="5.1.000" expanded="true" height="94" name="Generate Report (2)" width="90" x="715" y="120">
            <parameter key="report_name" value="Test Report"/>
            <parameter key="pdf_output_file" value="C:\Users\nwoehler\Desktop\Test_Report.pdf"/>
            <parameter key="pdf_template_file" value="C:\Users\nwoehler\workspace\RapidMiner_Unuk\no file selected"/>
            <parameter key="image_template_file" value="C:\Users\nwoehler\workspace\RapidMiner_Unuk\no file selected"/>
            <parameter key="section_one_font" value="courier"/>
            <parameter key="section_two_font" value="courier"/>
            <parameter key="section_three_font" value="courier"/>
            <parameter key="section_four_font" value="courier"/>
            <parameter key="section_five_font" value="courier"/>
            <parameter key="text_content_font" value="courier"/>
          </operator>
          <operator activated="true" class="reporting:add_section" compatibility="5.1.000" expanded="true" height="76" name="Add Section (2)" width="90" x="849" y="30">
            <parameter key="report_name" value="Test Report"/>
            <parameter key="report_section_name" value="Naive Bayes"/>
          </operator>
          <operator activated="true" class="loop_attributes" compatibility="5.2.001" expanded="true" height="60" name="Loop Attributes" width="90" x="983" y="30">
            <process expanded="true" height="638" width="547">
              <operator activated="true" class="recall" compatibility="5.2.001" expanded="true" height="60" name="Recall" width="90" x="112" y="30">
                <parameter key="name" value="naiveBayes"/>
                <parameter key="io_object" value="Model"/>
                <parameter key="remove_from_store" value="false"/>
              </operator>
              <operator activated="true" class="reporting:report" compatibility="5.1.000" expanded="true" height="60" name="Working Report" width="90" x="380" y="30">
                <parameter key="report_name" value="Test Report"/>
                <parameter key="report_item_header" value="%{loop_attribute}"/>
                <parameter key="specified" value="true"/>
                <parameter key="reportable_type" value="Kernel Bayes Model"/>
                <parameter key="renderer_name" value="Plot View"/>
                <list key="parameters">
                  <parameter key="attribute_name" value="%{loop_attribute}"/>
                  <parameter key="range_" value="."/>
                  <parameter key="rotate_labels" value="false"/>
                </list>
                <parameter key="image_height" value="800"/>
              </operator>
              <connect from_op="Recall" from_port="result" to_op="Working Report" to_port="reportable in"/>
              <portSpacing port="source_example set" spacing="0"/>
              <portSpacing port="sink_example set" spacing="0"/>
            </process>
          </operator>
          <connect from_op="Generate Data" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" 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="Naive Bayes (Kernel)" to_port="training set"/>
          <connect from_op="Naive Bayes (Kernel)" from_port="model" to_op="Remember" to_port="store"/>
          <connect from_op="Naive Bayes (Kernel)" from_port="exampleSet" to_op="Generate Report (2)" to_port="through 1"/>
          <connect from_op="Remember" from_port="stored" to_op="Generate Report (2)" to_port="through 2"/>
          <connect from_op="Generate Report (2)" from_port="through 1" to_op="Add Section (2)" to_port="through 1"/>
          <connect from_op="Add Section (2)" from_port="through 1" to_op="Loop Attributes" to_port="example set"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
        </process>
      </operator>
    </process>

  • vvoss
    vvoss New Altair Community Member
    Hello Nils,

    thanks for the answer. This solution works perfect for me.

    Best Regards,
    Volker Voß