Spaces:
Sleeping
Sleeping
File size: 1,082 Bytes
ff871f8 |
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 39 40 41 |
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
|