Homework # 4

Write a program in Python that implements a Multinomial Naive Bayes classifier for sentiment analysis.
import modules import nltk from nltk.corpus import movie_reviews'movie_reviews')

You need to implement four functions as defined below:

1. A function build raw data: # There are 2000 reviews with Positive and Negative reviews.
You also need to remove stop words and lemmatize tokens.

from nltk.corpus import stopwords
set (stopwords.words('english'))

2. A function feature_selection: # This function will construct a set of features (words) for document representation.
You need to identify a list of features (1-grams or 2-grams).
Ideally you want about 1000 features, but you need to experiment based on your classifier accuracy.

3. A function text_to_vector: # This function will convert each review to a vector of frequencies.
Each vector has the same dimension as the list of your features.

4. A function split_data: # this function randomly splits your data into 75% and 25% for training and testing sets, respectively.

5. A function model: # This function will build the classifier and report accuracy.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import nltk
from nltk.corpus import movie_reviews
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
import string

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score'movie_reviews')
stop_words = set(stopwords.words('english'))

def build_r...
$75.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats