package de.lmu.ifi.dbs.elki.evaluation.outlier;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see
* Key: {@code -rocauc.positive} *
*/ public static final OptionID POSITIVE_CLASS_NAME_ID = new OptionID("outliereval.positive", "Class label for the 'positive' class."); /** * Stores the "positive" class. */ private Pattern positiveClassName; /** * Key prefix for statistics logging. */ private String key = OutlierRankingEvaluation.class.getName(); /** * Constructor. * * @param positive_class_name Positive class name pattern */ public OutlierRankingEvaluation(Pattern positive_class_name) { super(); this.positiveClassName = positive_class_name; } private EvaluationResult evaluateOutlierResult(int size, SetDBIDs positiveids, OutlierResult or) { EvaluationResult res = new EvaluationResult("Evaluation of ranking", "ranking-evaluation"); DBIDsTest test = new DBIDsTest(positiveids); MeasurementGroup g = res.newGroup("Evaluation measures"); double rocauc = ROCEvaluation.STATIC.evaluate(test, new OutlierScoreAdapter(or)); g.addMeasure("ROC AUC", rocauc, 0., 1. ,.5, false); double avep = AveragePrecisionEvaluation.STATIC.evaluate(test, new OutlierScoreAdapter(or)); g.addMeasure("Average Precision", avep, 0., 1., 0., false); double rprec = PrecisionAtKEvaluation.RPRECISION.evaluate(test, new OutlierScoreAdapter(or)); g.addMeasure("R-Precision", rprec, 0., 1., 0., false); double maxf1 = MaximumF1Evaluation.STATIC.evaluate(test, new OutlierScoreAdapter(or)); g.addMeasure("Maximum F1", maxf1, 0., 1., 0., false); if(LOG.isStatistics()) { LOG.statistics(new DoubleStatistic(key + ".rocauc", rocauc)); LOG.statistics(new DoubleStatistic(key + ".precision.average", rocauc)); LOG.statistics(new DoubleStatistic(key + ".precision.r", rocauc)); LOG.statistics(new DoubleStatistic(key + ".f1.maximum", rocauc)); } return res; } private EvaluationResult evaluateOrderingResult(int size, SetDBIDs positiveids, DBIDs order) { if(order.size() != size) { throw new IllegalStateException("Iterable result doesn't match database size - incomplete ordering?"); } EvaluationResult res = new EvaluationResult("Evaluation of ranking", "ranking-evaluation"); DBIDsTest test = new DBIDsTest(positiveids); MeasurementGroup g = res.newGroup("Evaluation measures"); double rocauc = ROCEvaluation.STATIC.evaluate(test, new SimpleAdapter(order.iter())); g.addMeasure("ROC AUC", rocauc, 0., 1. ,.5, false); double avep = AveragePrecisionEvaluation.STATIC.evaluate(test, new SimpleAdapter(order.iter())); g.addMeasure("Average Precision", avep, 0., 1., 0., false); double rprec = PrecisionAtKEvaluation.RPRECISION.evaluate(test, new SimpleAdapter(order.iter())); g.addMeasure("R-Precision", rprec, 0., 1., 0., false); double maxf1 = MaximumF1Evaluation.STATIC.evaluate(test, new SimpleAdapter(order.iter())); g.addMeasure("Maximum F1", maxf1, 0., 1., 0., false); if(LOG.isStatistics()) { LOG.statistics(new DoubleStatistic(key + ".rocauc", rocauc)); LOG.statistics(new DoubleStatistic(key + ".precision.average", rocauc)); LOG.statistics(new DoubleStatistic(key + ".precision.r", rocauc)); LOG.statistics(new DoubleStatistic(key + ".f1.maximum", rocauc)); } return res; } @Override public void processNewResult(HierarchicalResult baseResult, Result result) { Database db = ResultUtil.findDatabase(baseResult); SetDBIDs positiveids = DBIDUtil.ensureSet(DatabaseUtil.getObjectsByLabelMatch(db, positiveClassName)); if(positiveids.size() == 0) { LOG.warning("Cannot evaluate outlier results - no objects matched the given pattern."); return; } boolean nonefound = true; List