Package org.elasticsearch.index.rankeval
Class PrecisionAtK
- java.lang.Object
-
- org.elasticsearch.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/Information_retrieval#Precision_at_K).
By default documents with a rating equal or bigger than 1 are considered to be "relevant" for this calculation. This value can be changes 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PrecisionAtK.Detail
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V extends java.lang.Object>, Writeable.Writer<V extends java.lang.Object>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NAME
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description PrecisionAtK()
PrecisionAtK(int threshold, boolean ignoreUnlabeled, int k)
Metric implementing Precision@K.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
EvalQueryQuality
evaluate(java.lang.String taskId, SearchHit[] hits, java.util.List<RatedDocument> ratedDocs)
Compute precisionAtN based on provided relevant document IDs.java.util.OptionalInt
forcedSearchSize()
Metrics can define a size of the search hits windows they want to retrieve by overwriting this method.static PrecisionAtK
fromXContent(XContentParser parser)
boolean
getIgnoreUnlabeled()
Gets the 'ignore_unlabeled' parameter.int
getRelevantRatingThreshold()
Return the rating threshold above which ratings are considered to be "relevant" for this metric.java.lang.String
getWriteableName()
int
hashCode()
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
void
writeTo(StreamOutput out)
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.index.rankeval.EvaluationMetric
combine
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PrecisionAtK
public PrecisionAtK(int threshold, boolean ignoreUnlabeled, int k)
Metric implementing Precision@K.- Parameters:
threshold
- 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()
-
-
Method Detail
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
-
getWriteableName
public java.lang.String getWriteableName()
- Specified by:
getWriteableName
in interfaceNamedWriteable
-
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.
-
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 interfaceEvaluationMetric
- Returns:
- the number of search hits this metrics requests
-
fromXContent
public static PrecisionAtK fromXContent(XContentParser parser)
-
evaluate
public EvalQueryQuality evaluate(java.lang.String taskId, SearchHit[] hits, java.util.List<RatedDocument> ratedDocs)
Compute precisionAtN based on provided relevant document IDs.- Specified by:
evaluate
in interfaceEvaluationMetric
- Parameters:
taskId
- an identifier of the query for which the search ranking is evaluatedhits
- the search result hitsratedDocs
- the documents that contain the document rating for this query case- Returns:
- precision at n for above
SearchResult
list.
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-