001/* 002 * Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.tribuo.evaluation; 018 019import com.oracle.labs.mlrg.olcut.provenance.Provenancable; 020import org.tribuo.Output; 021import org.tribuo.Prediction; 022import org.tribuo.evaluation.metrics.MetricID; 023import org.tribuo.provenance.EvaluationProvenance; 024 025import java.util.List; 026import java.util.Map; 027 028/** 029 * An immutable evaluation of a specific model and dataset. 030 * @param <T> The output type. 031 */ 032public interface Evaluation<T extends Output<T>> extends Provenancable<EvaluationProvenance> { 033 034 /** 035 * Get a map of all the metrics stored in this evaluation. The keys are metric id's and the values are their 036 * corresponding computed results. 037 * 038 * @return a map of all stored results 039 */ 040 public Map<MetricID<T>, Double> asMap(); 041 042 /** 043 * Gets the value associated with the specific metric. Throws {@link IllegalArgumentException} if 044 * the metric is unknown. 045 * @param key The metric to lookup. 046 * @return The value for that metric. 047 */ 048 public default double get(MetricID<T> key) { 049 Double value = asMap().get(key); 050 if (value == null) { 051 throw new IllegalArgumentException("Metric value not found: " + key.toString()); 052 } 053 return value; 054 } 055 056 /** 057 * Gets the predictions stored in this evaluation. 058 * @return The predictions. 059 */ 060 public List<Prediction<T>> getPredictions(); 061 062}