【问题标题】:RapidMiner: Loop for attribute to extract value and trigger another loopRapidMiner:循环获取属性以提取值并触发另一个循环
【发布时间】:2015-07-26 02:54:13
【问题描述】:

我刚开始使用 RapidMiner,我正在寻找一种方法来迭代一个属性,提取特定的整数值,并为每次迭代触发基于整数值创建新插入。

我认为可以使用循环值任务。在子流程中,我将使用迭代的特定值,然后触发新数据集的生成。但循环值似乎只适用于名义值。

此外,如何通过使用属性的当前值来定义迭代次数(例如,对于函数 Loop)?

有什么想法吗?

更新1:

循环示例似乎是我第一步的正确选择,因为循环值检查特定属性的不同值存在多少。

更新2:

有循环的部分:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.013">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.3.013" expanded="true" name="Process">
<parameter key="resultfile" value="/home/test.res"/>
<process expanded="true">
  <operator activated="true" breakpoints="after" class="read_excel" compatibility="5.3.013" expanded="true" height="60" name="Read Excel" width="90" x="1586" y="615">
    <parameter key="excel_file" value="D:\stack.xlsx"/>
    <list key="annotations"/>
    <list key="data_set_meta_data_information"/>
  </operator>
  <operator activated="true" breakpoints="after" class="loop_examples" compatibility="5.3.013" expanded="true" height="76" name="Loop Examples" width="90" x="1921" y="615">
    <process expanded="true">
      <operator activated="true" breakpoints="after" class="extract_macro" compatibility="5.3.013" expanded="true" height="60" name="Extract Macro" width="90" x="112" y="30">
        <parameter key="macro" value="macro_value"/>
        <parameter key="macro_type" value="data_value"/>
        <parameter key="attribute_name" value="att9"/>
        <parameter key="example_index" value="1"/>
        <list key="additional_macros"/>
      </operator>
      <operator activated="true" breakpoints="after" class="loop" compatibility="5.3.013" expanded="true" height="76" name="Loop (2)" width="90" x="380" y="30">
        <parameter key="set_iteration_macro" value="true"/>
        <parameter key="iterations" value="%{macro_value}"/>
        <process expanded="true">
          <operator activated="true" breakpoints="after" class="generate_data_user_specification" compatibility="5.3.013" expanded="true" height="60" name="Generate Data by User Specification (2)" width="90" x="45" y="300">
            <list key="attribute_values">
              <parameter key="person_type_id" value="3"/>
            </list>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" breakpoints="after" class="select_attributes" compatibility="5.3.013" expanded="true" height="76" name="Select Attributes (8)" width="90" x="112" y="120">
            <parameter key="attribute_filter_type" value="subset"/>
            <parameter key="attributes" value="id|temp_id||att9"/>
          </operator>
          <operator activated="true" breakpoints="after" class="join" compatibility="5.3.013" expanded="true" height="76" name="Join (5)" width="90" x="246" y="255">
            <parameter key="use_id_attribute_as_key" value="false"/>
            <list key="key_attributes"/>
          </operator>
          <operator activated="true" breakpoints="after" class="select_attributes" compatibility="5.3.013" expanded="true" height="76" name="Select Attributes (7)" width="90" x="447" y="255">
            <parameter key="attribute_filter_type" value="subset"/>
            <parameter key="attributes" value="id|person_type_id|temp_id|att9"/>
          </operator>
          <connect from_port="input 1" to_op="Select Attributes (8)" to_port="example set input"/>
          <connect from_op="Generate Data by User Specification (2)" from_port="output" to_op="Join (5)" to_port="right"/>
          <connect from_op="Select Attributes (8)" from_port="example set output" to_op="Join (5)" to_port="left"/>
          <connect from_op="Join (5)" from_port="join" to_op="Select Attributes (7)" to_port="example set input"/>
          <connect from_op="Select Attributes (7)" from_port="example set output" to_port="output 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="source_input 2" spacing="0"/>
          <portSpacing port="sink_output 1" spacing="0"/>
          <portSpacing port="sink_output 2" spacing="0"/>
        </process>
      </operator>
      <operator activated="true" breakpoints="after" class="append" compatibility="5.3.013" expanded="true" height="76" name="Append" width="90" x="648" y="30"/>
      <connect from_port="example set" to_op="Extract Macro" to_port="example set"/>
      <connect from_op="Extract Macro" from_port="example set" to_op="Loop (2)" to_port="input 1"/>
      <connect from_op="Loop (2)" from_port="output 1" to_op="Append" to_port="example set 1"/>
      <connect from_op="Append" from_port="merged set" to_port="example set"/>
      <portSpacing port="source_example set" spacing="0"/>
      <portSpacing port="sink_example set" spacing="0"/>
      <portSpacing port="sink_output 1" spacing="0"/>
    </process>
  </operator>
  <operator activated="true" breakpoints="after" class="write_csv" compatibility="5.3.013" expanded="true" height="76" name="writePersonref" width="90" x="2055" y="615">
    <parameter key="csv_file" value="/home/result.csv"/>
  </operator>
  <connect from_op="Read Excel" from_port="output" to_op="Loop Examples" to_port="example set"/>
  <connect from_op="Loop Examples" from_port="example set" to_op="writePersonref" to_port="input"/>
  <portSpacing port="source_input 1" spacing="0"/>
  <portSpacing port="sink_result 1" spacing="0"/>
</process>

测试数据只包含2行:第一行:id=1,att9=2,temp_id=2;第二行:id=2,att9=1,temp_id=4

正确的结果应该包含 3 行:第一行:id=1,att9=2,temp_id=2,person_type_id=3;第二行:id=1,att9=2,temp_id=2,person_type_id=3;第三行:id=2,att9=1,temp_id=2,person_type_id=3。

谢谢

【问题讨论】:

  • 不幸的是,XML 没有导入。可以重做吗?
  • XML 末尾缺少 。

标签: database loops rapidminer


【解决方案1】:

您可以使用Numerical to Polynominal 运算符将整数转换为标称值。 Loop Values 运算符将正常工作。如果您仍然需要循环内的整数值,我的建议是创建一个新属性(使用Generate Attributes),它是原始整数的副本,将其转换为多项式并使用它来控制Loop Values 运算符。

【讨论】:

  • 感谢您的评论。或者还有其他方法可以为我的用例建模吗?如何在每次迭代中使用一个属性的每个值在子流程内工作?我需要每次迭代的值来生成一个新的数据集。如果当前迭代值为 3,我需要在我生成的数据集中生成三行。此外,我需要在这个新生成的数据集中插入初始外键值。
  • 当前值将包含在宏中(默认名称为loop_value)。您可以使用它来控制新示例集的创建。我能想到的最简单的方法是使用Loop 运算符,并将其迭代参数设置为loop_value 宏。在此运算符中,为您想要的数据生成一行(例如,尝试Generate Data by User Specification)。 Loop 运算符的输出是单行的集合,您可以使用 Append 运算符将它们连接在一起。
  • 谢谢。是否也有可能通过使用原始数据集的值来生成新的数据集? %{value} 不适用于“按用户规范生成数据”。
  • 看来,我还是没有找到合适的循环运算符。循环值仅检查属性包含多少个区分值。循环示例不起作用,因为我无法访问特定属性迭代的当前值。
  • 一切皆有可能,但工作有点困难。要访问Loop Examples 中的特定值,您可以使用“迭代宏”参数来选择循环内的示例。 Extract Macro 运算符是在循环内使用的运算符。对于此运算符,将macro type 参数设置为data_value,您将获得新的下拉菜单,允许您为您选择的属性选择特定示例,并将值放入新宏。然后可以随意使用这个新宏。
【解决方案2】:

我做了一些改变。

  • 使用宏从 Loop Examples运营商
  • 过滤原始示例集以仅包含单行以 加入生成的示例集
  • 从Loop Examples 运算符输出原始示例集 (这是必需的,否则循环出错)
  • 将Append 移到Loop Examples 运算符之外

这是过程。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.015">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="5.3.015" expanded="true" name="Process">
    <parameter key="resultfile" value="/home/test.res"/>
    <process expanded="true">
      <operator activated="true" class="read_excel" compatibility="5.3.015" expanded="true" height="60" name="Read Excel" width="90" x="45" y="75">
    <parameter key="excel_file" value="D:\stack.xlsx"/>
    <list key="annotations"/>
    <list key="data_set_meta_data_information"/>
      </operator>
      <operator activated="true" class="loop_examples" compatibility="5.3.015" expanded="true" height="94" name="Loop Examples" width="90" x="246" y="75">
    <process expanded="true">
      <operator activated="true" class="multiply" compatibility="5.3.015" expanded="true" height="94" name="Multiply" width="90" x="45" y="30"/>
      <operator activated="true" class="extract_macro" compatibility="5.3.015" expanded="true" height="60" name="Extract Macro" width="90" x="45" y="165">
        <parameter key="macro" value="macro_value"/>
        <parameter key="macro_type" value="data_value"/>
        <parameter key="attribute_name" value="att9"/>
        <parameter key="example_index" value="%{example}"/>
        <list key="additional_macros"/>
      </operator>
      <operator activated="true" class="filter_example_range" compatibility="5.3.015" expanded="true" height="76" name="Filter Example Range (2)" width="90" x="45" y="255">
        <parameter key="first_example" value="%{example}"/>
        <parameter key="last_example" value="%{example}"/>
      </operator>
      <operator activated="true" class="loop" compatibility="5.3.015" expanded="true" height="76" name="Loop (2)" width="90" x="179" y="165">
        <parameter key="set_iteration_macro" value="true"/>
        <parameter key="iterations" value="%{macro_value}"/>
        <process expanded="true">
          <operator activated="true" class="generate_data_user_specification" compatibility="5.3.015" expanded="true" height="60" name="Generate Data by User Specification (2)" width="90" x="112" y="300">
        <list key="attribute_values">
          <parameter key="person_type_id" value="3"/>
        </list>
        <list key="set_additional_roles"/>
          </operator>
          <operator activated="false" breakpoints="after" class="select_attributes" compatibility="5.3.015" expanded="true" height="76" name="Select Attributes (8)" width="90" x="179" y="30">
        <parameter key="attribute_filter_type" value="subset"/>
        <parameter key="attributes" value="id|temp_id||att9"/>
          </operator>
          <operator activated="true" class="join" compatibility="5.3.015" expanded="true" height="76" name="Join (5)" width="90" x="246" y="210">
        <parameter key="use_id_attribute_as_key" value="false"/>
        <list key="key_attributes"/>
          </operator>
          <operator activated="false" class="select_attributes" compatibility="5.3.015" expanded="true" height="76" name="Select Attributes (7)" width="90" x="447" y="300">
        <parameter key="attribute_filter_type" value="subset"/>
        <parameter key="attributes" value="id|person_type_id|temp_id|att9"/>
          </operator>
          <connect from_port="input 1" to_op="Join (5)" to_port="left"/>
          <connect from_op="Generate Data by User Specification (2)" from_port="output" to_op="Join (5)" to_port="right"/>
          <connect from_op="Join (5)" from_port="join" to_port="output 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="source_input 2" spacing="0"/>
          <portSpacing port="sink_output 1" spacing="0"/>
          <portSpacing port="sink_output 2" spacing="0"/>
        </process>
      </operator>
      <connect from_port="example set" to_op="Multiply" to_port="input"/>
      <connect from_op="Multiply" from_port="output 1" to_port="example set"/>
      <connect from_op="Multiply" from_port="output 2" to_op="Extract Macro" to_port="example set"/>
      <connect from_op="Extract Macro" from_port="example set" to_op="Filter Example Range (2)" to_port="example set input"/>
      <connect from_op="Filter Example Range (2)" from_port="example set output" to_op="Loop (2)" to_port="input 1"/>
      <connect from_op="Loop (2)" from_port="output 1" to_port="output 1"/>
      <portSpacing port="source_example set" spacing="0"/>
      <portSpacing port="sink_example set" spacing="0"/>
      <portSpacing port="sink_output 1" spacing="0"/>
      <portSpacing port="sink_output 2" spacing="0"/>
    </process>
      </operator>
      <operator activated="true" class="append" compatibility="5.3.015" expanded="true" height="76" name="Append" width="90" x="380" y="120"/>
      <operator activated="true" class="write_csv" compatibility="5.3.015" expanded="true" height="76" name="writePersonref" width="90" x="514" y="165">
    <parameter key="csv_file" value="/home/result.csv"/>
      </operator>
      <connect from_op="Read Excel" from_port="output" to_op="Loop Examples" to_port="example set"/>
      <connect from_op="Loop Examples" from_port="example set" to_port="result 1"/>
      <connect from_op="Loop Examples" from_port="output 1" to_op="Append" to_port="example set 1"/>
      <connect from_op="Append" from_port="merged set" to_op="writePersonref" to_port="input"/>
      <portSpacing port="source_input 1" spacing="0"/>
      <portSpacing port="sink_result 1" spacing="0"/>
      <portSpacing port="sink_result 2" spacing="0"/>
    </process>
  </operator>
</process>

【讨论】:

  • 感谢您的帮助,对于我迟到的回复,我深表歉意。虽然最后我自己找到了方法,但可能只是因为你的支持。 ;-)
猜你喜欢
  • 2017-04-22
  • 2018-05-25
  • 2018-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-09
  • 1970-01-01
相关资源
最近更新 更多