Class PrecisionAtK

java.lang.Object
org.opensearch.index.rankeval.PrecisionAtK
All Implemented Interfaces:
NamedWriteable, Writeable, ToXContent, ToXContentObject, EvaluationMetric

public class PrecisionAtK
extends java.lang.Object
implements EvaluationMetric
Metric implementing Precision@K (https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval)#Precision).
By default documents with a rating equal or bigger than 1 are considered to be "relevant" for this calculation. This value can be changed using the `relevant_rating_threshold` parameter.
The `ignore_unlabeled` parameter (default to false) controls if unrated documents should be ignored. The `k` parameter (defaults to 10) controls the search window size.
  • Field Details

  • Constructor Details

    • PrecisionAtK

      public PrecisionAtK​(int relevantRatingThreshold, boolean ignoreUnlabeled, int k)
      Metric implementing Precision@K.
      Parameters:
      relevantRatingThreshold - ratings equal or above this value will be considered relevant.
      ignoreUnlabeled - Controls how unlabeled documents in the search hits are treated. Set to 'true', unlabeled documents are ignored and neither count as true or false positives. Set to 'false', they are treated as false positives.
      k - controls the window size for the search results the metric takes into account
    • PrecisionAtK

      public PrecisionAtK​(boolean ignoreUnlabeled)
    • PrecisionAtK

      public PrecisionAtK()
  • Method Details

    • fromXContent

      public static PrecisionAtK fromXContent​(XContentParser parser)
    • writeTo

      public void writeTo​(StreamOutput out) throws java.io.IOException
      Specified by:
      writeTo in interface Writeable
      Throws:
      java.io.IOException
    • toXContent

      public XContentBuilder toXContent​(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
      Specified by:
      toXContent in interface ToXContent
      Throws:
      java.io.IOException
    • getWriteableName

      public java.lang.String getWriteableName()
      Specified by:
      getWriteableName in interface NamedWriteable
    • getRelevantRatingThreshold

      public int getRelevantRatingThreshold()
      Return the rating threshold above which ratings are considered to be "relevant" for this metric. Defaults to 1.
    • getIgnoreUnlabeled

      public boolean getIgnoreUnlabeled()
      Gets the 'ignore_unlabeled' parameter.
    • getK

      public int getK()
    • forcedSearchSize

      public java.util.OptionalInt forcedSearchSize()
      Description copied from interface: EvaluationMetric
      Metrics can define a size of the search hits windows they want to retrieve by overwriting this method. The default implementation returns an empty optional.
      Specified by:
      forcedSearchSize in interface EvaluationMetric
      Returns:
      the number of search hits this metrics requests
    • evaluate

      public EvalQueryQuality evaluate​(java.lang.String taskId, SearchHit[] hits, java.util.List<RatedDocument> ratedDocs)
      Compute precision at k based on provided relevant document IDs.
      Specified by:
      evaluate in interface EvaluationMetric
      Parameters:
      taskId - an identifier of the query for which the search ranking is evaluated
      hits - the search result hits
      ratedDocs - the documents that contain the document rating for this query case
      Returns:
      precision at k for above SearchResult list.
    • equals

      public final boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class java.lang.Object