forked from Aayusi/SihSrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredictor.py
38 lines (26 loc) · 1.05 KB
/
predictor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pickle
import re
import time
import warnings
warnings.filterwarnings('ignore')
text = input("Enter your review: ")
start = time.perf_counter()
loaded_model = pickle.load(open("model.sav", 'rb'))
def cleanText(raw_text, remove_stopwords=False, stemming=False, split_text=False):
letters_only = re.sub("[^a-zA-Z]", " ", raw_text) # remove non-character
words = letters_only.lower().split() # convert to lower case
if remove_stopwords: # remove stopword
stops = set(stopwords.words("english"))
words = [w for w in words if not w in stops]
if stemming==True: # stemming
#stemmer = PorterStemmer()
stemmer = SnowballStemmer('english')
words = [stemmer.stem(w) for w in words]
if split_text==True: # split text
return (words)
return( " ".join(words))
fin = cleanText(text)
result = loaded_model.predict([fin])
print({True: "Positive", False: "Negative"} [result[0]==1])
end = time.perf_counter()
print("Time elapsed during the calculation:", end - start)