Advertisement
gandalfbialy

Untitled

May 24th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. def predict(model, text):
  2. words = preprocess(text)
  3. best_class, best_log = None, -float("inf")
  4. for c in model["class_counts"]:
  5. lp = log_prob(model, words, c)
  6. if lp > best_log:
  7. best_class, best_log = c, lp
  8. return best_class
  9.  
  10. def evaluate_model(model, test_data):
  11. correct = 0
  12. for rec in test_data:
  13. prediction = predict(model, rec["text"])
  14. if prediction == rec["label"]:
  15. correct += 1
  16. accuracy = correct / len(test_data)
  17. print(f"Skuteczność na zbiorze testowym: {accuracy * 100:.2f}%")
  18. return accuracy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement