<jupyter_start><jupyter_text>VISUALIZING THE DATA<jupyter_code>sns.countplot(depression_data['label'])
pip install nltk
import nltk
nltk.download('wordnet')
import re
from nltk.stem import PorterStemmer,WordNetLemmatizer
from nltk.corpus import stopwords
wo = WordNetLemmatizer()
corpus=[]
for i in range(0,len(depression_data)):
    message = re.sub('[^a-zA-Z]',' ',depression_data['message'][i])
    message = message.lower()
    message = message.split()
    message = [wo.lemmatize(word) for word in message ]
    message = ' '.join(message)
    corpus.append(message)
corpus[2]<jupyter_output><empty_output><jupyter_text>IMPORTING THE REQUIRED LIBRARIES FOR WORDS INITILIAZATION<jupyter_code>pip install wordcloud
from wordcloud import WordCloud
import matplotlib.pyplot as plt
depressed_words = ' '.join(list(depression_data[depression_data['label'] == 1]['message']))
depressed_wc = WordCloud(width = 512,height = 512, collocations=False, colormap="Blues").generate(depressed_words)
plt.figure(figsize = (10, 8), facecolor = 'k')
plt.imshow(depressed_wc)
plt.axis('off')
plt.tight_layout(pad = 0)
plt.show()
positive_words = ' '.join(list(depression_data[depression_data['label'] == 0]['message']))
positive_wc = WordCloud(width = 512,height = 512, collocations=False, colormap="Blues").generate(positive_words)
plt.figure(figsize = (10, 8), facecolor = 'k')
plt.imshow(positive_wc)
plt.axis('off'), 
plt.tight_layout(pad = 0)
plt.show()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(corpus,depression_data['label'],test_size=0.25,random_state=42)
from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer( ngram_range=(1,3), stop_words='english',max_features=15000)
X_train_vect = vectorizer.fit_transform(X_train)
X_test_vect = vectorizer.transform(X_test)
X_train_vect.shape
pip install imblearn
from imblearn import under_sampling 
from imblearn import over_sampling
from imblearn.over_sampling import SMOTE
x_resample, y_resample = SMOTE().fit_resample(X_train_vect, y_train)
x_test_resample, y_test_resample = SMOTE().fit_resample(X_test_vect, y_test)
# lets print the shape of x and y after resampling it
print(x_resample.shape)
print(y_resample.shape)<jupyter_output>(11978, 15000)
(11978,)<jupyter_text>APPLYING LOGISTIC REGRESSION MODEL<jupyter_code>from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(solver='lbfgs')
clf.fit(x_resample,y_resample)<jupyter_output><empty_output><jupyter_text>CLASSIFICATION REPORT FOR CHECKING THE ACCURACY<jupyter_code>from sklearn.metrics import accuracy_score, classification_report
y_pred = clf.predict(x_test_resample)
accuracy_score(y_test_resample,y_pred)
print(classification_report(y_test_resample,y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.96      0.99      0.98      2011
           1       0.99      0.96      0.97      2011

    accuracy                           0.98      4022
   macro avg       0.98      0.98      0.98      4022
weighted avg       0.98      0.98      0.98      4022<jupyter_text>APPLYING NAIVE BAYES MULTINOMIALNB MODEL<jupyter_code>from sklearn.naive_bayes import MultinomialNB
mnb = MultinomialNB()
mnb.fit(x_resample,y_resample)<jupyter_output><empty_output><jupyter_text>CLASSIFICATION REPORT FOR CHECKING THE ACCURACY OF NAIVE BAYES MODEL<jupyter_code>from sklearn.metrics import accuracy_score, classification_report
y_pred = mnb.predict(x_test_resample)
accuracy_score(y_test_resample,y_pred)
print(classification_report(y_test_resample,y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.95      0.96      0.95      2011
           1       0.96      0.95      0.95      2011

    accuracy                           0.95      4022
   macro avg       0.95      0.95      0.95      4022
weighted avg       0.95      0.95      0.95      4022<jupyter_text>FOR TAKING USER INPUT AND PREDICTION<jupyter_code>def preprocess(data):
    #preprocess
    a = re.sub('[^a-zA-Z]',' ',data)
    a = a.lower()
    a = a.split()
    a = [wo.lemmatize(word) for word in a ]
    a = ' '.join(a)  
    return a
import re
strr = input('Enter Your Message: ')
print("-------------------------------")
examples = strr

a = preprocess(examples)

example_counts = vectorizer.transform([a])
prediction =mnb.predict(example_counts)
prediction[0]

if prediction[0]==0:
    print('Positive')
elif prediction[0]==1:
    print('Depressive')
import pickle
filename = 'vectorizer.pkl'
pickle.dump(vectorizer, open(filename, 'wb'))
filename = 'prediction.pkl'
pickle.dump(mnb, open(filename, 'wb'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11436511329628046, 'fraction_numerical': 0.03847798204360838, 'mean_word_length': 4.434378629500581, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '604503', 'license': 'MIT', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1664, 'n_words': 320, 'path': 'Depression Detection.ipynb', 'repo_name': 'kishlayaug15/winter-of-contributing', 'size': '4678'}