Compare commits
2 Commits
5d4ec549c0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 93d8bf4a5b | |||
| 4887c03420 |
@@ -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"}
|
||||||
|
]
|
||||||
@@ -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()
|
||||||
Reference in New Issue
Block a user