Nltk nativebayes classification without Bigrams - sapnilcsecu/Nltk-sentiment-analysis GitHub Wiki

Nltk nativebayes classification without Bigrams

Following are the steps required to create a text classification model without Bigrams in Python:

  1. Import the library
  2. load the positive and negative review and create the feature
  3. Prepare train and test dataset
  4. Training Text Classification Model and Evaluating The Model

Import the library

Execute the following script to import the required libraries:

import nltk.classify.util
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import movie_reviews
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
import nltk

load the positive and negative review and create the feature dictionary

Execute the following script load the positive and negative review and create the feature then add to the feature dictionary

      for fileid in movie_reviews.fileids('pos'):
        words = movie_reviews.words(fileid)
        pos_reviews.append((create_word_features(words), "positive"))
 

      for fileid in movie_reviews.fileids('neg'):
        words1 = movie_reviews.words(fileid)
        neg_reviews.append((create_word_features(words1), "negative"))

Prepare train and test dataset

Execute the following script for preparing train and test dataset

    train_set = neg_reviews[:750] + pos_reviews[:750]
    test_set = neg_reviews[750:] + pos_reviews[750:]

Training Text Classification Model and Evaluating The Model

Execute the following script for Training Text Classification Model and Evaluating The Model

    classifier = NaiveBayesClassifier.train(train_set)
    accuracy = nltk.classify.util.accuracy(classifier, test_set)
    print(accuracy * 100) 

complere source code you can get in this link Senti_model

⚠️ **GitHub.com Fallback** ⚠️