Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def predict(model, text):
- words = preprocess(text)
- best_class, best_log = None, -float("inf")
- for c in model["class_counts"]:
- lp = log_prob(model, words, c)
- if lp > best_log:
- best_class, best_log = c, lp
- return best_class
- def evaluate_model(model, test_data):
- correct = 0
- for rec in test_data:
- prediction = predict(model, rec["text"])
- if prediction == rec["label"]:
- correct += 1
- accuracy = correct / len(test_data)
- print(f"Skuteczność na zbiorze testowym: {accuracy * 100:.2f}%")
- return accuracy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement