【问题标题】:Integration of Rapidminer with Java: Obtaining the output Example Set (Process Result)Rapidminer 与 Java 的集成:获取输出示例集(处理结果)
【发布时间】:2014-05-30 20:54:44
【问题描述】:

我想从 Java 执行 Rapidminer 进程,以使用输出 ExampleSet (Process Result) 进行后续操作(使用 Java)。

我使用下面的代码管理流程执行,但我不知道如何获取流程结果示例集。

理想情况下,我希望获得独立于变量的任何示例集,但如果您需要预先生成元数据,则必须这样做。

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();
        }
    }
}

【问题讨论】:

    标签: java rapidminer


    【解决方案1】:

    获取流程的ExampleSet需要添加

    IOContainer ioResult = process.run();
    

    取自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");
         }
    }
    

    【讨论】:

      【解决方案2】:

      选项 1: 单击上下文,并将过程输出保存到文件。 然后,从文件中读取。

      选项2:

      使用 WriteAsText 保存您想要的内容。然后从文件中读取。

      我只是将 rapidminer 作为脚本运行:

      http://rapid-i.com/rapidforum/index.php?topic=3009.0

      【讨论】:

      • 感谢您的回答。该解决方案涵盖了我想要的所有内容,但我需要一些更克制的东西,考虑一个外部化的生产过程。
      猜你喜欢
      • 2014-05-07
      • 2018-09-18
      • 2017-03-05
      • 1970-01-01
      • 2023-04-07
      • 2015-12-27
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      相关资源
      最近更新 更多