Last active
August 2, 2020 14:20
-
-
Save kipronokoech/9e44d02ad8ef85b6fbd71dc215bf9277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Import necessary packages | |
import numpy as np | |
import random | |
import matplotlib.pyplot as plt | |
from sklearn.model_selection import train_test_split | |
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer | |
from sklearn.metrics import f1_score #f1 score to use it as and evaluation metric | |
import ast #to convert string into dictionary | |
from IPython.display import clear_output | |
from sklearn import svm #support vector machine classifier | |
from sklearn.metrics import confusion_matrix | |
from sklearn.linear_model import LogisticRegression #import logistic regression | |
from sklearn.tree import DecisionTreeClassifier #import Decision tree | |
from sklearn.naive_bayes import GaussianNB | |
from sklearn.ensemble import RandomForestClassifier | |
import pandas as pd | |
import seaborn as sb | |
# A class to categorize a review as positive, negative or neutral | |
class Review: | |
def __init__(self, text, score): | |
self.text = text | |
self.score = score | |
self.sentiment = self.get_sentiment() | |
def get_sentiment(self): | |
if self.score <= 2: | |
return "NEGATIVE" | |
elif self.score == 3: | |
return "NEUTRAL" | |
else: #Score of 4 or 5 | |
return "POSITIVE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment