Compare commits

..

2 Commits

Author SHA1 Message Date
93d8bf4a5b finished TextBlob hw 2026-04-01 11:41:21 -04:00
4887c03420 added test.json 2026-04-01 11:39:35 -04:00
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
[
{"text": "The beer was good.", "label": "pos"},
{"text": "I do not enjoy my job", "label": "neg"},
{"text": "I feel amazing!", "label": "pos"},
{"text": "I am very tired", "label": "neg"}
]

View File

@@ -0,0 +1,31 @@
from textblob.classifiers import NaiveBayesClassifier
from pathlib import Path
def main():
# Get directory where this script is located
base_dir = Path(__file__).parent
# Build paths to data files
train_path = base_dir / "train.json"
test_path = base_dir / "test.json"
# Load training data
with open(train_path, "r") as train_file:
classifier = NaiveBayesClassifier(train_file, format="json")
# Load test data
with open(test_path, "r") as test_file:
accuracy = classifier.accuracy(test_file)
print("Accuracy:", accuracy)
print("Classifying sentences:")
print("I love this place ->", classifier.classify("I love this place"))
print("I hate this job ->", classifier.classify("I hate this job"))
print("\nMost Informative Features:")
classifier.show_informative_features(5)
if __name__ == "__main__":
main()