Skip to content

Instantly share code, notes, and snippets.

@kipronokoech
Last active August 2, 2020 14:20
Show Gist options
  • Save kipronokoech/9e44d02ad8ef85b6fbd71dc215bf9277 to your computer and use it in GitHub Desktop.
Save kipronokoech/9e44d02ad8ef85b6fbd71dc215bf9277 to your computer and use it in GitHub Desktop.
#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