text_plain_output_1.png
from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.metrics import accuracy_score, precision_recall_fscore_support

from sklearn.naive_bayes import MultinomialNB

from sklearn.pipeline import Pipeline

def calculate_results(y_true, y_pred):
    model_accuracy = accuracy_score(y_true, y_pred) * 100
    model_precision, model_recall, model_f1, _ = precision_recall_fscore_support(y_true, y_pred, average='weighted')
    model_results = {'accuracy': model_accuracy, 'precision': model_precision, 'recall': model_recall, 'f1': model_f1}
    return model_results

model_1 = Pipeline([('tfidf', TfidfVectorizer()), ('clf', MultinomialNB())])
model_1.fit(train_sentences, train_label)

model_1_score = model_1.score(test_sentences, test_label)
model_1_score

model_1_preds = model_1.predict(test_sentences)
model_1_preds

model_1_results = calculate_results(y_true=test_label, y_pred=model_1_preds)
model_1_results