"Edit to Decision tree condition value"

sp
sp New Altair Community Member
edited November 5 in Community Q&A
hi,
  Thanks RapidMiner Team for this GUI Data Mining Software.
  I am new To RM, for the past three months i am developing one simple project in RM using Decision Tree Learner.
  Now my Boss want to Edit the Rule Value of Decision Tree and then again Apply the new Decision Tree in Data Set.
  So any chance, to edit the rule value in java applet program and again feed into rapidminer process.
Because now i get decision tree ouput as jpeg, txt and xml.

Thanks in advance

Answers

  • sp
    sp New Altair Community Member
    Here is my Code in Java:

    import com.rapidminer.RapidMiner;
    import com.rapidminer.Process;
    import com.rapidminer.tools.container.Pair;

    import java.io.File;
    public class RunRMProcess{
    public static void main(String[] argv) throws Exception {
    RapidMiner.init();
    System.setProperty("rapidminer.init.operators", "G:\\RapidMiner\\Processxml-files\\rmprocess.xml");
    Process process=new Process(new File("G:\\RapidMiner\\Processxml-files\\rmprocess.xml"));
       process.getContext().addMacro(new Pair<String,String>("Appname","wine"));
       process.run();
    }
    }



    Here is my Rapidminer Xml:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.1.017">
     <context>
       <input/>
       <output/>
       <macros/>
     </context>
     <operator activated="true" class="process" compatibility="5.1.017" expanded="true" name="Process">
       <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"/>
       <parameter key="parallelize_main_process" value="false"/>
       <process expanded="true" height="550" width="1418">
         <operator activated="true" class="read_database" compatibility="5.1.017" expanded="true" height="60" name="Read Database" width="90" x="45" y="30">
           <parameter key="define_connection" value="predefined"/>
           <parameter key="connection" value="New connection2"/>
           <parameter key="database_system" value="MySQL"/>
           <parameter key="define_query" value="table name"/>
           <parameter key="use_default_schema" value="true"/>
           <parameter key="table_name" value="%{Appname}_verified"/>
           <parameter key="prepare_statement" value="false"/>
           <enumeration key="parameters"/>
           <parameter key="datamanagement" value="double_array"/>
         </operator>
         <operator activated="true" class="set_role" compatibility="5.1.017" expanded="true" height="76" name="Set Role" width="90" x="180" y="30">
           <parameter key="name" value="Label"/>
           <parameter key="target_role" value="label"/>
           <list key="set_additional_roles">
             <parameter key="ID" value="id"/>
           </list>
         </operator>
         <operator activated="true" class="read_database" compatibility="5.1.017" expanded="true" height="60" name="Read Database (2)" width="90" x="45" y="210">
           <parameter key="define_connection" value="predefined"/>
           <parameter key="connection" value="New connection2"/>
           <parameter key="database_system" value="MySQL"/>
           <parameter key="define_query" value="table name"/>
           <parameter key="use_default_schema" value="true"/>
           <parameter key="table_name" value="%{Appname}_unverified"/>
           <parameter key="prepare_statement" value="false"/>
           <enumeration key="parameters"/>
           <parameter key="datamanagement" value="double_array"/>
         </operator>
         <operator activated="true" class="x_validation" compatibility="5.1.017" expanded="true" height="112" name="Validation" width="90" x="315" y="30">
           <parameter key="create_complete_model" value="false"/>
           <parameter key="average_performances_only" value="true"/>
           <parameter key="leave_one_out" value="false"/>
           <parameter key="number_of_validations" value="10"/>
           <parameter key="sampling_type" value="stratified sampling"/>
           <parameter key="use_local_random_seed" value="false"/>
           <parameter key="local_random_seed" value="1992"/>
           <parameter key="parallelize_training" value="false"/>
           <parameter key="parallelize_testing" value="false"/>
           <process expanded="true" height="385" width="373">
             <operator activated="true" class="decision_tree" compatibility="5.1.017" expanded="true" height="76" name="Decision Tree" width="90" x="112" y="30">
               <parameter key="criterion" value="gain_ratio"/>
               <parameter key="minimal_size_for_split" value="4"/>
               <parameter key="minimal_leaf_size" value="2"/>
               <parameter key="minimal_gain" value="0.1"/>
               <parameter key="maximal_depth" value="20"/>
               <parameter key="confidence" value="0.25"/>
               <parameter key="number_of_prepruning_alternatives" value="3"/>
               <parameter key="no_pre_pruning" value="false"/>
               <parameter key="no_pruning" value="false"/>
             </operator>
             <connect from_port="training" to_op="Decision Tree" to_port="training set"/>
             <connect from_op="Decision Tree" from_port="model" to_port="model"/>
             <portSpacing port="source_training" spacing="0"/>
             <portSpacing port="sink_model" spacing="0"/>
             <portSpacing port="sink_through 1" spacing="0"/>
           </process>
           <process expanded="true" height="385" width="373">
             <operator activated="true" class="apply_model" compatibility="5.1.017" expanded="true" height="76" name="Apply Model (2)" width="90" x="45" y="30">
               <list key="application_parameters"/>
               <parameter key="create_view" value="false"/>
             </operator>
             <operator activated="true" class="performance" compatibility="5.1.017" expanded="true" height="76" name="Performance" width="90" x="179" y="30">
               <parameter key="use_example_weights" value="true"/>
             </operator>
             <connect from_port="model" to_op="Apply Model (2)" to_port="model"/>
             <connect from_port="test set" to_op="Apply Model (2)" to_port="unlabelled data"/>
             <connect from_op="Apply Model (2)" from_port="labelled data" to_op="Performance" to_port="labelled data"/>
             <connect from_op="Performance" from_port="performance" to_port="averagable 1"/>
             <portSpacing port="source_model" spacing="0"/>
             <portSpacing port="source_test set" spacing="0"/>
             <portSpacing port="source_through 1" spacing="0"/>
             <portSpacing port="sink_averagable 1" spacing="0"/>
             <portSpacing port="sink_averagable 2" spacing="0"/>
           </process>
         </operator>
         <operator activated="true" class="multiply" compatibility="5.1.017" expanded="true" height="112" name="Multiply" width="90" x="450" y="30"/>
         <operator activated="true" class="write" compatibility="5.1.017" expanded="true" height="60" name="Write" width="90" x="648" y="30">
           <parameter key="object_file" value="C:\RapidMiner\modelfile\%{Appname}.xml"/>
           <parameter key="output_type" value="XML"/>
           <parameter key="continue_on_error" value="false"/>
         </operator>
         <operator activated="true" class="reporting:generate_report" compatibility="5.1.000" expanded="true" height="76" name="Generate Report" width="90" x="648" y="120">
           <parameter key="report_name" value="%{Appname}"/>
           <parameter key="format" value="HTML"/>
           <parameter key="report_to_repository" value="false"/>
           <parameter key="repository_entry" value="iris testing/decisiontreemodel"/>
           <parameter key="html_output_directory" value="C:\RapidMiner\modelfile\%{Appname}.html"/>
           <parameter key="rtf_output_file" value="C:\RapidMiner\modelfile\dd.rtf"/>
           <parameter key="html_image_format" value="png"/>
           <parameter key="image_col_span" value="8"/>
           <parameter key="image_row_span" value="17"/>
           <parameter key="page_size" value="A4"/>
           <parameter key="page_format" value="portrait"/>
           <parameter key="template_type" value="none"/>
           <parameter key="image_alignment" value="aspect_ratio"/>
           <parameter key="set_background_color" value="false"/>
           <parameter key="background_color" value="255,255,255"/>
           <parameter key="page_width" value="595"/>
           <parameter key="page_height" value="842"/>
           <parameter key="top_page_margin" value="36"/>
           <parameter key="bottom_page_margin" value="36"/>
           <parameter key="left_page_margin" value="36"/>
           <parameter key="right_page_margin" value="36"/>
           <parameter key="section_one_font_size" value="12.0"/>
           <parameter key="section_one_font_style_bold" value="false"/>
           <parameter key="section_one_font_style_italic" value="false"/>
           <parameter key="section_one_font_style_underline" value="false"/>
           <parameter key="section_one_font_style_strikethrough" value="false"/>
           <parameter key="section_one_font_color" value="0,0,0"/>
           <parameter key="section_two_font_size" value="12.0"/>
           <parameter key="section_two_font_style_bold" value="false"/>
           <parameter key="section_two_font_style_italic" value="false"/>
           <parameter key="section_two_font_style_underline" value="false"/>
           <parameter key="section_two_font_style_strikethrough" value="false"/>
           <parameter key="section_two_font_color" value="0,0,0"/>
           <parameter key="section_three_font_size" value="12.0"/>
           <parameter key="section_three_font_style_bold" value="false"/>
           <parameter key="section_three_font_style_italic" value="false"/>
           <parameter key="section_three_font_style_underline" value="false"/>
           <parameter key="section_three_font_style_strikethrough" value="false"/>
           <parameter key="section_three_font_color" value="0,0,0"/>
           <parameter key="section_four_font_size" value="12.0"/>
           <parameter key="section_four_font_style_bold" value="false"/>
           <parameter key="section_four_font_style_italic" value="false"/>
           <parameter key="section_four_font_style_underline" value="false"/>
           <parameter key="section_four_font_style_strikethrough" value="false"/>
           <parameter key="section_four_font_color" value="0,0,0"/>
           <parameter key="section_five_font_size" value="12.0"/>
           <parameter key="section_five_font_style_bold" value="false"/>
           <parameter key="section_five_font_style_italic" value="false"/>
           <parameter key="section_five_font_style_underline" value="false"/>
           <parameter key="section_five_font_style_strikethrough" value="false"/>
           <parameter key="section_five_font_color" value="0,0,0"/>
           <parameter key="text_content_font_size" value="12.0"/>
           <parameter key="text_content_font_style_bold" value="false"/>
           <parameter key="text_content_font_style_italic" value="false"/>
           <parameter key="text_content_font_style_underline" value="false"/>
           <parameter key="text_content_font_style_strikethrough" value="false"/>
           <parameter key="text_content_font_color" value="0,0,0"/>
           <parameter key="system_fonts" value="false"/>
           <parameter key="directory_fonts" value="false"/>
           <parameter key="table_column_number" value="8"/>
           <parameter key="table_header_color" value="128,128,128"/>
           <parameter key="table_row_color_one" value="255,255,255"/>
           <parameter key="table_row_color_two" value="192,192,192"/>
         </operator>
         <operator activated="true" class="reporting:report" compatibility="5.1.000" expanded="true" height="60" name="Report" width="90" x="849" y="120">
           <parameter key="report_name" value="%{Appname}"/>
           <parameter key="report_item_header" value="%{Appname}"/>
           <parameter key="specified" value="true"/>
           <parameter key="reportable_type" value="Decision Tree"/>
           <parameter key="renderer_name" value="Graph View"/>
           <list key="parameters">
             <parameter key="layout" value="Tree"/>
             <parameter key="show_node_labels" value="true"/>
             <parameter key="show_edge_labels" value="true"/>
           </list>
           <parameter key="image_width" value="800"/>
           <parameter key="image_height" value="800"/>
         </operator>
         <operator activated="true" class="apply_model" compatibility="5.1.017" expanded="true" height="76" name="Apply Model" width="90" x="447" y="210">
           <list key="application_parameters"/>
           <parameter key="create_view" value="false"/>
         </operator>
         <operator activated="true" class="multiply" compatibility="5.1.017" expanded="true" height="94" name="Multiply (2)" width="90" x="648" y="210"/>
         <operator activated="true" class="tutorial:store_special_attributes" compatibility="5.0.000" expanded="true" height="60" name="store_special_attributes" width="90" x="849" y="300"/>
         <operator activated="true" class="write_database" compatibility="5.1.017" expanded="true" height="60" name="Write Database (2)" width="90" x="983" y="300">
           <parameter key="define_connection" value="predefined"/>
           <parameter key="connection" value="New connection2"/>
           <parameter key="database_system" value="MySQL"/>
           <parameter key="use_default_schema" value="true"/>
           <parameter key="table_name" value="%{Appname}_decisiontree_confidence_data"/>
           <parameter key="overwrite_mode" value="overwrite"/>
           <parameter key="set_default_varchar_length" value="false"/>
           <parameter key="default_varchar_length" value="128"/>
           <parameter key="add_generated_primary_keys" value="false"/>
           <parameter key="db_key_attribute_name" value="generated_primary_key"/>
           <parameter key="batch_size" value="1"/>
         </operator>
         <operator activated="true" class="tutorial:store_predicted_label" compatibility="5.0.000" expanded="true" height="60" name="store_predicted_label (2)" width="90" x="849" y="210"/>
         <operator activated="true" class="write_database" compatibility="5.1.017" expanded="true" height="60" name="Write Database" width="90" x="983" y="210">
           <parameter key="define_connection" value="predefined"/>
           <parameter key="connection" value="New connection2"/>
           <parameter key="database_system" value="MySQL"/>
           <parameter key="use_default_schema" value="true"/>
           <parameter key="table_name" value="%{Appname}_verified_unverified_data"/>
           <parameter key="overwrite_mode" value="overwrite"/>
           <parameter key="set_default_varchar_length" value="false"/>
           <parameter key="default_varchar_length" value="128"/>
           <parameter key="add_generated_primary_keys" value="false"/>
           <parameter key="db_key_attribute_name" value="generated_primary_key"/>
           <parameter key="batch_size" value="1"/>
         </operator>
         <connect from_op="Read Database" from_port="output" to_op="Set Role" to_port="example set input"/>
         <connect from_op="Set Role" from_port="example set output" to_op="Validation" to_port="training"/>
         <connect from_op="Read Database (2)" from_port="output" to_op="Apply Model" to_port="unlabelled data"/>
         <connect from_op="Validation" from_port="model" to_op="Multiply" to_port="input"/>
         <connect from_op="Validation" from_port="averagable 1" to_port="result 1"/>
         <connect from_op="Multiply" from_port="output 1" to_op="Write" to_port="object"/>
         <connect from_op="Multiply" from_port="output 2" to_op="Generate Report" to_port="through 1"/>
         <connect from_op="Multiply" from_port="output 3" to_op="Apply Model" to_port="model"/>
         <connect from_op="Generate Report" from_port="through 1" to_op="Report" to_port="reportable in"/>
         <connect from_op="Report" from_port="reportable out" to_port="result 2"/>
         <connect from_op="Apply Model" from_port="labelled data" to_op="Multiply (2)" to_port="input"/>
         <connect from_op="Multiply (2)" from_port="output 1" to_op="store_predicted_label (2)" to_port="example set"/>
         <connect from_op="Multiply (2)" from_port="output 2" to_op="store_special_attributes" to_port="example set"/>
         <connect from_op="store_special_attributes" from_port="example set" to_op="Write Database (2)" to_port="input"/>
         <connect from_op="Write Database (2)" from_port="through" to_port="result 4"/>
         <connect from_op="store_predicted_label (2)" from_port="example set" to_op="Write Database" to_port="input"/>
         <connect from_op="Write Database" from_port="through" to_port="result 3"/>
         <portSpacing port="source_input 1" spacing="216"/>
         <portSpacing port="sink_result 1" spacing="36"/>
         <portSpacing port="sink_result 2" spacing="36"/>
         <portSpacing port="sink_result 3" spacing="72"/>
         <portSpacing port="sink_result 4" spacing="72"/>
         <portSpacing port="sink_result 5" spacing="0"/>
       </process>
     </operator>
    </process>
    Help me to show editable decision tree in java applet program..
    Thanks in advance
  • sp
    sp New Altair Community Member
    Anyone....
      Please give atleast  a hint, where to start.
      Now i have to do
        1. Show the ouput Model(Decision Tree) in java applet.
              For that i have to convert Output of Decision Tree Learner into Editable Graph.
        2. Edited value of Tree Node must reflected in XML file.
              The value must parsed into xml file of Decision Tree Model.

    Thanks in advance...
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    do I understand you correctly that you want to edit the conditions on the edges of the decision tree, e.g. when it say "if value >0.5 go left, otherwise go right" you want to edit the 0.5?
    If so, I'm afraid that's not supported by RapidMiner. If you want to add this functionality, you would have to replace/extend RapidMiner code.
    Classes that might be interesting:

    com.rapidminer.operator.learner.tree.TreeModel
    com.rapidminer.operator.learner.tree.Tree
    com.rapidminer.operator.learner.tree.Edge

    Apart from that, models are not stored as XML files. They are serialized objects, so you might want to look at IOObjectSerializer.getInstance().serialize(OutputStream, IOObject) and IOObjectSerializer.getInstance().deserialize(InputStream).
    You should be able to cast the model from IOObject to TreeModel (or whatever your own model you implemented yourself later on is called) and continue from there.


    Regards,
    Marco