# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## MultinomialNB Model

# +
import pickle
import numpy as np
from scipy.sparse import csr_matrix

# Open cv and classifier
with open('./cv_test.pkl', 'rb') as cv_file:
        cv = pickle.load(cv_file)

with open('./naive_bayes_classifier_test.pkl', 'rb') as model_file:
        model = pickle.load(model_file)

# +
# Some test data (0 = Content; 1 = Tech)
# text = "Dear One, Can you explain this activity to me? Thank you!" # Content
text = "Dear One, My computer froze and i lost an attempt? Thank you!" # Tech

# clean the text
import re
import nltk    
# nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer

body_wash = re.sub('[^a-zA-Z]', ' ', text)
body_wash = body_wash.lower()
body_wash = body_wash.split()
ps = PorterStemmer()
body_wash = [ps.stem(word) for word in body_wash if not word in set(stopwords.words('english'))]
body_wash = [' '.join(body_wash)]

prepared_text = cv.transform(body_wash)
# print(body_wash)
# print(prepared_text)
# print(type(prepared_text))

print('0 = Content; 1 = Tech ', model.predict(prepared_text))

StarcoderdataJupyterScriptsDedupFiltered