Options

How to log a PerformanceVector when doing optimization

MerlotMerlot Member Posts: 12 Contributor II
edited November 2018 in Help
Hi all,

I want to let RM optimize my params for different classification models. Basically, the optimization works and the params as well as the accuracy is written to a log file. Now, I want to save the PerformanceVector as shown below for any combination used to optimize the model.

image

It seems like the Log operator doesn't offer to log the PerformanceVector. Using the Write Performance operator i am only able to set a log file name which will contain the latest PerformanceVector created. I need the PerformanceVectors to be stored along with the params (like Log operator does).

This is what I've got so far:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.1.014">
 <context>
   <input/>
   <output/>
   <macros/>
 </context>
 <operator activated="true" class="process" compatibility="5.1.014" expanded="true" name="Process">
   <process expanded="true" height="600" width="994">
     <operator activated="true" class="text:process_document_from_data" compatibility="5.1.003" expanded="true" height="76" name="Process Documents from Data" width="90" x="179" y="75">
       <parameter key="prune_method" value="absolute"/>
       <parameter key="prune_below_absolute" value="2"/>
       <parameter key="prune_above_absolute" value="999"/>
       <list key="specify_weights"/>
       <process expanded="true" height="618" width="1012">
         <operator activated="true" class="text:transform_cases" compatibility="5.1.003" expanded="true" height="60" name="Transform Cases" width="90" x="45" y="30"/>
         <operator activated="true" class="text:tokenize" compatibility="5.1.003" expanded="true" height="60" name="Tokenize" width="90" x="180" y="30"/>
         <operator activated="true" class="text:filter_stopwords_german" compatibility="5.1.003" expanded="true" height="60" name="Filter Stopwords (German)" width="90" x="315" y="30"/>
         <operator activated="true" class="text:filter_stopwords_english" compatibility="5.1.003" expanded="true" height="60" name="Filter Stopwords (English)" width="90" x="450" y="30"/>
         <operator activated="false" class="text:stem_snowball" compatibility="5.1.003" expanded="true" height="60" name="Stem (Snowball)" width="90" x="585" y="30">
           <parameter key="language" value="German"/>
         </operator>
         <operator activated="true" class="text:filter_by_length" compatibility="5.1.003" expanded="true" height="60" name="Filter Tokens (by Length)" width="90" x="715" y="30">
           <parameter key="min_chars" value="3"/>
           <parameter key="max_chars" value="999"/>
         </operator>
         <connect from_port="document" to_op="Transform Cases" to_port="document"/>
         <connect from_op="Transform Cases" from_port="document" to_op="Tokenize" to_port="document"/>
         <connect from_op="Tokenize" from_port="document" to_op="Filter Stopwords (German)" to_port="document"/>
         <connect from_op="Filter Stopwords (German)" from_port="document" to_op="Filter Stopwords (English)" to_port="document"/>
         <connect from_op="Filter Stopwords (English)" from_port="document" to_op="Filter Tokens (by Length)" to_port="document"/>
         <connect from_op="Filter Tokens (by Length)" from_port="document" to_port="document 1"/>
         <portSpacing port="source_document" spacing="0"/>
         <portSpacing port="sink_document 1" spacing="0"/>
         <portSpacing port="sink_document 2" spacing="0"/>
       </process>
     </operator>
     <operator activated="true" class="optimize_parameters_grid" compatibility="5.1.014" expanded="true" height="94" name="Optimize Parameters (Grid)" width="90" x="313" y="75">
       <list key="parameters">
         <parameter key="SVM.C" value="[-2;+2;2;linear]"/>
       </list>
       <process expanded="true" height="618" width="1012">
         <operator activated="true" class="x_validation" compatibility="5.1.014" expanded="true" height="112" name="Validation" width="90" x="313" y="30">
           <parameter key="number_of_validations" value="5"/>
           <process expanded="true" height="618" width="481">
             <operator activated="true" class="support_vector_machine" compatibility="5.1.014" expanded="true" height="112" name="SVM" width="90" x="195" y="30"/>
             <connect from_port="training" to_op="SVM" to_port="training set"/>
             <connect from_op="SVM" 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="618" width="481">
             <operator activated="true" class="apply_model" compatibility="5.1.014" expanded="true" height="76" name="Apply Model" width="90" x="45" y="30">
               <list key="application_parameters"/>
             </operator>
             <operator activated="true" class="performance_classification" compatibility="5.1.014" expanded="true" height="76" name="Performance" width="90" x="179" y="30">
               <list key="class_weights"/>
             </operator>
             <operator activated="false" class="write_performance" compatibility="5.1.014" expanded="true" height="60" name="Write Performance" width="90" x="278" y="159"/>
             <connect from_port="model" to_op="Apply Model" to_port="model"/>
             <connect from_port="test set" to_op="Apply Model" to_port="unlabelled data"/>
             <connect from_op="Apply Model" 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="log" compatibility="5.1.014" expanded="true" height="76" name="Log" width="90" x="581" y="30">
           <parameter key="filename" value="log.txt"/>
           <list key="log">
             <parameter key="Execution_Time_SVM" value="operator.SVM.value.execution-time"/>
             <parameter key="Execution_Time_Apply" value="operator.Apply Model.value.execution-time"/>
             <parameter key="Execution_Time_Process" value="operator.Process.value.execution-time"/>
             <parameter key="Memory_Process" value="operator.Process.value.memory"/>
             <parameter key="Param_SVM_C" value="operator.SVM.parameter.C"/>
             <parameter key="Validation_Performance" value="operator.Validation.value.performance"/>
           </list>
         </operator>
         <connect from_port="input 1" to_op="Validation" to_port="training"/>
         <connect from_op="Validation" from_port="averagable 1" to_op="Log" to_port="through 1"/>
         <connect from_op="Log" from_port="through 1" to_port="performance"/>
         <portSpacing port="source_input 1" spacing="0"/>
         <portSpacing port="source_input 2" spacing="0"/>
         <portSpacing port="source_input 3" spacing="0"/>
         <portSpacing port="sink_performance" spacing="0"/>
         <portSpacing port="sink_result 1" spacing="0"/>
       </process>
     </operator>
     <connect from_port="input 1" to_op="Process Documents from Data" to_port="example set"/>
     <connect from_op="Process Documents from Data" from_port="example set" to_op="Optimize Parameters (Grid)" to_port="input 1"/>
     <connect from_op="Process Documents from Data" from_port="word list" to_op="Optimize Parameters (Grid)" to_port="input 2"/>
     <connect from_op="Optimize Parameters (Grid)" from_port="performance" to_port="result 1"/>
     <connect from_op="Optimize Parameters (Grid)" from_port="parameter" to_port="result 2"/>
     <portSpacing port="source_input 1" spacing="0"/>
     <portSpacing port="source_input 2" 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>
I'm sorry that this code is not working stand-alone as my data is passed through a Java application.

I would appreciate any help.

Regards
Merlot

Answers

  • Options
    MariusHelfMariusHelf RapidMiner Certified Expert, Member Posts: 1,869 Unicorn
    Hi Merlot,

    do you really need the complete performance vector? If you only need up to three performance measures, you can log them and write them to file. Btw, you can also store the log in the repository instead of a file, if you use the Log to Data operator after the Log operator.

    If you really need to store the complete Performance Vector, you can use Extract Macro to extract the current parameter values from the operators and use them to create a unique repository location based on the parameter values in a Store operator. That Store operator could then be used to store the Performance vector in the repository.

    Best regards,
    Marius
Sign In or Register to comment.