<jupyter_start><jupyter_text>Preprocessing<jupyter_code># from google.colab import drive
# drive.mount('/content/drive')
# cd drive/MyDrive/NLP_Project
# !pip install pandas matplotlib tqdm seaborn sklearn numpy graphviz
import pandas as pd
import matplotlib.pyplot as plt
from tqdm import tqdm
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import GridSearchCV
import numpy as np
import warnings
warnings.filterwarnings('always') 
from sklearn.metrics import classification_report
from sklearn.metrics import accuracy_score
import pickle as pk
trainData = np.load('../../../dataFinal/npy_files/fin_noWE_t2_train.npy')
trainLabels = open('../../../dataFinal/finalTrainLabels.labels', 'r').readlines()
testData = np.load('../../../dataFinal/npy_files/fin_noWE_t2_test.npy')
testLabels = open('../../../dataFinal/finalTestLabels.labels', 'r').readlines()
validationData = np.load('../../../dataFinal/npy_files/fin_noWE_t2_trial.npy')
validationLabels = open('../../../dataFinal/finalDevLabels.labels', 'r').readlines()
for i in tqdm(range(len(trainLabels))):
    trainLabels[i] = int(trainLabels[i])
for i in tqdm(range(len(testLabels))):
    testLabels[i] = int(testLabels[i])
for i in tqdm(range(len(validationLabels))):
    validationLabels[i] = int(validationLabels[i])
trainLabels = np.array(trainLabels)
testLabels = np.array(testLabels)
validationLabels = np.array(validationLabels)
trainLabels = trainLabels.reshape((-1, ))
testLabels = testLabels.reshape((-1, ))
validationLabels = validationLabels.reshape((-1, ))
X_train, X_test, y_train, y_test, X_val, y_val = trainData, testData, trainLabels, testLabels, validationData, validationLabels<jupyter_output><empty_output><jupyter_text>Estimators  Range 1<jupyter_code># accuracy = []
# predVal = []
itr= [150, 250, 350, 450]
for i in tqdm(range(len(itr))):
    clf = AdaBoostClassifier(algorithm="SAMME.R",n_estimators=itr[i], random_state=0)
    clf.fit(trainData, trainLabels)

    y_pred = clf.predict(testData)
    y_true = testLabels
    print("Test Data:")
    print("Classification report for case: ",itr[i])
    print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
    print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
    y_pred = clf.predict(trainData)
    y_true = trainLabels
    print("Train Data:")
    print("Classification report for case: ",itr[i])
    print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
    print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
    y_pred = clf.predict(validationData)
    y_true = validationLabels
    print("Validation Data:")
    print("Classification report for case: ",itr[i])
    print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
    print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
    #predVal.append(itr[i])


# plt.plot(predVal, accuracy)
# plt.xlabel('Num estimators')
# plt.ylabel('Accuracy')
# plt.title('Accuracy vs Num estimators')
# plt.show()<jupyter_output>0%|          | 0/4 [00:00<?, ?it/s]<jupyter_text>Range 2<jupyter_code># ada_accuracy = []
# ada_predVal = []
# itr= [150, 175, 200, 225]
# for i in tqdm(range(len(itr))):
#     clf = AdaBoostClassifier(algorithm="SAMME.R",n_estimators=itr[i], random_state=0)
#     clf.fit(trainData, trainLabels)
#     y_pred = clf.predict(testData)
#     y_true = testLabels
#     print("Test Data:")
#     print("Classification report for case: ",itr[i])
#     print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
#     print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
#     y_pred = clf.predict(trainData)
#     y_true = trainLabels
#     print("Train Data:")
#     print("Classification report for case: ",itr[i])
#     print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
#     print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
#     y_pred = clf.predict(validationData)
#     y_true = validationLabels
#     print("Validation Data:")
#     print("Classification report for case: ",itr[i])
#     print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
#     print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
#     # ada_accuracy.append(round(accuracy_score(y_pred = y_pred, y_true = testLabels) * 100,2))
#     # ada_predVal.append(itr[i])


# # plt.plot(ada_predVal, ada_accuracy)
# # plt.xlabel('Num estimators')
# # plt.ylabel('ada_Accuracy')
# # plt.title('ada_Accuracy vs Num estimators')
# # plt.show()<jupyter_output><empty_output><jupyter_text>Algrithm  "SAMME"<jupyter_code>clf = AdaBoostClassifier(algorithm="SAMME", n_estimators=200, random_state=0)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
y_true = testLabels
print("Test Data:")
accuracy = round(accuracy_score(y_pred = y_pred, y_true = y_true) * 100,2)
print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
y_pred = clf.predict(X_train)
y_true = trainLabels
print("Train Data:")
print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
y_pred = clf.predict(X_val)
y_true = validationLabels
print("Validation Data:")
print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))<jupyter_output>Test Data:
Accuracy % :  22.8
              precision    recall  f1-score   support

           1       0.00      0.00      0.00      2022
           2       0.00      0.00      0.00      1955
           3       0.00      0.00      0.00      1099
           4       1.00      0.00      0.00      1246
           5       0.00      0.00      0.00       786
           6       0.00      0.00      0.00       809
           7       0.00      0.00      0.00       928
           8       0.00      0.00      0.00       669
           9       0.00      0.00      0.00       569
          10       0.00      0.00      0.00       595
          11       1.00      0.00      0.01       696
          12       0.00      0.00      0.00       546
          13       0.00      0.00      0.00       492
          14       0.00      0.00      0.00       536
          15       0.00      0.00      0.00       498
          16       0.00      0.00      0.00       492
          17       0.67      0.52      0.59       5[...]<jupyter_text>"SAMME.R" Better<jupyter_code>X_train, X_test, y_train, y_test = trainData, testData, trainLabels, testLabels
clf = AdaBoostClassifier(algorithm="SAMME.R",n_estimators=200, random_state=0)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
y_true = testLabels
print("Test Data:")
accuracy = round(accuracy_score(y_pred = y_pred, y_true = y_true) * 100,2)
print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
y_pred = clf.predict(X_train)
y_true = trainLabels
print("Train Data:")
print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
y_pred = clf.predict(X_val)
y_true = validationLabels
print("Validation Data:")
print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))<jupyter_output>Test Data:
Accuracy % :  27.28
              precision    recall  f1-score   support

           1       0.22      0.01      0.02      2022
           2       0.35      0.15      0.21      1955
           3       0.40      0.01      0.02      1099
           4       0.50      0.22      0.31      1246
           5       0.11      0.00      0.00       786
           6       0.43      0.06      0.10       809
           7       0.36      0.09      0.14       928
           8       0.33      0.04      0.07       669
           9       0.27      0.03      0.05       569
          10       0.07      0.01      0.01       595
          11       0.53      0.32      0.40       696
          12       0.34      0.31      0.33       546
          13       0.34      0.02      0.04       492
          14       0.00      0.00      0.00       536
          15       0.22      0.04      0.06       498
          16       0.21      0.02      0.03       492
          17       0.61      0.63      0.62       [...]<jupyter_text>AdaBoost Final Results algorithm="SAMME.R",n_estimators=200 Accuracy:  27.24<jupyter_code># clf = AdaBoostClassifier(algorithm="SAMME.R",n_estimators=200, random_state=0)
# clf.fit(trainData, trainLabels)
# y_pred = clf.predict(X_test)
# y_true = testLabels
# print("Test Data:")
# accuracy = round(accuracy_score(y_pred = y_pred, y_true = y_true) * 100,2)
# print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
# print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
# y_pred = clf.predict(X_train)
# y_true = trainLabels
# print("Train Data:")
# print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
# print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
# y_pred = clf.predict(X_val)
# y_true = validationLabels
# print("Validation Data:")
# print("Accuracy % : ",round(accuracy_score(y_pred = y_pred, y_true=y_true) * 100,2))
# print(classification_report(y_true,y_pred,labels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
filename = 'finalModel_AB_NoWE'
pk.dump(clf,open(filename,'wb'))<jupyter_output>/var/folders/gj/mzxgltyj3wb83jl14fkhz8_w0000gn/T/ipykernel_37424/3440957383.py:2: ResourceWarning: unclosed file <_io.BufferedWriter name='finalModel_AB_NoWE'>
  pk.dump(clf,open(filename,'wb'))
ResourceWarning: Enable tracemalloc to get the object allocation traceback
{'fraction_non_alphanumeric': 0.14604369377639068, 'fraction_numerical': 0.0979438222874977, 'mean_word_length': 2.9332129963898916, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 79, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '55345', 'license': 'CC0-1.0', 'n_tokens_mistral': 4906, 'n_tokens_neox': 4132, 'n_words': 938, 'path': 'src/finalModels/AdaBoost/Adaboost_NoWE_3500.ipynb', 'repo_name': 'AbrolKaran/Making-Emojis-More-Predictable', 'size': '10894'}