Sentiment Analysis of Reviews
Budget: $10 – $30 USD
You are provided with a large dataset of reviews for vehicles (car_reviews.csv). Each review is
labelled with either ‘Pos’ or ‘Neg’ to indicate whether the review has been assessed as positive or negative in the sentiment it expresses. You should treat these labels as a reliable indicator of sentiment. You can assume that there are no neutral reviews. There are 1,382 reviews in the CSV file in total, 691 of which are positive and 691 of which are negative.
implement a Naïve Bayes classifier using 80% (1106) of the reviews as training data. The training data should be selected at random from the full dataset. Test your classifier using the remaining 20% (276) of the reviews and report the classifier’s performance using a confusion matrix.
It is important that you avoid issues of data leakage1 , meaning that your classifier should only be trained using data that it has access to from within the training data set. If there are words that only appear in the test data they should not be part of the classifier. You will need to make sure that your code is able to deal with encountering words in the test data that the classifier has not seen in the training data. It is up to you to decide how you will handle this.
Your code will need to read the review data CSV file provided.
You will need to perform some clean up of the data before using it in your classifier. This should include:
• Identifying and excluding all punctuation and words that are not likely to affect sentiment (e.g. stopwords2).
As an example, Natural Language Toolkit (NLTK) in Python has lists of common stopwords that you may wish
to use, but you are also free to find and use other libraries or tools for this.
• ensuring that remaining words are not case sensitive (i.e. the classifier should not distinguish upper/lower
case characters).
Your sentiment classifier should use a bag of words technique3, in which you build a vocabulary of individual words that appear in the dataset once it has been cleaned up.
You should attempt to treat minor variations of a word (e.g. ‘fault’, ‘faults’ and ‘faulty’) as instances of the same word (e.g. ‘fault’) when you are using them in your classifier. You should investigate and implement stemming as a way of doing this.
For each review you should create a vector as input for your classifier, containing EITHER binary values indicating whether a word/stem occurs in the review OR a numerical count of the number of times each word/stem appears.
As described above, vectors that are used to train the classifier should only include words that appear in the training data (and not words that only exist within the test data).
Note: You do not need to code everything required from scratch. you are encouraged to make use of existing libraries for all parts of the tasks. For example, you may find the MultinomialNB classifier in scikit.learn and natural language processing tools such as NLTK and spaCy useful for this task. It is also important to note that there is no single correct answer in terms of the output and performance of your
classifier. This will depend on the choices you make about how you deal with the data at each stage of the process – i will not be looking for a specific level of performance, rather that you have taken appropriate steps
and implemented them correct
contact me if you are certain you can do it and i will provide further information
labelled with either ‘Pos’ or ‘Neg’ to indicate whether the review has been assessed as positive or negative in the sentiment it expresses. You should treat these labels as a reliable indicator of sentiment. You can assume that there are no neutral reviews. There are 1,382 reviews in the CSV file in total, 691 of which are positive and 691 of which are negative.
implement a Naïve Bayes classifier using 80% (1106) of the reviews as training data. The training data should be selected at random from the full dataset. Test your classifier using the remaining 20% (276) of the reviews and report the classifier’s performance using a confusion matrix.
It is important that you avoid issues of data leakage1 , meaning that your classifier should only be trained using data that it has access to from within the training data set. If there are words that only appear in the test data they should not be part of the classifier. You will need to make sure that your code is able to deal with encountering words in the test data that the classifier has not seen in the training data. It is up to you to decide how you will handle this.
Your code will need to read the review data CSV file provided.
You will need to perform some clean up of the data before using it in your classifier. This should include:
• Identifying and excluding all punctuation and words that are not likely to affect sentiment (e.g. stopwords2).
As an example, Natural Language Toolkit (NLTK) in Python has lists of common stopwords that you may wish
to use, but you are also free to find and use other libraries or tools for this.
• ensuring that remaining words are not case sensitive (i.e. the classifier should not distinguish upper/lower
case characters).
Your sentiment classifier should use a bag of words technique3, in which you build a vocabulary of individual words that appear in the dataset once it has been cleaned up.
You should attempt to treat minor variations of a word (e.g. ‘fault’, ‘faults’ and ‘faulty’) as instances of the same word (e.g. ‘fault’) when you are using them in your classifier. You should investigate and implement stemming as a way of doing this.
For each review you should create a vector as input for your classifier, containing EITHER binary values indicating whether a word/stem occurs in the review OR a numerical count of the number of times each word/stem appears.
As described above, vectors that are used to train the classifier should only include words that appear in the training data (and not words that only exist within the test data).
Note: You do not need to code everything required from scratch. you are encouraged to make use of existing libraries for all parts of the tasks. For example, you may find the MultinomialNB classifier in scikit.learn and natural language processing tools such as NLTK and spaCy useful for this task. It is also important to note that there is no single correct answer in terms of the output and performance of your
classifier. This will depend on the choices you make about how you deal with the data at each stage of the process – i will not be looking for a specific level of performance, rather that you have taken appropriate steps
and implemented them correct
contact me if you are certain you can do it and i will provide further information