← Lesson
Baselines
Joeven
Run
Reset
Python loads on first run
# 0 = search, 1 = sql, 2 = finish examples = [ ("weather", 0), ("docs", 0), ("revenue", 1), ("users", 1), ("done", 2), ("thanks", 2), ("select", 1), ("hello", 0), ] def majority(rows): counts = {} for _, y in rows: counts[y] = counts.get(y, 0) + 1 return max(counts, key=counts.get) def keywords(text): t = text.lower() if t in {"revenue", "users", "select"}: return 1 if t in {"done", "thanks", "stop"}: return 2 return 0 def acc(fn): return sum(fn(x) == y for x, y in examples) / len(examples) maj = majority(examples) print("majority class", maj, "acc", round(sum(maj == y for _, y in examples) / len(examples), 2)) print("keyword acc", round(acc(keywords), 2)) print("always-search acc", round(sum(0 == y for _, y in examples) / len(examples), 2))
Run to execute this in your browser. Nothing is sent to a server.