← Lesson
What Is Machine Learning?
Joeven
Run
Reset
Python loads on first run
tickets = [ {"downs": 0, "urgent": 0}, {"downs": 1, "urgent": 0}, {"downs": 2, "urgent": 1}, {"downs": 3, "urgent": 1}, {"downs": 4, "urgent": 1}, ] def predict(downs, w, b, cutoff=0.5): score = w * downs + b return (1 if score >= cutoff else 0, score) def accuracy(w, b): ok = 0 for row in tickets: yhat, _ = predict(row["downs"], w, b) if yhat == row["urgent"]: ok += 1 return ok / len(tickets) for w, b in [(0.0, 0.0), (0.4, -0.5), (1.0, -1.5)]: print("w", w, "b", b, "acc", accuracy(w, b))
Run to execute this in your browser. Nothing is sent to a server.