<jupyter_start><jupyter_text>MALIGNANT COMMENTS CLASSIFIER<jupyter_code>#import libraries
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
#load datasets
train=pd.read_csv("train.csv")
test=pd.read_csv("test.csv")
train
test
print('Train_data:',train.shape)
print('Test_data:',test.shape)
train.columns
test.columns
train.isnull().sum()
test.isnull().sum()<jupyter_output><empty_output><jupyter_text>Visualizations Count plot:<jupyter_code>col=['malignant','highly_malignant','rude','threat','abuse','loathe']

for i in col:
    print(i)
    print("\n")
    print(train[i].value_counts())
    sns.countplot(train[i])
    plt.show()<jupyter_output>malignant


0    144277
1     15294
Name: malignant, dtype: int64<jupyter_text>From the above observation we can see that, 15294 comments are malignant and 144277 comments are not malignant.1595 comments are highly_malignant and 157976 comments are not highly_malignant.8449 comments are rude and 151122 are not rude.478 comments are threat and 159093 comments are not threat.7877 comments are abuse and 151694 comments are not abuse.1405 comments are loathe and 158166 comments are not loathe.  Correlation:<jupyter_code>train.corr()<jupyter_output><empty_output><jupyter_text>correlation using heatmap:<jupyter_code>plt.figure(figsize=(15,7))
sns.heatmap(train.corr(),annot=True,linewidth=0.5,linecolor="black",fmt='.2f')<jupyter_output><empty_output><jupyter_text>Describing dataset:<jupyter_code>train.describe()<jupyter_output><empty_output><jupyter_text>Describe of dataset using heatmap:<jupyter_code>plt.figure(figsize=(15,12))
sns.heatmap(round(train.describe()[1:].transpose(),2),linewidth=2,annot=True,fmt="f")
plt.xticks(fontsize=18)
plt.yticks(fontsize=12)
plt.title("Variable Summary")
plt.show()<jupyter_output><empty_output><jupyter_text>From the above plotting, we can determine mean, standard deviation, minimum and maximum value of each column of the dataset.159571 rows8 columnsmalignant:    mean=0.095844    std=0.294379    max_value=1.000000    min_value=0.000000    highly_malignant:    mean=0.009996    std=0.099477    max_value=1.000000    min_value=0.000000    rude:    mean=0.052948    std=0.223931    max_value=1.000000    min_value=0.000000    threat:    mean=0.002996    std=0.054650    max_value=1.000000    min_value=0.000000    abuse:    mean=0.049364    std=0.216627    max_value=1.000000    min_value=0.000000    loathe:    mean=0.008805    std=0.093420    max_value=1.000000    min_value=0.000000<jupyter_code>print(train.info())
print("\n")
print(test.info())<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 159571 entries, 0 to 159570
Data columns (total 8 columns):
 #   Column            Non-Null Count   Dtype 
---  ------            --------------   ----- 
 0   id                159571 non-null  object
 1   comment_text      159571 non-null  object
 2   malignant         159571 non-null  int64 
 3   highly_malignant  159571 non-null  int64 
 4   rude              159571 non-null  int64 
 5   threat            159571 non-null  int64 
 6   abuse             159571 non-null  int64 
 7   loathe            159571 non-null  int64 
dtypes: int64(6), object(2)
memory usage: 9.7+ MB
None


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 153164 entries, 0 to 153163
Data columns (total 2 columns):
 #   Column        Non-Null Count   Dtype 
---  ------        --------------   ----- 
 0   id            153164 non-null  object
 1   comment_text  153164 non-null  object
dtypes: object(2)
memory usage: 2.3+ MB
None<jupyter_text>Skewness:<jupyter_code>train.skew()<jupyter_output><empty_output><jupyter_text>All the columns of the dataset has skewness.  Normal Distribution Curve:<jupyter_code>sns.distplot(train['malignant'])<jupyter_output><empty_output><jupyter_text>The data of the column is not normalized. The building blocks is out of the normalized curve.<jupyter_code>sns.distplot(train['highly_malignant'])<jupyter_output><empty_output><jupyter_text>The data of the column is not normalized. The building blocks is out of the normalized curve.<jupyter_code>sns.distplot(train['rude'])<jupyter_output><empty_output><jupyter_text>The data of the column is not normalized. The building blocks is out of the normalized curve.<jupyter_code>sns.distplot(train['threat'])<jupyter_output><empty_output><jupyter_text>The data of the column is not normalized. The building blocks is out of the normalized curve.<jupyter_code>sns.distplot(train['abuse'])<jupyter_output><empty_output><jupyter_text>The data of the column is not normalized. The building blocks is out of the normalized curve.<jupyter_code>sns.distplot(train['loathe'])<jupyter_output><empty_output><jupyter_text>The data of the column is not normalized. The building blocks is out of the normalized curve.<jupyter_code>#importing necessary libraries

import nltk
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
import string
train['length']=train['comment_text'].str.len()
train
#convert all messages to lower case
train['comment_text'] = train['comment_text'].str.lower()

#Replace email address with 'email'
train['comment_text'] = train['comment_text'].str.replace(r'^.+@[^\.].*\.[a-z]{2,}$', 'emailaddress')

#Replace URLs with 'webaddress'
train['comment_text'] = train['comment_text'].str.replace(r'^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$', 'webaddress')

#Replace money sumbols with 'moneysymb'
train['comment_text'] = train['comment_text'].str.replace(r'£|\$', 'dollars')

#Replace 10 digit phone numbers with 'phonenumber'
train['comment_text'] = train['comment_text'].str.replace(r'\(?[\d]{3}\)?[\s-]?[\d]{3}[\s-]?[\d]{4}$', 'phonenumber')

#Replace numbers with 'num'
train['comment_text'] = train['comment_text'].str.replace(r'\d+(\.\d+)?', 'num')

train['comment_text'] = train['comment_text'].apply(lambda x: ''.join(term for term in x.split() if term not in string.punctuation))

stop_words = set(stopwords.words('english') + ['u','ur','4','2','im','dont','doin','ure'])
train['comment_text'] = train['comment_text'].apply(lambda x: ''.join(term for term in x.split() if term not in stop_words))

lem=WordNetLemmatizer()
train['comment_text'] = train['comment_text'].apply(lambda x: ''.join(lem.lemmatize(t) for t in x.split()))

train['clean_length']=train.comment_text.str.len()
train
#total length removal
print('Original Length: ', train.length.sum())
print('Clean Length: ', train.clean_length.sum())
#!pip install wordcloud
#offensive loud words
from wordcloud import WordCloud
hams = train['comment_text'][train['malignant']==1]
spam_cloud = WordCloud(width=600, height=400, background_color='white',max_words=50).generate(''.join(hams))
plt.figure(figsize=(10,8),facecolor='r')
plt.imshow(spam_cloud)
plt.axis('off')
plt.tight_layout(pad=0)
plt.show()
target_column=['malignant','highly_malignant','rude','threat','abuse','loathe']

target=train[target_column]

train['bad']=train[target_column].sum(axis=1)
print(train['bad'].value_counts())
train['bad']=train['bad']>0
train['bad']=train['bad'].astype(int)
print(train['bad'].value_counts())
sns.countplot(x='bad', data=train)
print(train['bad'].value_counts())
plt.show()
train.head()
#converting text into vectors using TF-IDF

from sklearn.feature_extraction.text import TfidfVectorizer
tfidf= TfidfVectorizer(max_features=10000, stop_words='english')
feature= tfidf.fit_transform(train['comment_text'])
print(train.shape)
print(test.shape)<jupyter_output>(159571, 11)
(153164, 2)<jupyter_text>Dividing Dataframe into feature and target<jupyter_code>x=feature
y=train['bad']
y.value_counts()
from imblearn.over_sampling import SMOTE
sm=SMOTE()
xtrain,ytrain=sm.fit_resample(x,y)
ytrain.value_counts()<jupyter_output><empty_output><jupyter_text>Model Building<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import accuracy_score,classification_report,confusion_matrix<jupyter_output><empty_output><jupyter_text>Logistic Regression:<jupyter_code>lg=LogisticRegression()

train_x,test_x,train_y,test_y=train_test_split(xtrain,ytrain,test_size=0.20,random_state=45)
lg.fit(train_x,train_y)
pred_train=lg.predict(train_x)
pred_test=lg.predict(test_x)

print("Training Accuracy:",accuracy_score(train_y,pred_train)*100)
print("Testing Accuracy:",accuracy_score(test_y,pred_test)*100)<jupyter_output>Training Accuracy: 75.04632596913928
Testing Accuracy: 74.33858281448926<jupyter_text>Cross Validation for logistic regression:<jupyter_code>from sklearn.model_selection import cross_val_score

lg.fit(train_x,train_y)
lg.score(train_x,train_y)
pred_lg = lg.predict(test_x)

lss = accuracy_score(test_y,pred_lg)
for j in range(2,10):
    lsscore = cross_val_score(lg,xtrain,ytrain,cv=j)
    ls_cv = lsscore.mean() 
    print("At cv:-",j)
    print("Cross validation score is:-",ls_cv*100 )
    print("Accuracy score is :-",lss*100)
    print("\n")
print("At cv:",9)
print("Cross validation score is:",74.33099030511153)
print("Accuracy score is :",74.33858281448926)<jupyter_output>At cv: 9
Cross validation score is: 74.33099030511153
Accuracy score is : 74.33858281448926<jupyter_text>AUC-ROC Curve:<jupyter_code>from sklearn.metrics import roc_curve,auc
fpr,tpr,thresholds=roc_curve(pred_lg,test_y)
roc_auc=auc(fpr,tpr)
plt.figure()
plt.plot(fpr,tpr,color='darkorange',lw=10,label='ROC Curve(area=%0.2f)'%roc_auc)
plt.plot([0,1],[0,1],color='navy',lw=10,linestyle='--')
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('LOGISTIC REGRESSION')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output><jupyter_text>Approaching more classifiers:<jupyter_code>from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier<jupyter_output><empty_output><jupyter_text>1.Decision Tree Classifier:<jupyter_code>parameters = {'criterion':['gini', 'entropy'],'splitter':['best','random']}
dtc = DecisionTreeClassifier()
clf = GridSearchCV(dtc,parameters)
clf.fit(train_x,train_y)

print(clf.best_params_)
dtc = DecisionTreeClassifier(criterion='gini', splitter='best')
dtc.fit(train_x,train_y)
dtc.score(train_x,train_y)
pred_dtc = dtc.predict(test_x)

print("Accuracy Score:",accuracy_score(test_y,pred_dtc)*100)
print("Classification report:",classification_report(test_y,pred_dtc)*100)
print("Confusion Matrix:",confusion_matrix(test_y,pred_dtc)*100)

dtc_score = cross_val_score(dtc,xtrain,ytrain,cv=9)
dtc_cc = dtc_score.mean() 
print('Cross Val Score:',dtc_cc*100)<jupyter_output>Accuracy Score: 77.23538952545388
Classification report:               precision    recall  f1-score   support

           0       0.91      0.61      0.73     28576
           1       0.71      0.94      0.81     28763

    accuracy                           0.77     57339
   macro avg       0.81      0.77      0.77     57339
weighted avg       0.81      0.77      0.77     57339
              precision    recall  f1-score   support

           0       0.91      0.61      0.73     28576
           1       0.71      0.94      0.81     28763

    accuracy                           0.77     57339
   macro avg       0.81      0.77      0.77     57339
weighted avg       0.81      0.77      0.77     57339
              precision    recall  f1-score   support

           0       0.91      0.61      0.73     28576
           1       0.71      0.94      0.81     28763

    accuracy                           0.77     57339
   macro avg       0.81      0.77      0.77     57339
weighted avg       [...]<jupyter_text>AUC-ROC Curve:<jupyter_code>from sklearn.metrics import roc_curve,auc
fpr,tpr,thresholds=roc_curve(pred_dtc,test_y)
roc_auc=auc(fpr,tpr)
plt.figure()
plt.plot(fpr,tpr,color='darkorange',lw=10,label='ROC Curve(area=%0.2f)'%roc_auc)
plt.plot([0,1],[0,1],color='navy',lw=10,linestyle='--')
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Decision Tree Classifier')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output><jupyter_text>2.KNeighbors Classifier:<jupyter_code>parameters = {'algorithm':['auto', 'ball_tree', 'kd_tree', 'brute']}
knc = KNeighborsClassifier()
clf = GridSearchCV(knc,parameters)
clf.fit(train_x,train_y)

print(clf.best_params_)
knc = KNeighborsClassifier(algorithm='auto', n_neighbors=5)
knc.fit(train_x,train_y)
knc.score(train_x,train_y)
pred_knc = knc.predict(test_x)

print("Accuracy Score:",accuracy_score(test_y,pred_knc)*100)
print("Classification report:",classification_report(test_y,pred_knc)*100)
print("Confusion Matrix:",confusion_matrix(test_y,pred_knc)*100)

knc_score = cross_val_score(knc,xtrain,ytrain,cv=9)
knc_cc = knc_score.mean() 
print('Cross Val Score:',knc_cc*100)<jupyter_output>Accuracy Score: 60.55389874256613
Classification report:               precision    recall  f1-score   support

           0       0.58      0.76      0.66     28576
           1       0.66      0.45      0.53     28763

    accuracy                           0.61     57339
   macro avg       0.62      0.61      0.60     57339
weighted avg       0.62      0.61      0.60     57339
              precision    recall  f1-score   support

           0       0.58      0.76      0.66     28576
           1       0.66      0.45      0.53     28763

    accuracy                           0.61     57339
   macro avg       0.62      0.61      0.60     57339
weighted avg       0.62      0.61      0.60     57339
              precision    recall  f1-score   support

           0       0.58      0.76      0.66     28576
           1       0.66      0.45      0.53     28763

    accuracy                           0.61     57339
   macro avg       0.62      0.61      0.60     57339
weighted avg       [...]<jupyter_text>AUC-ROC Curve:<jupyter_code>from sklearn.metrics import roc_curve,auc
fpr,tpr,thresholds=roc_curve(pred_knc,test_y)
roc_auc=auc(fpr,tpr)
plt.figure()
plt.plot(fpr,tpr,color='darkorange',lw=10,label='ROC Curve(area=%0.2f)'%roc_auc)
plt.plot([0,1],[0,1],color='navy',lw=10,linestyle='--')
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('KNeighbors Classifier')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output><jupyter_text>ENSEMBLE METHODS:<jupyter_code>from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import GradientBoostingClassifier<jupyter_output><empty_output><jupyter_text>1.Random Forest Classifier:<jupyter_code>parameters = {'criterion':['gini', 'entropy'],'n_estimators':[100]}
rfc = RandomForestClassifier()
clf = GridSearchCV(rfc,parameters)
clf.fit(train_x,train_y)

print(clf.best_params_)
rfc = RandomForestClassifier(criterion='entropy', n_estimators=100)
rfc.fit(train_x,train_y)
rfc.score(train_x,train_y)
pred_rfc = rfc.predict(test_x)

print("Accuracy Score:",accuracy_score(test_y,pred_rfc)*100)
print("Classification report:",classification_report(test_y,pred_rfc)*100)
print("Confusion Matrix:",confusion_matrix(test_y,pred_rfc)*100)

rfc_score = cross_val_score(rfc,xtrain,ytrain,cv=9)
rfc_cc = rfc_score.mean() 
print('Cross Val Score:',rfc_cc*100)<jupyter_output>Accuracy Score: 77.93822703569995
Classification report:               precision    recall  f1-score   support

           0       0.93      0.61      0.73     28576
           1       0.71      0.95      0.81     28763

    accuracy                           0.78     57339
   macro avg       0.82      0.78      0.77     57339
weighted avg       0.82      0.78      0.77     57339
              precision    recall  f1-score   support

           0       0.93      0.61      0.73     28576
           1       0.71      0.95      0.81     28763

    accuracy                           0.78     57339
   macro avg       0.82      0.78      0.77     57339
weighted avg       0.82      0.78      0.77     57339
              precision    recall  f1-score   support

           0       0.93      0.61      0.73     28576
           1       0.71      0.95      0.81     28763

    accuracy                           0.78     57339
   macro avg       0.82      0.78      0.77     57339
weighted avg       [...]<jupyter_text>AUC-ROC Curve<jupyter_code>from sklearn.metrics import roc_curve,auc
fpr,tpr,thresholds=roc_curve(pred_rfc,test_y)
roc_auc=auc(fpr,tpr)
plt.figure()
plt.plot(fpr,tpr,color='darkorange',lw=10,label='ROC Curve(area=%0.2f)'%roc_auc)
plt.plot([0,1],[0,1],color='navy',lw=10,linestyle='--')
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Random Forest Classifier')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output><jupyter_text>2.Ada Boost Classifier:<jupyter_code>abc = AdaBoostClassifier(n_estimators=50, learning_rate=1.0, algorithm='SAMME')
abc.fit(train_x,train_y)
abc.score(train_x,train_y)
pred_abc = abc.predict(test_x)

print("Accuracy Score:",accuracy_score(test_y,pred_abc)*100)
print("Classification report:",classification_report(test_y,pred_abc)*100)
print("Confusion Matrix:",confusion_matrix(test_y,pred_abc)*100)

abc_score = cross_val_score(abc,xtrain,ytrain,cv=9)
abc_cc = abc_score.mean() 
print('Cross Val Score:',abc_cc*100)<jupyter_output>Accuracy Score: 56.642076073876424
Classification report:               precision    recall  f1-score   support

           0       0.84      0.16      0.27     28576
           1       0.54      0.97      0.69     28763

    accuracy                           0.57     57339
   macro avg       0.69      0.57      0.48     57339
weighted avg       0.69      0.57      0.48     57339
              precision    recall  f1-score   support

           0       0.84      0.16      0.27     28576
           1       0.54      0.97      0.69     28763

    accuracy                           0.57     57339
   macro avg       0.69      0.57      0.48     57339
weighted avg       0.69      0.57      0.48     57339
              precision    recall  f1-score   support

           0       0.84      0.16      0.27     28576
           1       0.54      0.97      0.69     28763

    accuracy                           0.57     57339
   macro avg       0.69      0.57      0.48     57339
weighted avg      [...]<jupyter_text>AUC-ROC Curve<jupyter_code>from sklearn.metrics import roc_curve,auc
fpr,tpr,thresholds=roc_curve(pred_abc,test_y)
roc_auc=auc(fpr,tpr)
plt.figure()
plt.plot(fpr,tpr,color='darkorange',lw=10,label='ROC Curve(area=%0.2f)'%roc_auc)
plt.plot([0,1],[0,1],color='navy',lw=10,linestyle='--')
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Ada Boost Classifier')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output><jupyter_text>3.Gradient Boosting Classifier:<jupyter_code>gbc = GradientBoostingClassifier(criterion='mse', n_estimators=100, learning_rate=0.1, loss='deviance')
gbc.fit(train_x,train_y)
gbc.score(train_x,train_y)
pred_gbc = gbc.predict(test_x)

print("Accuracy Score:",accuracy_score(test_y,pred_gbc)*100)
print("Classification report:",classification_report(test_y,pred_gbc)*100)
print("Confusion Matrix:",confusion_matrix(test_y,pred_gbc)*100)

gbc_score = cross_val_score(gbc,xtrain,ytrain,cv=9)
gbc_cc = gbc_score.mean() 
print('Cross Val Score:',gbc_cc*100)<jupyter_output>Accuracy Score: 63.346064633146725
Classification report:               precision    recall  f1-score   support

           0       0.79      0.36      0.49     28576
           1       0.59      0.91      0.71     28763

    accuracy                           0.63     57339
   macro avg       0.69      0.63      0.60     57339
weighted avg       0.69      0.63      0.60     57339
              precision    recall  f1-score   support

           0       0.79      0.36      0.49     28576
           1       0.59      0.91      0.71     28763

    accuracy                           0.63     57339
   macro avg       0.69      0.63      0.60     57339
weighted avg       0.69      0.63      0.60     57339
              precision    recall  f1-score   support

           0       0.79      0.36      0.49     28576
           1       0.59      0.91      0.71     28763

    accuracy                           0.63     57339
   macro avg       0.69      0.63      0.60     57339
weighted avg      [...]<jupyter_text>AUC-ROC Curve:<jupyter_code>from sklearn.metrics import roc_curve,auc
fpr,tpr,thresholds=roc_curve(pred_gbc,test_y)
roc_auc=auc(fpr,tpr)
plt.figure()
plt.plot(fpr,tpr,color='darkorange',lw=10,label='ROC Curve(area=%0.2f)'%roc_auc)
plt.plot([0,1],[0,1],color='navy',lw=10,linestyle='--')
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Gradient Boosting Classifier')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output><jupyter_text>XGBOOST:<jupyter_code>#!pip install xgboost
import xgboost

xgb = xgboost.XGBClassifier()
xgb.fit(train_x,train_y)
xgb.score(train_x,train_y)
pred_xgb = xgb.predict(test_x)

print("Accuracy Score:",accuracy_score(test_y,pred_xgb)*100)
print("Classification report:",classification_report(test_y,pred_xgb)*100)
print("Confusion Matrix:",confusion_matrix(test_y,pred_xgb)*100)

xgb_score = cross_val_score(xgb,xtrain,ytrain,cv=9)
xgb_cc = gbc_score.mean() 
print('Cross Val Score:',xgb_cc*100)<jupyter_output>[18:40:03] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.5.1/src/learner.cc:1115: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.
Accuracy Score: 67.83515582762169
Classification report:               precision    recall  f1-score   support

           0       0.84      0.44      0.58     28576
           1       0.62      0.91      0.74     28763

    accuracy                           0.68     57339
   macro avg       0.73      0.68      0.66     57339
weighted avg       0.73      0.68      0.66     57339
              precision    recall  f1-score   support

           0       0.84      0.44      0.58     28576
           1       0.62      0.91      0.74     28763

    accuracy                           0.68     57339
   macro avg       0.73      0.68      0.66     57339
weighted avg       0.73      0.68  [...]<jupyter_text>AUC-ROC Curve:<jupyter_code>from sklearn.metrics import roc_curve,auc
fpr,tpr,thresholds=roc_curve(pred_xgb,test_y)
roc_auc=auc(fpr,tpr)
plt.figure()
plt.plot(fpr,tpr,color='darkorange',lw=10,label='ROC Curve(area=%0.2f)'%roc_auc)
plt.plot([0,1],[0,1],color='navy',lw=10,linestyle='--')
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('XGBoost Classifier')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output><jupyter_text>The best model is Random Forest Classifier. Since the difference between the percentage score of cross validation,accuracy_score and ROC Curve is optimum.  Model Saving:<jupyter_code>import pickle
filename='malign-comment.pkl'
pickle.dump(rfc,open(filename,'wb'))<jupyter_output><empty_output><jupyter_text>Coclusion:<jupyter_code>import numpy as np
a=np.array(test_y)
predicted=np.array(rfc.predict(test_x))
mal_con=pd.DataFrame({"original":a,"predicted":predicted},index=range(len(a)))
mal_con<jupyter_output><empty_output><jupyter_text>From the above table, the model is predicted with 78 percent accuracy.<jupyter_code>#Converting test dataset into vector

test1=tfidf.fit_transform(test['comment_text'])
test1
#predicting test dataset using chosen model

pred = rfc.predict(test1)
pred
#creating dataset with predicted output

test['Predicted Output'] = pred
test
#converting into csv file

test.to_csv('Test.csv', index = False)
#downloading the csv file

test.to_csv(r'C:\Users\DELL\Downloads\Test.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12612091408735898, 'fraction_numerical': 0.08120170254969214, 'mean_word_length': 3.4387380777696257, 'pattern_counts': {'":': 2, '<': 140, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '37', 'dir': 'jupyter-structured-clean-dedup', 'id': '347418', 'license': 'MIT', 'n_tokens_mistral': 9903, 'n_tokens_neox': 8714, 'n_words': 1608, 'path': 'Malignant-Comments-Classifier.ipynb', 'repo_name': 'asifansar120/MALIGNANT-COMMENTS-CLASSIFIER-', 'size': '24199'}