liveBook · Manning

Evaluation

As explained in AI-Powered Search

Evaluation is the systematic measurement of a model's performance on data separate from the examples used for training.

Evaluation measures whether a search model generalizes beyond its training examples. Hold out queries or judgments, train only on the training portion, then rank unseen test queries and calculate a relevance metric such as precision. section 10.5.3 section 12.1.2

A practical evaluation loop is:

  • Split data at the query level so judgments from one query do not leak between training and testing. section 10.5.3
  • Train the ranking model only on the training judgments. section 10.5.3
  • Rank each test query, count relevant results among the top k, and average precision across queries. section 10.5.3
  • Compare feature choices and revisit incorrectly ranked results, while treating offline scores as evidence rather than a guarantee of live success. section 10.5.3 section 12.1.2
Listing 10.15 Can our model generalize beyond the training data?
def score_one(features, model):
  score = 0.0
  for idx, f in enumerate(features):
    this_coef = model.coef_[0][idx].item()
    score += f * this_coef
  return score

def rank(query_judgments, model):
  for j in query_judgments:
    j.score = score_one(j.features, model)
  return sorted(query_judgments, key=lambda j: j.score, reverse=True)

def evaluate_model(test_data, model, k=5):
  total_precision = 0
  unique_queries = groupby(test_data, lambda j: j.qid)
  num_groups = 0
  for qid, query_judgments in unique_queries: #1
    num_groups += 1
    ranked = rank(list(query_judgments), model)  #2
    total_relevant = len([j for j in ranked[:k]
                            if j.grade == 1])  #3
    total_precision += total_relevant / float(k)
  return total_precision / num_groups

evaluation = evaluate_model(test_data, model)
print(evaluation)

The implementation groups judgments by query, scores and sorts them with a trained model, computes top-k precision, and averages the result. section 10.5.3

How AI-Powered Search covers it

How deep it goes
Provides an implementation-level split, training, ranking, and precision workflow, but defers broader metric selection and live validation.
Examples
Demonstrates query-level splitting, movie-ranking features, top-four precision near 0.3–0.4, and a test evaluation of 0.36.
What it assumes
Assumes labeled query judgments, extracted ranking features, a trainable model, and familiarity with search relevance.
What you can do after
Diagnose ranking quality with held-out queries, calculate precision, and identify features or examples needing improvement.
How it connects
Connects learning to rank with train/test splits, precision, feature engineering, and A/B testing.

Also explained in

Compare how 15 books explain evaluation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.