[英]Integration of Rapidminer with Java: Obtaining the output Example Set (Process Result)
I want to execute a Rapidminer process from Java to use the output ExampleSet (Process Result) for subsequent operations (with Java). 我想从Java执行Rapidminer流程,以将输出ExampleSet(流程结果)用于后续操作(与Java一起使用)。
I managed the process execution with the code below, but I don't have a clue how to obtain the process Result Example Set. 我使用下面的代码管理流程的执行,但是我不知道如何获取流程结果示例集。
Ideally, I want to get any Example Set independent of the variables, but if you need to generate the metadata beforehand, will have to be. 理想情况下,我想获取任何独立于变量的示例集,但是如果您需要事先生成元数据,则必须这样做。
package com.companyname.rm;
import com.rapidminer.Process;
import com.rapidminer.RapidMiner;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.tools.XMLException;
import java.io.File;
import java.io.IOException;
public class RunProcess {
public static void main(String[] args) {
try {
RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
RapidMiner.init();
Process process = new Process(new File("//my_path/..../test_JAVA.rmp"));
process.run();
} catch (IOException | XMLException | OperatorException ex) {
ex.printStackTrace();
}
}
}
To obtain the ExampleSet of the process you need add 要获取流程的ExampleSet,您需要添加
IOContainer ioResult = process.run();
A shortened example taken from http://allinoneat.blogspot.de/2013/04/integrate-rapidminer-wtih-java.html 摘自http://allinoneat.blogspot.de/2013/04/integrate-rapidminer-wtih-java.html的简短示例
IOContainer ioResult = process.run();
if (ioResult.getElementAt(0) instanceof ExampleSet) {
ExampleSet resultSet = (ExampleSet) ioResult.getElementAt(0);
for (Example example : resultSet) {
Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
while (allAtts.hasNext()) {
Attribute a = allAtts.next();
if (a.isNumerical()) {
double value = example.getValue(a);
System.out.print(value + " ");
} else {
String value = example.getValueAsString(a);
System.out.print(value + " ");
}
}
System.out.println("\n");
}
}
Option 1: Click on context, and save process output to files. 选项1:单击上下文,然后将过程输出保存到文件中。 Then, read from files.
然后,从文件中读取。
Option2: 选项2:
Use the WriteAsText to save what you want. 使用WriteAsText保存所需的内容。 Then read from the file.
然后从文件中读取。
I just run the rapidminer as a script: 我只是将Rapidminer作为脚本运行:
http://rapid-i.com/rapidforum/index.php?topic=3009.0 http://rapid-i.com/rapidforum/index.php?topic=3009.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.