Multiple Label dataset classification

nickshel81nickshel81 Member Posts: 7 Contributor II
edited November 2018 in Help

Hi Everyone,

I am working on this text mining use case where my dataset has simply 4 columns, An ID, a Comments field (text), a Failure (Yes/No) and a Failure Type (Polynomial). The failure type is there only when a failure exists otherwise it is empty.

I know how to use the text mining process to classify a failure yes or no  but how can I then classify the type of failure based on the text once the record is classified as a failure? Do I have to do this in two seperate processes or can I do both labels classification in the same process?

Please let me know if you have any questions.

Thanks 

Best Answer

  • nickshel81nickshel81 Member Posts: 7 Contributor II
    Solution Accepted

    Hi @Telcontar120

     

    Thanks for the recommendation. I was actually able to solve this in a different way. One challenge I faced was actually testing the model once i figured out training the two labels. I hope this is helpful for others. I'm actually surprised there isn't a more straight forward way to deal with multi label datasets in rapidminer. maybe a future feature :)

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.3.000">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.3.000" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve Failures" width="90" x="45" y="34">
    <parameter key="repository_entry" value="../../data/Failure/Failures"/>
    </operator>
    <operator activated="true" class="text:process_document_from_data" compatibility="7.3.000" expanded="true" height="82" name="Process Documents from Data" width="90" x="313" y="34">
    <parameter key="prune_below_percent" value="1.0"/>
    <parameter key="prune_above_percent" value="99.0"/>
    <parameter key="prune_below_absolute" value="10"/>
    <parameter key="prune_above_absolute" value="1000"/>
    <parameter key="prune_above_rank" value="0.99"/>
    <list key="specify_weights"/>
    <process expanded="true">
    <operator activated="true" class="text:tokenize" compatibility="7.3.000" expanded="true" height="68" name="Tokenize" width="90" x="246" y="34"/>
    <operator activated="true" class="text:transform_cases" compatibility="7.3.000" expanded="true" height="68" name="Transform Cases" width="90" x="380" y="34">
    <parameter key="transform_to" value="upper case"/>
    </operator>
    <operator activated="true" class="text:filter_stopwords_english" compatibility="7.3.000" expanded="true" height="68" name="Filter Stopwords (English)" width="90" x="514" y="34"/>
    <operator activated="true" class="text:filter_by_length" compatibility="7.3.000" expanded="true" height="68" name="Filter Tokens (by Length)" width="90" x="648" y="34">
    <parameter key="min_chars" value="3"/>
    </operator>
    <operator activated="false" class="text:stem_porter" compatibility="7.3.000" expanded="true" height="68" name="Stem (Porter)" width="90" x="782" y="85"/>
    <operator activated="true" class="text:generate_n_grams_terms" compatibility="7.3.000" expanded="true" height="68" name="Generate n-Grams (2)" width="90" x="916" y="34"/>
    <connect from_port="document" to_op="Tokenize" to_port="document"/>
    <connect from_op="Tokenize" from_port="document" to_op="Transform Cases" to_port="document"/>
    <connect from_op="Transform Cases" 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_op="Generate n-Grams (2)" to_port="document"/>
    <connect from_op="Generate n-Grams (2)" 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="set_role" compatibility="7.3.000" expanded="true" height="82" name="Set Role" width="90" x="514" y="34">
    <parameter key="attribute_name" value="FAILURE"/>
    <parameter key="target_role" value="label1"/>
    <list key="set_additional_roles">
    <parameter key="FAILURE_TYPE" value="label2"/>
    </list>
    </operator>
    <operator activated="true" class="loop_labels" compatibility="7.3.000" expanded="true" height="103" name="Loop Labels" width="90" x="715" y="34">
    <process expanded="true">
    <operator activated="true" class="concurrency:cross_validation" compatibility="7.3.000" expanded="true" height="145" name="Cross Validation" width="90" x="514" y="34">
    <process expanded="true">
    <operator activated="true" class="neural_net" compatibility="7.3.000" expanded="true" height="82" name="Neural Net" width="90" x="246" y="34">
    <list key="hidden_layers"/>
    </operator>
    <connect from_port="training set" to_op="Neural Net" to_port="training set"/>
    <connect from_op="Neural Net" from_port="model" to_port="model"/>
    <portSpacing port="source_training set" spacing="0"/>
    <portSpacing port="sink_model" spacing="0"/>
    <portSpacing port="sink_through 1" spacing="0"/>
    </process>
    <process expanded="true">
    <operator activated="true" class="apply_model" compatibility="7.1.001" expanded="true" height="82" name="Apply Model" width="90" x="112" y="34">
    <list key="application_parameters"/>
    </operator>
    <operator activated="true" class="performance_classification" compatibility="7.3.000" expanded="true" height="82" name="Performance" width="90" x="246" y="34">
    <list key="class_weights"/>
    </operator>
    <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="performance 1"/>
    <portSpacing port="source_model" spacing="0"/>
    <portSpacing port="source_test set" spacing="0"/>
    <portSpacing port="source_through 1" spacing="0"/>
    <portSpacing port="sink_test set results" spacing="0"/>
    <portSpacing port="sink_performance 1" spacing="0"/>
    <portSpacing port="sink_performance 2" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="store" compatibility="7.3.000" expanded="true" height="68" name="Store (2)" width="90" x="648" y="34">
    <parameter key="repository_entry" value="Model%{execution_count}"/>
    </operator>
    <connect from_port="example set" to_op="Cross Validation" to_port="example set"/>
    <connect from_op="Cross Validation" from_port="model" to_op="Store (2)" to_port="input"/>
    <connect from_op="Cross Validation" from_port="performance 1" to_port="out 2"/>
    <connect from_op="Store (2)" from_port="through" to_port="out 1"/>
    <portSpacing port="source_example set" spacing="0"/>
    <portSpacing port="sink_out 1" spacing="0"/>
    <portSpacing port="sink_out 2" spacing="0"/>
    <portSpacing port="sink_out 3" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="read_excel" compatibility="7.3.000" expanded="true" height="68" name="Read Excel" width="90" x="45" y="187">
    <parameter key="excel_file" value="C:\Users\Hussein\Desktop\Failures.xlsx"/>
    <parameter key="imported_cell_range" value="A1:D14"/>
    <list key="annotations">
    <parameter key="0" value="Name"/>
    </list>
    <list key="data_set_meta_data_information">
    <parameter key="0" value="ID.true.integer.attribute"/>
    <parameter key="1" value="COMMENTS.true.text.attribute"/>
    <parameter key="2" value="FAILURE.true.attribute_value.attribute"/>
    <parameter key="3" value="FAILURE_TYPE.true.attribute_value.attribute"/>
    </list>
    </operator>
    <operator activated="true" class="generate_attributes" compatibility="7.3.000" expanded="true" height="82" name="Duplicate Comments" width="90" x="179" y="187">
    <list key="function_descriptions">
    <parameter key="NOTES" value="COMMENTS"/>
    </list>
    </operator>
    <operator activated="true" class="text:process_document_from_data" compatibility="7.3.000" expanded="true" height="82" name="Process Documents from Data (2)" width="90" x="313" y="187">
    <parameter key="prune_below_percent" value="1.0"/>
    <parameter key="prune_above_percent" value="99.0"/>
    <parameter key="prune_below_absolute" value="10"/>
    <parameter key="prune_above_absolute" value="1000"/>
    <parameter key="prune_above_rank" value="0.99"/>
    <list key="specify_weights"/>
    <process expanded="true">
    <operator activated="true" class="text:tokenize" compatibility="7.3.000" expanded="true" height="68" name="Tokenize (2)" width="90" x="246" y="34"/>
    <operator activated="true" class="text:transform_cases" compatibility="7.3.000" expanded="true" height="68" name="Transform Cases (2)" width="90" x="380" y="34">
    <parameter key="transform_to" value="upper case"/>
    </operator>
    <operator activated="true" class="text:filter_stopwords_english" compatibility="7.3.000" expanded="true" height="68" name="Filter Stopwords (2)" width="90" x="514" y="34"/>
    <operator activated="true" class="text:filter_by_length" compatibility="7.3.000" expanded="true" height="68" name="Filter Tokens (2)" width="90" x="648" y="34">
    <parameter key="min_chars" value="3"/>
    </operator>
    <operator activated="false" class="text:stem_porter" compatibility="7.3.000" expanded="true" height="68" name="Stem (2)" width="90" x="782" y="85"/>
    <operator activated="true" class="text:generate_n_grams_terms" compatibility="7.3.000" expanded="true" height="68" name="Generate n-Grams (3)" width="90" x="916" y="34"/>
    <connect from_port="document" to_op="Tokenize (2)" to_port="document"/>
    <connect from_op="Tokenize (2)" from_port="document" to_op="Transform Cases (2)" to_port="document"/>
    <connect from_op="Transform Cases (2)" from_port="document" to_op="Filter Stopwords (2)" to_port="document"/>
    <connect from_op="Filter Stopwords (2)" from_port="document" to_op="Filter Tokens (2)" to_port="document"/>
    <connect from_op="Filter Tokens (2)" from_port="document" to_op="Generate n-Grams (3)" to_port="document"/>
    <connect from_op="Generate n-Grams (3)" 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="set_role" compatibility="7.3.000" expanded="true" height="82" name="Set Role (2)" width="90" x="514" y="187">
    <parameter key="attribute_name" value="FAILURE"/>
    <parameter key="target_role" value="label1"/>
    <list key="set_additional_roles">
    <parameter key="FAILURE_TYPE" value="label2"/>
    <parameter key="ID" value="id"/>
    </list>
    </operator>
    <operator activated="true" class="loop_labels" compatibility="7.3.000" expanded="true" height="82" name="Loop Labels (2)" width="90" x="715" y="187">
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve" width="90" x="313" y="34">
    <parameter key="repository_entry" value="Model%{execution_count}"/>
    </operator>
    <operator activated="true" class="apply_model" compatibility="7.3.000" expanded="true" height="82" name="Apply Model (2)" width="90" x="447" y="85">
    <list key="application_parameters"/>
    </operator>
    <connect from_port="example set" to_op="Apply Model (2)" to_port="unlabelled data"/>
    <connect from_op="Retrieve" from_port="output" to_op="Apply Model (2)" to_port="model"/>
    <connect from_op="Apply Model (2)" from_port="labelled data" to_port="out 1"/>
    <portSpacing port="source_example set" spacing="0"/>
    <portSpacing port="sink_out 1" spacing="0"/>
    <portSpacing port="sink_out 2" spacing="0"/>
    </process>
    </operator>
    <connect from_op="Retrieve Failures" from_port="output" to_op="Process Documents from Data" to_port="example set"/>
    <connect from_op="Process Documents from Data" from_port="example set" to_op="Set Role" to_port="example set input"/>
    <connect from_op="Process Documents from Data" from_port="word list" to_op="Process Documents from Data (2)" to_port="word list"/>
    <connect from_op="Set Role" from_port="example set output" to_op="Loop Labels" to_port="example set"/>
    <connect from_op="Loop Labels" from_port="out 1" to_port="result 1"/>
    <connect from_op="Loop Labels" from_port="out 2" to_port="result 2"/>
    <connect from_op="Read Excel" from_port="output" to_op="Duplicate Comments" to_port="example set input"/>
    <connect from_op="Duplicate Comments" from_port="example set output" to_op="Process Documents from Data (2)" to_port="example set"/>
    <connect from_op="Process Documents from Data (2)" from_port="example set" to_op="Set Role (2)" to_port="example set input"/>
    <connect from_op="Set Role (2)" from_port="example set output" to_op="Loop Labels (2)" to_port="example set"/>
    <connect from_op="Loop Labels (2)" from_port="out 1" to_port="result 3"/>
    <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"/>
    <portSpacing port="sink_result 4" spacing="0"/>
    </process>
    </operator>
    </process>

     

Answers

  • JEdwardJEdward RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 578 Unicorn

    Yes, the operator you are looking for is Loop Labels, this will change the target label of your dataset by iterating across them.  So label1, label2, etc. 

    The output in this case would be two models stored as a collection.  One to classify Failure/Non-failure, the other to classify the type of failure. 

     

    I will warn you in advance that you might want to consider how you automate the model building process within the Loop Labels operator as, because it will apply the same operators to the data you might need to optimize to select the best algorithm for the problem. 

     

    With that in mind here is a toy example attached of the LoopLabels operator in action on the Titanic dataset.  For algorithm selection it uses the model selection building block from @mschmitz which you can download from the building blocks section of the forum.  

     

  • nickshel81nickshel81 Member Posts: 7 Contributor II

    Hi @JEdward,

     

    Thanks for the reply It was very helpful especially with the example. However I have one question that i am hoping you can help with.

     

    How do i limit the second run of the loop label operator to only do the failure type classification on the "Yes's" predicted failure and not the "No's"? In other words the loop label will apply the text mining process in the first round to predict the Yes/No (whether there is a failure or not and it will then use the same text comments to predict the type of failure on both Yes's and No's which is not accurate. I want it to do the second label classification (failure type) only on the ones predicted with a Yes failure occurred.

     

    Hope this makes sense.

    thanks again for your help.

  • Telcontar120Telcontar120 Moderator, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 Unicorn

    To accomplish that you can simply add a "filter examples" operator and set the condition to where your first label value is equal to "yes." 

    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
  • nickshel81nickshel81 Member Posts: 7 Contributor II

    Hi @Telcontar120,

     

    Thanks for your reply. Wouldn't that also apply on the first label run? meaning it will also apply on when the model is classifying the Yes/No failures! Is there a way to apply the filter on the 2nd label loop?

     

    Thanks

  • Telcontar120Telcontar120 Moderator, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 Unicorn

    Yes, there is, although it will make your process a bit more complicated :-)

    You'll need to create an outer loop, and then use the "select subprocess" or "branch" operator, and have two subprocesses.  In the first subprocess you will do the first modeling with you "yes" and "no" observations both, and then write that model prediction into the dataset.  In the second subprocess you'll do the filtering as described.  The selection will be based on which iteration of the outer loop you are on--the first one will use all the data and any subsequent ones will use only the "yes" observations.  The loop iteration number is stored as a macro and can be used to trigger the "select subprocess" opreator. I think that should work!

     

    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
Sign In or Register to comment.