将ExampleSet设置为ExampleSet2SimilarityExampleSet Rapidminer操作符与Java

我创建了一个测量相似度的流程。我使用了ExampleSet2SimilarityExampleSet操作符,并且我想在输入中添加一个在我的代码中生成的示例集。

最初的想法是将我的示例集写入本地存储库。然后我将使用检索操作符读取示例集,并将检索操作符的输出连接到ExampleSet2SimilarityExampleSet操作符的输入。

所以我想知道是否可以避免读写操作。

  public class Test {        public static void main(String[] args) throws OperatorCreationException, OperatorException{            Test t = new Test();                    t.createprocess();        }          public void createprocess() throws OperatorCreationException, OperatorException{                RapidMiner.init();                ExampleSet exampleset = getExampleset();                Operator silimarityOperator = OperatorService.createOperator(ExampleSet2SimilarityExampleSet.class);        //        silimarityOperator.setParameter("measure_type", "NumericalMeasures");        //        silimarityOperator.setParameter("numerical_measure", "CosineSimilarity");                Process process = new Process();                process.getRootOperator().getSubprocess(0).addOperator(silimarityOperator);                process.getRootOperator().getSubprocess(0).getInnerSources().getPortByIndex(0).connectTo( silimarityOperator.getInputPorts().getPortByName("input"));                // 使用新创建的示例集运行流程                IOContainer run = process.run(new IOContainer(exampleset));                System.out.println(run.toString());            }            public ExampleSet getExampleset() {        // 构建属性集                Attribute[] attributes = new Attribute[3];                attributes[0] = AttributeFactory.createAttribute("Topic1", Ontology.STRING);                attributes[1] = AttributeFactory.createAttribute("Topic2", Ontology.STRING);                attributes[2] = AttributeFactory.createAttribute("Topic3", Ontology.STRING);                MemoryExampleTable table = new MemoryExampleTable(attributes);                DataRowFactory ROW_FACTORY = new DataRowFactory(0);                Double[] strings = new Double[3];                double a = 0;                for (int i = 0; i < 3; i++) {                    a++;                    strings[i] = a;                    // 创建并添加行                    DataRow row = ROW_FACTORY.create(strings, attributes);                    table.addDataRow(row);                }                ExampleSet exampleSet = table.createExampleSet();                return exampleSet;            }    }

回答:

我找到了解决方案。我在操作符连接时遇到了错误。没有名为“input”的端口,所以我使用了端口0。

 process.getRootOperator().getSubprocess(0).getInnerSources().getPortByIndex(0).connectTo(            silimarityOperator.getInputPorts().getPortByIndex(0));     silimarityOperator.getOutputPorts().getPortByIndex(0).connectTo(          process.getRootOperator().getSubprocess(0).getInnerSinks().getPortByIndex(0));

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注