我有一个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文件中,然后将它们上传到快速采矿者,我希望快速采矿者能够更快地执行任务。通过使其接受第一种格式或将其更改为第二种格式或甚至是MYSQL查询来执行此操作。
考虑到向量表非常大(大约500 mb),因此可伸缩性是一个问题
答案 0 :(得分:1)
“Pivot”操作员将为您完成这项工作。将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>