本文整理汇总了Java中com.rapidminer.operator.learner.PredictionModel类的典型用法代码示例。如果您正苦于以下问题:Java PredictionModel类的具体用法?Java PredictionModel怎么用?Java PredictionModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PredictionModel类属于com.rapidminer.operator.learner包,在下文中一共展示了PredictionModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/**
* Applies the applier and evaluator (= second subprocess). In order to reuse possibly created
* predicted label attributes, we do the following: We compare the predicted label of
* <code>testSet</code> before and after applying the inner operator. If it changed, the
* predicted label is removed again. No outer operator could ever see it. The same applies for
* the confidence attributes in case of classification learning.
*/
protected final void evaluate(ExampleSet testSet) throws OperatorException {
Attribute predictedBefore = testSet.getAttributes().getPredictedLabel();
applyProcessExampleSetOutput.deliver(testSet);
applyProcessModelOutput.deliver(trainingProcessModelInput.getData(IOObject.class));
throughExtender.passDataThrough();
executeEvaluator();
Tools.buildAverages(applyProcessPerformancePortExtender);
Attribute predictedAfter = testSet.getAttributes().getPredictedLabel();
// remove predicted label and confidence attributes if there is a new prediction which is
// not equal to an old one
if (predictedAfter != null
&& (predictedBefore == null || predictedBefore.getTableIndex() != predictedAfter.getTableIndex())) {
PredictionModel.removePredictedLabel(testSet);
}
}
示例2: BayesianBoosting
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/** Constructor. */
public BayesianBoosting(OperatorDescription description) {
super(description);
modelInput.addPrecondition(new SimplePrecondition(modelInput, new PredictionModelMetaData(PredictionModel.class,
new ExampleSetMetaData()), false));
addValue(new ValueDouble("performance", "The performance.") {
@Override
public double getDoubleValue() {
return performance;
}
});
addValue(new ValueDouble("iteration", "The current iteration.") {
@Override
public double getDoubleValue() {
return currentIteration;
}
});
}
示例3: residualReplace
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/**
* This methods replaces the labels of the given example set with the label residuals after
* using the given model. Please note that the label column will be overwritten and the original
* label should be stored!
*/
private void residualReplace(ExampleSet exampleSet, Model model, boolean shrinkage) throws OperatorException {
ExampleSet resultSet = model.apply(exampleSet);
Attribute label = exampleSet.getAttributes().getLabel();
Iterator<Example> originalReader = exampleSet.iterator();
Iterator<Example> predictionReader = resultSet.iterator();
while ((originalReader.hasNext()) && (predictionReader.hasNext())) {
Example originalExample = originalReader.next();
Example predictionExample = predictionReader.next();
double prediction = predictionExample.getPredictedLabel();
if (shrinkage) {
prediction *= getParameterAsDouble(PARAMETER_SHRINKAGE);
}
double residual = originalExample.getLabel() - prediction;
originalExample.setValue(label, residual);
}
PredictionModel.removePredictedLabel(resultSet);
}
示例4: residualReplace
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/**
* This methods replaces the labels of the given example set with the label residuals after
* using the given model. Please note that the label column will be overwritten and the original
* label should be stored!
*/
private void residualReplace(ExampleSet exampleSet, Model model, boolean shrinkage) throws OperatorException {
ExampleSet resultSet = model.apply(exampleSet);
Attribute label = exampleSet.getAttributes().getLabel();
Iterator<Example> originalReader = exampleSet.iterator();
Iterator<Example> predictionReader = resultSet.iterator();
double shrinkageValue = 0;
if (shrinkage) {
shrinkageValue = getParameterAsDouble(PARAMETER_SHRINKAGE);
}
while (originalReader.hasNext() && predictionReader.hasNext()) {
Example originalExample = originalReader.next();
Example predictionExample = predictionReader.next();
double prediction = predictionExample.getPredictedLabel();
if (shrinkage) {
prediction *= shrinkageValue;
}
double residual = originalExample.getLabel() - prediction;
originalExample.setValue(label, residual);
}
PredictionModel.removePredictedLabel(resultSet);
}
示例5: evaluate
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/**
* Applies the applier and evaluator (= second subprocess).
* In order to reuse possibly created predicted label attributes, we do the
* following: We compare the predicted label of <code>testSet</code>
* before and after applying the inner operator. If it changed, the
* predicted label is removed again. No outer operator could ever see it.
* The same applies for the confidence attributes in case of classification
* learning.
*/
protected final void evaluate(ExampleSet testSet) throws OperatorException {
Attribute predictedBefore = testSet.getAttributes().getPredictedLabel();
applyProcessExampleSetOutput.deliver(testSet);
applyProcessModelOutput.deliver(trainingProcessModelInput.getData(IOObject.class));
throughExtender.passDataThrough();
executeEvaluator();
Tools.buildAverages(applyProcessPerformancePortExtender);
Attribute predictedAfter = testSet.getAttributes().getPredictedLabel();
// remove predicted label and confidence attributes if there is a new prediction which is not equal to an old one
if ((predictedAfter != null) && ((predictedBefore == null) ||
(predictedBefore.getTableIndex() != predictedAfter.getTableIndex()))) {
PredictionModel.removePredictedLabel(testSet);
}
}
示例6: BayesianBoosting
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/** Constructor. */
public BayesianBoosting(OperatorDescription description) {
super(description);
modelInput.addPrecondition(new SimplePrecondition(modelInput, new PredictionModelMetaData(PredictionModel.class, new ExampleSetMetaData()), false));
addValue(new ValueDouble("performance", "The performance.") {
@Override
public double getDoubleValue() {
return performance;
}
});
addValue(new ValueDouble("iteration", "The current iteration.") {
@Override
public double getDoubleValue() {
return currentIteration;
}
});
}
示例7: residualReplace
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/**
* This methods replaces the labels of the given example set with the label residuals after using the given model.
* Please note that the label column will be overwritten and the original label should be stored!
*/
private void residualReplace(ExampleSet exampleSet, Model model, boolean shrinkage) throws OperatorException {
ExampleSet resultSet = model.apply(exampleSet);
Attribute label = exampleSet.getAttributes().getLabel();
Iterator<Example> originalReader = exampleSet.iterator();
Iterator<Example> predictionReader = resultSet.iterator();
while ((originalReader.hasNext()) && (predictionReader.hasNext())) {
Example originalExample = originalReader.next();
Example predictionExample = predictionReader.next();
double prediction = predictionExample.getPredictedLabel();
if (shrinkage)
prediction *= getParameterAsDouble(PARAMETER_SHRINKAGE);
double residual = originalExample.getLabel() - prediction;
originalExample.setValue(label, residual);
}
PredictionModel.removePredictedLabel(resultSet);
}
示例8: doWork
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
Model model = modelInput.getData(Model.class);
// some checks
if (exampleSet.getAttributes().getLabel() == null) {
throw new UserError(this, 105, new Object[0]);
}
if (exampleSet.getAttributes().size() == 0) {
throw new UserError(this, 106, new Object[0]);
}
final Attribute label = this.extractLabel(model, exampleSet);
PlattParameters plattParams;
{
ExampleSet calibrationSet = (ExampleSet) exampleSet.clone();
calibrationSet = model.apply(calibrationSet);
plattParams = computeParameters(calibrationSet, label);
PredictionModel.removePredictedLabel(calibrationSet);
}
PlattScalingModel scalingModel = new PlattScalingModel(exampleSet, model, plattParams);
exampleSetOutput.deliver(scalingModel.apply(exampleSet));
modelOutput.deliver(scalingModel);
}
示例9: extractLabel
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
private Attribute extractLabel(Model model, ExampleSet exampleSet) {
if (model instanceof PredictionModel) {
return ((PredictionModel) model).getLabel();
}
logWarning("Could not find label in model for Platt's Scaling, using Label of provided ExampleSet instead.");
return exampleSet.getAttributes().getLabel();
}
示例10: doWork
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
if (exampleSet.getAttributes().getLabel() == null) {
throw new UserError(this, 105);
}
if (!exampleSet.getAttributes().getLabel().isNominal()) {
throw new UserError(this, 101, "ROC Charts", exampleSet.getAttributes().getLabel());
}
if (exampleSet.getAttributes().getLabel().getMapping().getValues().size() != 2) {
throw new UserError(this, 114, "ROC Charts", exampleSet.getAttributes().getLabel());
}
if (exampleSet.getAttributes().getPredictedLabel() != null && getParameterAsBoolean(PARAMETER_USE_MODEL)) {
getLogger().warning("Input example already has a predicted label which will be removed.");
PredictionModel.removePredictedLabel(exampleSet);
}
if (exampleSet.getAttributes().getPredictedLabel() == null && !getParameterAsBoolean(PARAMETER_USE_MODEL)) {
throw new UserError(this, 107);
}
Model model = null;
if (getParameterAsBoolean(PARAMETER_USE_MODEL)) {
model = modelInput.getData(Model.class);
exampleSet = model.apply(exampleSet);
}
if (exampleSet.getAttributes().getPredictedLabel() == null) {
throw new UserError(this, 107);
}
ROCDataGenerator rocDataGenerator = new ROCDataGenerator(1.0d, 1.0d);
ROCData rocPoints = rocDataGenerator.createROCData(exampleSet, getParameterAsBoolean(PARAMETER_USE_EXAMPLE_WEIGHTS),
ROCBias.getROCBiasParameter(this));
rocDataGenerator.createROCPlotDialog(rocPoints);
PredictionModel.removePredictedLabel(exampleSet);
modelOutput.deliver(model);
exampleSetOutput.deliver(exampleSet);
}
示例11: doWork
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
Model model = modelInput.getData(Model.class);
if (exampleSet.getAttributes().getLabel() == null) {
throw new UserError(this, 105);
}
if (!exampleSet.getAttributes().getLabel().isNominal()) {
throw new UserError(this, 101, "Lift Charts", exampleSet.getAttributes().getLabel());
}
if (exampleSet.getAttributes().getLabel().getMapping().getValues().size() != 2) {
throw new UserError(this, 114, "Lift Charts", exampleSet.getAttributes().getLabel());
}
ExampleSet workingSet = (ExampleSet) exampleSet.clone();
if (workingSet.getAttributes().getPredictedLabel() != null) {
PredictionModel.removePredictedLabel(workingSet);
}
workingSet = model.apply(workingSet);
if (workingSet.getAttributes().getPredictedLabel() == null) {
throw new UserError(this, 107);
}
LiftDataGenerator liftDataGenerator = new LiftDataGenerator();
List<double[]> liftPoints = liftDataGenerator.createLiftDataList(workingSet);
liftDataGenerator.createLiftChartPlot(liftPoints);
PredictionModel.removePredictedLabel(workingSet);
exampleSetOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
示例12: applyPriorModel
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/**
* Helper method applying the start model and adding it to the modelInfo collection
*/
private void applyPriorModel(ExampleSet trainingSet, List<BayBoostBaseModelInfo> modelInfo) throws OperatorException {
// If the input contains a model already, initialise the example weights.
if (this.startModel != null) {
ExampleSet resultSet = this.startModel.apply((ExampleSet) trainingSet.clone());
// Initial values and the input model are stored in the output model.
WeightedPerformanceMeasures wp = new WeightedPerformanceMeasures(resultSet);
this.reweightExamples(wp, resultSet);
modelInfo.add(new BayBoostBaseModelInfo(this.startModel, wp.getContingencyMatrix()));
PredictionModel.removePredictedLabel(resultSet);
}
}
示例13: performPrediction
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
@Override
public ExampleSet performPrediction(ExampleSet exampleSet, Attribute predictedLabel) throws OperatorException {
// apply default model
exampleSet = defaultModel.apply(exampleSet);
double[] predictions = new double[exampleSet.size()];
Iterator<Example> e = exampleSet.iterator();
int counter = 0;
while (e.hasNext()) {
predictions[counter++] = e.next().getPredictedLabel();
}
PredictionModel.removePredictedLabel(exampleSet);
// apply all models to the example set sum up the predictions
for (int i = 0; i < residualModels.length; i++) {
exampleSet = residualModels[i].apply(exampleSet);
e = exampleSet.iterator();
counter = 0;
while (e.hasNext()) {
predictions[counter++] += shrinkage * e.next().getPredictedLabel();
}
PredictionModel.removePredictedLabel(exampleSet);
}
// set final predictions
e = exampleSet.iterator();
counter = 0;
Attribute newPredictedLabel = createPredictedLabel(exampleSet, getLabel());
while (e.hasNext()) {
e.next().setValue(newPredictedLabel, predictions[counter++]);
}
return exampleSet;
}
示例14: performPredictionRecursivly
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
/**
* This method will apply all the nodes recursively. For each node it will be called when
* descending the learner hierarchy. The outcomes array stores the information to which node
* each example of the applySet has been assigned. Each node's model will be applied to the
* subset of a partitioned example set according to the node's partition id. After the
* classification has been performed, the examples will be assigned the partion id's of the
* child nodes, to whose class the examples where classified.
*
* It is very important that after each application the predicted label and the confidences are
* removed explicitly to avoid a memory leak in the memory table!
*
* Confidences are multiplied with the outcome every application.
*/
private void performPredictionRecursivly(ExampleSet applySet, Node node, double[] confidences, int[] outcomes,
int[] depths, int depth, int numberOfPartitions) throws OperatorException {
if (!node.isLeaf()) {
// creating partitioned example set
SplittedExampleSet splittedSet = new SplittedExampleSet(applySet, new Partition(outcomes, numberOfPartitions));
splittedSet.selectSingleSubset(node.getPartitionId());
// applying
ExampleSet currentResultSet = node.getModel().apply(splittedSet);
// assign each example a child node regarding to the classification outcome
int resultIndex = 0;
Attribute predictionAttribute = currentResultSet.getAttributes().getPredictedLabel();
for (Example example : currentResultSet) {
int parentIndex = splittedSet.getActualParentIndex(resultIndex);
// extracting data
String label = example.getValueAsString(predictionAttribute);
confidences[parentIndex] *= example.getConfidence(label);
// setting outcome index according to referenced child node: if child is leaf, this
// is equivalent to class index
outcomes[parentIndex] = node.getChild(label).getPartitionId();
depths[parentIndex] = depth;
resultIndex++;
}
// deleting new columns from example table
PredictionModel.removePredictedLabel(currentResultSet);
// now go through children and apply their subset
for (Node child : node.getChildren()) {
performPredictionRecursivly(applySet, child, confidences, outcomes, depths, depth + 1, numberOfPartitions);
}
}
}
示例15: AbstractStacking
import com.rapidminer.operator.learner.PredictionModel; //导入依赖的package包/类
public AbstractStacking(OperatorDescription description, String... subprocessNames) {
super(description, subprocessNames);
baseInputExtender.start();
baseModelExtender.start();
getTransformer().addRule(baseInputExtender.makePassThroughRule(exampleSetInput));
getTransformer().addRule(new SubprocessTransformRule(getSubprocess(0)));
getTransformer().addRule(
new GeneratePredictionModelTransformationRule(exampleSetInput, modelOutput, PredictionModel.class));
}