UEH_SentimentAnalysis / functions.py
perman2011's picture
Update functions.py
4e23176
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
def sentiment_analysis_LR(input):
# Assuming you have a Logistic Regression model and TfidfVectorizer in the pipeline
input = preprocess_text(input)
vectorizer = model_LR.named_steps['tfidfvectorizer']
lr_classifier = model_LR.named_steps['logisticregression']
# Transform the user input using the TF-IDF vectorizer
user_input_tfidf = vectorizer.transform([input])
# Make predictions
user_pred = lr_classifier.predict(user_input_tfidf)
# Display the prediction
if user_pred[0] == 0:
return 0
else:
return 1
def sentiment_analysis_NB(input):
input = preprocess_text(input)
vectorizer = model_NB.named_steps['tfidf']
nb_classifier = model_NB.named_steps['nb']
# Transform the user input using the TF-IDF vectorizer
user_input_tfidf = vectorizer.transform([input])
# Make predictions
user_pred = nb_classifier.predict(user_input_tfidf)
# Display the prediction
if user_pred[0] == 0:
return 0
else:
return 1