सेंटिमेंट एनालिसिस के लिए उच्च-क्रम n-grams
एक पहले वाले अभ्यास की तरह, हम एक classifier बनाएँगे जो बता सके कि किसी खास मूवी की review पॉज़िटिव है या नेगेटिव. लेकिन इस बार, हम n-grams को n=2 तक उपयोग करेंगे.
n-gram वाले training reviews X_train_ng के रूप में उपलब्ध हैं. इनके corresponding test reviews X_test_ng में हैं. अंत में, training और test की sentiment classes के लिए क्रमशः y_train और y_test का उपयोग करें.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में NLP के लिए Feature Engineering
अभ्यास निर्देश
- MultinomialNB का एक instance परिभाषित करें. इसका नाम
clf_ngरखें. - classifier को
X_train_ngऔरy_trainपर fit करें. score()method का उपयोग करकेX_test_ngऔरy_testपरaccuracyमापें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Define an instance of MultinomialNB
clf_ng = ____
# Fit the classifier
clf_ng.____(____, ____)
# Measure the accuracy
accuracy = ____
print("The accuracy of the classifier on the test set is %.3f" % accuracy)
# Predict the sentiment of a negative review
review = "The movie was not good. The plot had several holes and the acting lacked panache."
prediction = clf_ng.predict(ng_vectorizer.transform([review]))[0]
print("The sentiment predicted by the classifier is %i" % (prediction))