1

我有一个 TFIDF 向量,它保存在数据库内的 MYSQL 表中,该表具有以下架构:

id | docid | word    | weight | class/label | timestamp
1  | 1     | argon   | 0.2123 | pos         | 2013-03-25 16:22:48
2  | 1     | apple   | 0.1523 | pos         | 2013-03-25 16:22:48
3  | 2     | orange  | 0.8823 | pos         | 2013-03-25 16:22:48
4  | 2     | diffuse | 0.9812 | pos         | 2013-03-25 16:22:48
5  | 3     | master  | 0.2653 | neg         | 2013-03-25 16:22:48
6  | 3     | mouse   | 0.7623 | neg         | 2013-03-25 16:22:48

所有文档的向量垂直位于同一张表上,并按docid字段区分

我想将它们加载到 RapidMiner 中,以便为 pos 和 neg 类构建分类器,据我所知,RapidMiner 中的分类器模型接受的格式是每个文档水平地连续表示,如下所示:

docid | class/label | argon |apple   | orange  | diffuse | .... 
1     | pos         | 0.154 |0       | 0.1326  | 0.7741  | ....
2     | pos         | 0.545 |0       | 0       | 0.77    | ....
3     | neg         | 0.565 |0.122   | 0.1555  | 0       | ....

我可以编写一些代码来完成这项任务并将它们保存在 CSV 文件中,然后将它们上传到 rapid miner,我希望在 rapid miner 中执行更快的任务。通过使其接受第一种格式或将其更改为第二种甚至是 MYSQL 查询来做到这一点。

考虑到向量表非常大(大约 500 mb),因此可扩展性是一个问题

4

1 回答 1

1

“枢轴”操作员将为您完成这项工作。设置docid为您的组属性和word索引属性,您将获得与您想要的类似的东西。为了得到你想要的,你必须先删除 id 属性,重命名属性,然后替换缺失的部分。

我为你建立了一个小例子。忽略 CSV 运算符并将其替换为“读取数据库”运算符。

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.3.009">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.3.009" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="read_csv" compatibility="5.3.009" expanded="true" height="60" name="Read CSV" width="90" x="45" y="30">
            <parameter key="csv_file" value="~/temp/stackoverflow/vectors.csv"/>
            <parameter key="trim_lines" value="true"/>
            <parameter key="first_row_as_names" value="false"/>
            <list key="annotations">
              <parameter key="0" value="Name"/>
            </list>
            <parameter key="encoding" value="UTF-8"/>
            <list key="data_set_meta_data_information">
              <parameter key="0" value="id.true.integer.attribute"/>
              <parameter key="1" value="docid.true.integer.attribute"/>
              <parameter key="2" value="word.true.polynominal.attribute"/>
              <parameter key="3" value="weight.true.real.attribute"/>
              <parameter key="4" value="class/label.true.binominal.attribute"/>
              <parameter key="5" value="timestamp.true.binominal.attribute"/>
            </list>
          </operator>
          <operator activated="true" class="select_attributes" compatibility="5.3.009" expanded="true" height="76" name="Remove id" width="90" x="179" y="30">
            <parameter key="attribute_filter_type" value="single"/>
            <parameter key="attribute" value="id"/>
            <parameter key="regular_expression" value="id_.*"/>
            <parameter key="invert_selection" value="true"/>
          </operator>
          <operator activated="true" class="pivot" compatibility="5.3.009" expanded="true" height="76" name="Pivot" width="90" x="313" y="30">
            <parameter key="group_attribute" value="docid"/>
            <parameter key="index_attribute" value="word"/>
          </operator>
          <operator activated="true" class="rename_by_replacing" compatibility="5.3.009" expanded="true" height="76" name="Remove prefix" width="90" x="447" y="30">
            <parameter key="replace_what" value="weight_"/>
          </operator>
          <operator activated="true" class="replace_missing_values" compatibility="5.3.009" expanded="true" height="94" name="Replace Missing Values" width="90" x="581" y="30">
            <parameter key="attribute_filter_type" value="value_type"/>
            <parameter key="value_type" value="numeric"/>
            <parameter key="default" value="zero"/>
            <list key="columns"/>
          </operator>
          <connect from_op="Read CSV" from_port="output" to_op="Remove id" to_port="example set input"/>
          <connect from_op="Remove id" from_port="example set output" to_op="Pivot" to_port="example set input"/>
          <connect from_op="Pivot" from_port="example set output" to_op="Remove prefix" to_port="example set input"/>
          <connect from_op="Remove prefix" from_port="example set output" to_op="Replace Missing Values" to_port="example set input"/>
          <connect from_op="Replace Missing Values" from_port="example set output" 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"/>
        </process>
      </operator>
    </process>
于 2013-05-17T14:27:39.240 回答