<jupyter_start><jupyter_text>importing Libraries<jupyter_code>import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix,accuracy_score
from sklearn.ensemble import RandomForestClassifier
import nltk
from nltk.corpus import stopwords
import re
from nltk import WordNetLemmatizer
nltk.download('stopwords')
nltk.download('wordnet')<jupyter_output>[nltk_data] Downloading package stopwords to
[nltk_data]     C:\Users\nikhi\AppData\Roaming\nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
[nltk_data] Downloading package wordnet to
[nltk_data]     C:\Users\nikhi\AppData\Roaming\nltk_data...
[nltk_data]   Package wordnet is already up-to-date!<jupyter_text>importing Dataset<jupyter_code>df = pd.read_csv('Customer_review.tsv',delimiter='\t',quoting=3)
print(df)<jupyter_output>Review  Liked
0                             Wow... Loved this place.      1
1                                   Crust is not good.      0
2            Not tasty and the texture was just nasty.      0
3    Stopped by during the late May bank holiday of...      1
4    The selection on the menu was great and so wer...      1
..                                                 ...    ...
995  I think food should have flavor and texture an...      0
996                           Appetite instantly gone.      0
997  Overall I was not impressed and would not go b...      0
998  The whole experience was underwhelming, and I ...      0
999  Then, as if I hadn't wasted enough of my life ...      0

[1000 rows x 2 columns]<jupyter_text>Data Preprocessing<jupyter_code>lemm = WordNetLemmatizer()
corpus = []
for i in range(0,1000):
    review = df.iloc[i,0]
    review = re.sub('[^a-zA-z]',' ',review)
    review = review.lower()
    review = review.split()
    all_stopwords = stopwords.words('english')
    all_stopwords.remove('not')
    review = [lemm.lemmatize(word) for word in review if not word in all_stopwords]
    review = ' '.join(review)
    corpus.append(review)
vector = TfidfVectorizer(max_features=1700)
x = vector.fit_transform(corpus).toarray()
y = df.iloc[:,-1].values
len(x[0])
x_tr,x_te,y_tr,y_te=train_test_split(x,y,test_size=0.02,random_state=0)<jupyter_output><empty_output><jupyter_text>RandomForestClassifier<jupyter_code>classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 7)
classifier.fit(x_tr,y_tr)
y_pred = classifier.predict(x_te)
print(confusion_matrix(y_te,y_pred))
acc=accuracy_score(y_te,y_pred)
print(acc)<jupyter_output>[[12  0]
 [ 1  7]]
0.95<jupyter_text>Testing the Model<jupyter_code>test = ['the food was pretty good, i liked it']
tet = vector.transform(test)
print(tet)
test_pred = classifier.predict(tet)[0]
print(test_pred)
import pickle
filename = 'Customer_rev.sav'
pickle.dump(classifier, open(filename, 'wb'))
with open('corpus.data', 'wb') as filehandle:        
    pickle.dump(corpus, filehandle)          # store the data as binary data stream<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10480490164463076, 'fraction_numerical': 0.020638503708481134, 'mean_word_length': 3.6576576576576576, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '138745', 'license': 'MIT', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1047, 'n_words': 261, 'path': 'Review.ipynb', 'repo_name': 'NiKHiLkr23/Restaurant_Review', 'size': '3101'}