类别

版本

您正在查看版本9.2的RapidMiner开发人员文档查看最新版本

RapidMiner 7.3中的API变化

RapidMiner 7.3带来了两个影响扩展开发的变化。首先,一个用于创建数据集的中央API (ExampleSet实例)。第二,ExampleSet接口通过一种方法进行扩展,以允许释放未使用的数据。

只有当扩展包含生成新数据集或定义自己的数据集的操作符时,这些更改才会影响您ExampleSetS(例如,自定义视图)。

生成数据集

RapidMiner 7.3添加ExampleSets类,它提供一组用于构建新数据集的静态方法。的直接实例化ExampleTable实现,例如MemoryExampleTable.的所有公共构造函数MemoryExampleTable类已弃用。

新的API提供了从柱状数据和面向行数据创建数据集的方法:

进口com.rapidminer.example.Attribute;进口com.rapidminer.example.Attributes;进口com.rapidminer.example.ExampleSet;进口com.rapidminer.example.table.AttributeFactory;进口com.rapidminer.example.table.BinominalMapping;进口com.rapidminer.example.table.DataRow;进口com.rapidminer.example.table.DataRowFactory;进口com.rapidminer.example.table.NominalMapping;进口com.rapidminer.example.utils.ExampleSetBuilder;进口com.rapidminer.example.utils.ExampleSets; import com.rapidminer.operator.Operator; import com.rapidminer.operator.OperatorDescription; import com.rapidminer.operator.OperatorException; import com.rapidminer.tools.Ontology; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.List; /** Create example set using column fillers */ Attribute topTen = AttributeFactory.createAttribute("Top Ten Numbers", Ontology.INTEGER); Attribute coinFlip = AttributeFactory.createAttribute("Coin Flip", Ontology.BINOMINAL); NominalMapping coin = new BinominalMapping(); int heads = coin.mapString("Heads"); int tails = coin.mapString("Tails"); coinFlip.setMapping(coin); ExampleSet numbers = ExampleSets.from(topTen, coinFlip) .withRole(topTen, Attributes.ID_NAME) .withBlankSize(10) .withColumnFiller(topTen, i -> i + 1) .withColumnFiller(coinFlip, i -> Math.random() < 0.5 ? heads : tails) .build(); /** Create example set from double matrix */ ExampleSetBuilder builder = ExampleSets.from(AttributeFactory.createAttribute(Ontology.REAL), AttributeFactory.createAttribute(Ontology.REAL), AttributeFactory.createAttribute(Ontology.REAL)); builder.withExpectedSize(10); double rawData[][] = new double[10][3]; for (double[] row : rawData) { builder.addRow(row); } ExampleSet matrix = builder.build(); /** Create example set from custom DataRows */ Attribute nominalAttribute = AttributeFactory.createAttribute("Nominal", Ontology.NOMINAL); Attribute numericalAttribute = AttributeFactory.createAttribute("Numerical", Ontology.REAL); Attribute dateTimeAttribute = AttributeFactory.createAttribute("DateTime", Ontology.DATE_TIME); List attributes = new ArrayList<>(); attributes.add(nominalAttribute); attributes.add(numericalAttribute); attributes.add(dateTimeAttribute); ExampleSetBuilder builder = ExampleSets.from(attributes).withExpectedSize(2); DataRowFactory dataRowFactory = new DataRowFactory(DataRowFactory.TYPE_DOUBLE_ARRAY, '.'); DataRow dataRow = dataRowFactory.create(attributes.size()); // this is important, for nominal attributes the value to set in the data row is the index of the mapped string! dataRow.set(nominalAttribute, nominalAttribute.getMapping().mapString("Hello")); dataRow.set(numericalAttribute, 1.0); dataRow.set(dateTimeAttribute, Instant.now().toEpochMilli()); builder.addDataRow(dataRow); dataRow = dataRowFactory.create(attributes.size()); // see comment above, index of the mapped string! dataRow.set(nominalAttribute, nominalAttribute.getMapping().mapString("World")); dataRow.set(numericalAttribute, 42.0); dataRow.set(dateTimeAttribute, Instant.now().plus(Duration.ofDays(1)).toEpochMilli()); builder.addDataRow(dataRow); ExampleSet exampleSet = builder.build();

释放未使用的资源乐鱼体育安装

ExampleSet接口已被扩展清理()方法。RapidMiner将在流程执行的某些点调用此方法,例如,在操作符之间。请注意,默认实现什么也不做。

/** *释放未使用的资源,如果实现支乐鱼体育安装持。默认情况下不做任何事情。* *只能在新{@link #clone}ed {@link ExampleSet}上使用,以确保之后不会请求*已清理的资源。乐鱼体育安装* * @since 7.3 */ public default void cleanup(){//默认什么都不做}

当实现管理自己资源的自定义示例集时,请使用此方法释放未使用的数据,例如临时属性。乐鱼体育安装

如果您不管理自己的资源,而是实现一个自定义乐鱼体育安装ExampleSet那作为另一个数据集之上的视图,请相应地委派调用。

例如,RapidMiner的大多数视图实现都引用了一个设置示例。因此,他们的实施清理()归结起来就是:

@覆盖公共无效清理(){parent.cleanup();}