<jupyter_start><jupyter_text>Business Problem<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
data = pd.read_csv("Restaurant_Reviews.tsv", sep = '\t', quoting = 3)
data.head()
data.tail()
data['Liked'].value_counts()
# balanced dataset<jupyter_output><empty_output><jupyter_text>Cleaning Text Data<jupyter_code>import nltk
import re
nltk.download('stopwords')
from nltk.corpus import stopwords
data['Review'][0]
review = re.sub('[^a-zA-Z]', ' ', data['Review'][0])
review
review = review.lower()
review
# everything become lowercase
review = review.split()
review
preview = []
for word in review:
  if word not in stopwords.words('english'):
    preview.append(word)
preview
review = [word for word in review if word not in stopwords.words('english')]
review
from nltk.stem.porter import PorterStemmer
ps = PorterStemmer()
review = [ps.stem(word) for word in review]
review
review = " ".join(review)
print(review)
corpus = []
ps = PorterStemmer()

for i in range(len(data)):
  review = re.sub('[^a-zA-Z]', ' ', data['Review'][i])
  review = review.lower()
  review = review.split()
  review = [ps.stem(word) for word in review if word not in stopwords.words('english')]
  review = " ".join(review)

  corpus.append(review)
print(corpus)<jupyter_output>['wow love place', 'crust good', 'tasti textur nasti', 'stop late may bank holiday rick steve recommend love', 'select menu great price', 'get angri want damn pho', 'honeslti tast fresh', 'potato like rubber could tell made ahead time kept warmer', 'fri great', 'great touch', 'servic prompt', 'would go back', 'cashier care ever say still end wayyy overpr', 'tri cape cod ravoli chicken cranberri mmmm', 'disgust pretti sure human hair', 'shock sign indic cash', 'highli recommend', 'waitress littl slow servic', 'place worth time let alon vega', 'like', 'burritto blah', 'food amaz', 'servic also cute', 'could care less interior beauti', 'perform', 'right red velvet cake ohhh stuff good', 'never brought salad ask', 'hole wall great mexican street taco friendli staff', 'took hour get food tabl restaur food luke warm sever run around like total overwhelm', 'worst salmon sashimi', 'also combo like burger fri beer decent deal', 'like final blow', 'found place accid could happier', 'seem like go[...]<jupyter_text>Bag of word model<jupyter_code>from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(max_features = 1500)
x = cv.fit_transform(corpus).toarray()
x.shape
y = data.iloc[:, 1].values
y.shape
y[:10]<jupyter_output><empty_output><jupyter_text>Apply Naive Bayes Algorithm<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(x,y, test_size = .2, random_state = 123)
X_train.shape, X_test.shape
y_train.shape, y_test.shape
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import accuracy_score
accuracy_score(y_test, y_pred)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12140052356020943, 'fraction_numerical': 0.004581151832460733, 'mean_word_length': 6.109302325581395, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '646959', 'license': 'MIT', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1003, 'n_words': 322, 'path': 'Projects/2 Restaurant Review (good-bad)/restaurant_reviews_with_NLTK.ipynb', 'repo_name': 'ogulcanertunc/NLP-Projects', 'size': '3056'}