{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd \nimport  matplotlib.pyplot as plt\nimport numpy as np \nimport tensorflow as tf\nimport keras\nimport re\nimport string\nimport nltk\nfrom nltk.corpus import stopwords\nfrom nltk.stem.porter import PorterStemmer\nfrom wordcloud import WordCloud\nfrom nltk.stem.snowball import SnowballStemmer\nfrom sklearn.model_selection import train_test_split\nimport pickle\nimport xgboost as xgb\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn import metrics\nfrom sklearn.metrics import roc_auc_score , accuracy_score , confusion_matrix , f1_score\nfrom sklearn.multiclass import OneVsRestClassifier\nfrom skmultilearn.problem_transform import BinaryRelevance\nfrom sklearn.feature_extraction.text import TfidfVectorizer\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:18:50.790226Z","iopub.execute_input":"2022-07-14T05:18:50.790821Z","iopub.status.idle":"2022-07-14T05:18:57.912793Z","shell.execute_reply.started":"2022-07-14T05:18:50.790727Z","shell.execute_reply":"2022-07-14T05:18:57.911980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data  =  pd.read_csv('../input/jigsaw-toxic-comment-classification-challenge/train.csv.zip')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:18:57.914424Z","iopub.execute_input":"2022-07-14T05:18:57.914651Z","iopub.status.idle":"2022-07-14T05:18:59.830236Z","shell.execute_reply.started":"2022-07-14T05:18:57.914618Z","shell.execute_reply":"2022-07-14T05:18:59.829471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data  =  pd.read_csv('../input/jigsaw-toxic-comment-classification-challenge/test.csv.zip')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:18:59.831685Z","iopub.execute_input":"2022-07-14T05:18:59.832014Z","iopub.status.idle":"2022-07-14T05:19:01.780963Z","shell.execute_reply.started":"2022-07-14T05:18:59.831973Z","shell.execute_reply":"2022-07-14T05:19:01.780118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_target =  pd.read_csv('../input/jigsaw-toxic-comment-classification-challenge/test_labels.csv.zip')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:01.782988Z","iopub.execute_input":"2022-07-14T05:19:01.783241Z","iopub.status.idle":"2022-07-14T05:19:01.986405Z","shell.execute_reply.started":"2022-07-14T05:19:01.783207Z","shell.execute_reply":"2022-07-14T05:19:01.985636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:01.989377Z","iopub.execute_input":"2022-07-14T05:19:01.989657Z","iopub.status.idle":"2022-07-14T05:19:02.009769Z","shell.execute_reply.started":"2022-07-14T05:19:01.989622Z","shell.execute_reply":"2022-07-14T05:19:02.009084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.012326Z","iopub.execute_input":"2022-07-14T05:19:02.013126Z","iopub.status.idle":"2022-07-14T05:19:02.022173Z","shell.execute_reply.started":"2022-07-14T05:19:02.013088Z","shell.execute_reply":"2022-07-14T05:19:02.021343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_target.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.023616Z","iopub.execute_input":"2022-07-14T05:19:02.023910Z","iopub.status.idle":"2022-07-14T05:19:02.036638Z","shell.execute_reply.started":"2022-07-14T05:19:02.023874Z","shell.execute_reply":"2022-07-14T05:19:02.035724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.038428Z","iopub.execute_input":"2022-07-14T05:19:02.038799Z","iopub.status.idle":"2022-07-14T05:19:02.044751Z","shell.execute_reply.started":"2022-07-14T05:19:02.038757Z","shell.execute_reply":"2022-07-14T05:19:02.044010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.046128Z","iopub.execute_input":"2022-07-14T05:19:02.046588Z","iopub.status.idle":"2022-07-14T05:19:02.056567Z","shell.execute_reply.started":"2022-07-14T05:19:02.046553Z","shell.execute_reply":"2022-07-14T05:19:02.055908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_target)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.060534Z","iopub.execute_input":"2022-07-14T05:19:02.061120Z","iopub.status.idle":"2022-07-14T05:19:02.069808Z","shell.execute_reply.started":"2022-07-14T05:19:02.061084Z","shell.execute_reply":"2022-07-14T05:19:02.068948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.071136Z","iopub.execute_input":"2022-07-14T05:19:02.071821Z","iopub.status.idle":"2022-07-14T05:19:02.121239Z","shell.execute_reply.started":"2022-07-14T05:19:02.071785Z","shell.execute_reply":"2022-07-14T05:19:02.120339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.122864Z","iopub.execute_input":"2022-07-14T05:19:02.123195Z","iopub.status.idle":"2022-07-14T05:19:02.177821Z","shell.execute_reply.started":"2022-07-14T05:19:02.123161Z","shell.execute_reply":"2022-07-14T05:19:02.177098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"comments = train_data.drop(['id','comment_text'],axis = 1)\nfor i in comments.columns :\n    print(\"Percent of {0}s: \".format(i), round(100*comments[i].mean(),2), \"%\")\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.179456Z","iopub.execute_input":"2022-07-14T05:19:02.179719Z","iopub.status.idle":"2022-07-14T05:19:02.193919Z","shell.execute_reply.started":"2022-07-14T05:19:02.179683Z","shell.execute_reply":"2022-07-14T05:19:02.193078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = {}\nfor i in list(comments.columns):\n    classes[i] =  comments[i].sum()\nn_classes = [classes[i] for i in list(classes.keys())]\nclasses = list(classes.keys())","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.195136Z","iopub.execute_input":"2022-07-14T05:19:02.195524Z","iopub.status.idle":"2022-07-14T05:19:02.202986Z","shell.execute_reply.started":"2022-07-14T05:19:02.195456Z","shell.execute_reply":"2022-07-14T05:19:02.202384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"color = ['red','blue','green','yellow','black','orange']\nplt.figure(figsize=(12,12))\nfig, ax = plt.subplots()\nax.bar(classes,n_classes,color = color)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.204402Z","iopub.execute_input":"2022-07-14T05:19:02.204868Z","iopub.status.idle":"2022-07-14T05:19:02.433259Z","shell.execute_reply.started":"2022-07-14T05:19:02.204829Z","shell.execute_reply":"2022-07-14T05:19:02.432569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def  clean_text(text):\n    text =  text.lower()\n    text = re.sub(r\"i'm\", \"i am\", text)\n    text = re.sub(r\"\\r\", \"\", text)\n    text = re.sub(r\"he's\", \"he is\", text)\n    text = re.sub(r\"she's\", \"she is\", text)\n    text = re.sub(r\"it's\", \"it is\", text)\n    text = re.sub(r\"that's\", \"that is\", text)\n    text = re.sub(r\"what's\", \"that is\", text)\n    text = re.sub(r\"where's\", \"where is\", text)\n    text = re.sub(r\"how's\", \"how is\", text)\n    text = re.sub(r\"\\'ll\", \" will\", text)\n    text = re.sub(r\"\\'ve\", \" have\", text)\n    text = re.sub(r\"\\'re\", \" are\", text)\n    text = re.sub(r\"\\'d\", \" would\", text)\n    text = re.sub(r\"\\'re\", \" are\", text)\n    text = re.sub(r\"won't\", \"will not\", text)\n    text = re.sub(r\"can't\", \"cannot\", text)\n    text = re.sub(r\"n't\", \" not\", text)\n    text = re.sub(r\"n'\", \"ng\", text)\n    text = re.sub(r\"'bout\", \"about\", text)\n    text = re.sub(r\"'til\", \"until\", text)\n    text = re.sub(r\"[-()\\\"#/@;:<>{}`+=~|.!?,]\", \"\", text)\n    text = text.translate(str.maketrans('', '', string.punctuation)) \n    text = re.sub(\"(\\\\W)\",\" \",text) \n    text = re.sub('\\S*\\d\\S*\\s*','', text)\n    \n    return text","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.434648Z","iopub.execute_input":"2022-07-14T05:19:02.435047Z","iopub.status.idle":"2022-07-14T05:19:02.446295Z","shell.execute_reply.started":"2022-07-14T05:19:02.435008Z","shell.execute_reply":"2022-07-14T05:19:02.445454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain_data.comment_text = train_data.comment_text.apply(clean_text)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:02.447581Z","iopub.execute_input":"2022-07-14T05:19:02.448064Z","iopub.status.idle":"2022-07-14T05:19:30.956628Z","shell.execute_reply.started":"2022-07-14T05:19:02.448022Z","shell.execute_reply":"2022-07-14T05:19:30.955867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:30.958220Z","iopub.execute_input":"2022-07-14T05:19:30.958743Z","iopub.status.idle":"2022-07-14T05:19:30.971986Z","shell.execute_reply.started":"2022-07-14T05:19:30.958704Z","shell.execute_reply":"2022-07-14T05:19:30.971121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nltk.download('stopwords')\nsn = SnowballStemmer(language='english')\n\n\ndef stemmer(text):\n    words =  text.split()\n    train = [sn.stem(word) for word in words if not word in set(stopwords.words('english'))]\n    return ' '.join(train)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:30.973536Z","iopub.execute_input":"2022-07-14T05:19:30.974127Z","iopub.status.idle":"2022-07-14T05:19:31.270995Z","shell.execute_reply.started":"2022-07-14T05:19:30.974092Z","shell.execute_reply":"2022-07-14T05:19:31.270093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.comment_text = train_data.comment_text.apply(stemmer)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:19:31.272258Z","iopub.execute_input":"2022-07-14T05:19:31.272527Z","iopub.status.idle":"2022-07-14T05:43:40.872595Z","shell.execute_reply.started":"2022-07-14T05:19:31.272490Z","shell.execute_reply":"2022-07-14T05:43:40.871820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.comment_text.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:40.877024Z","iopub.execute_input":"2022-07-14T05:43:40.878944Z","iopub.status.idle":"2022-07-14T05:43:40.890204Z","shell.execute_reply.started":"2022-07-14T05:43:40.878904Z","shell.execute_reply":"2022-07-14T05:43:40.889337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wordcloud = WordCloud(stopwords=stopwords.words('english'),max_words=50).generate(str(train_data.comment_text))\nplt.figure(figsize=(10,6))\nplt.imshow(wordcloud)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:40.893242Z","iopub.execute_input":"2022-07-14T05:43:40.893672Z","iopub.status.idle":"2022-07-14T05:43:41.357723Z","shell.execute_reply.started":"2022-07-14T05:43:40.893636Z","shell.execute_reply":"2022-07-14T05:43:41.356874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x =  train_data.comment_text\ny =  train_data.drop(['id','comment_text'],axis = 1)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:41.358759Z","iopub.execute_input":"2022-07-14T05:43:41.358977Z","iopub.status.idle":"2022-07-14T05:43:41.371609Z","shell.execute_reply.started":"2022-07-14T05:43:41.358949Z","shell.execute_reply":"2022-07-14T05:43:41.370797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(type(x))","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:41.373155Z","iopub.execute_input":"2022-07-14T05:43:41.373597Z","iopub.status.idle":"2022-07-14T05:43:41.378180Z","shell.execute_reply.started":"2022-07-14T05:43:41.373559Z","shell.execute_reply":"2022-07-14T05:43:41.377506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train,x_test,y_train,y_test =  train_test_split(x,y,test_size = 0.2,random_state = 45)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:41.379374Z","iopub.execute_input":"2022-07-14T05:43:41.379822Z","iopub.status.idle":"2022-07-14T05:43:41.418233Z","shell.execute_reply.started":"2022-07-14T05:43:41.379786Z","shell.execute_reply":"2022-07-14T05:43:41.417468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:41.419670Z","iopub.execute_input":"2022-07-14T05:43:41.419952Z","iopub.status.idle":"2022-07-14T05:43:41.427559Z","shell.execute_reply.started":"2022-07-14T05:43:41.419915Z","shell.execute_reply":"2022-07-14T05:43:41.426755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train2 = x_train.to_numpy()\nx_test2 =  x_test.to_numpy()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:41.428830Z","iopub.execute_input":"2022-07-14T05:43:41.429254Z","iopub.status.idle":"2022-07-14T05:43:41.437918Z","shell.execute_reply.started":"2022-07-14T05:43:41.429216Z","shell.execute_reply":"2022-07-14T05:43:41.437167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train2 =  y_train.to_numpy()\ny_test =  y_test.to_numpy()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:43:41.443366Z","iopub.execute_input":"2022-07-14T05:43:41.443972Z","iopub.status.idle":"2022-07-14T05:43:41.449438Z","shell.execute_reply.started":"2022-07-14T05:43:41.443940Z","shell.execute_reply":"2022-07-14T05:43:41.448760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"word_vectorizer = TfidfVectorizer(\n    strip_accents='unicode',     \n    analyzer='word',            \n    token_pattern=r'\\w{1,}',    \n    ngram_range=(1, 3),         \n    stop_words='english',\n    sublinear_tf=True)\n\nword_vectorizer.fit(x_train2)    \ntrain_word_features = word_vectorizer.transform(x_train2)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:54:02.481230Z","iopub.execute_input":"2022-07-14T05:54:02.481496Z","iopub.status.idle":"2022-07-14T05:54:57.882275Z","shell.execute_reply.started":"2022-07-14T05:54:02.481466Z","shell.execute_reply":"2022-07-14T05:54:57.881460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import joblib\n\njoblib.dump(word_vectorizer, open('vectroize2_jlib', 'wb'))\n\nvectorizer = joblib.load('vectroize2_jlib')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:54:57.883831Z","iopub.execute_input":"2022-07-14T05:54:57.884061Z","iopub.status.idle":"2022-07-14T05:56:13.307978Z","shell.execute_reply.started":"2022-07-14T05:54:57.884028Z","shell.execute_reply":"2022-07-14T05:56:13.307183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_transformed = vectorizer.transform(x_train2)\nX_test_transformed = vectorizer.transform(x_test2)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:56:13.309524Z","iopub.execute_input":"2022-07-14T05:56:13.309833Z","iopub.status.idle":"2022-07-14T05:56:32.136437Z","shell.execute_reply.started":"2022-07-14T05:56:13.309799Z","shell.execute_reply":"2022-07-14T05:56:32.135469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train_transformed)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:04:51.170905Z","iopub.execute_input":"2022-07-14T06:04:51.171172Z","iopub.status.idle":"2022-07-14T06:04:51.281905Z","shell.execute_reply.started":"2022-07-14T06:04:51.171143Z","shell.execute_reply":"2022-07-14T06:04:51.281119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"log_reg = LogisticRegression(C = 10, penalty='l2', solver = 'liblinear', random_state=45)\n\nclassifier = OneVsRestClassifier(log_reg)\nclassifier.fit(X_train_transformed, y_train)\n\n\ny_train_pred_proba = classifier.predict_proba(X_train_transformed)\ny_test_pred_proba = classifier.predict_proba(X_test_transformed)\n\n\nroc_auc_score_train = roc_auc_score(y_train2, y_train_pred_proba,average='weighted')\nroc_auc_score_test = roc_auc_score(y_test, y_test_pred_proba,average='weighted')\n\nprint(\"ROC AUC Score Train:\", roc_auc_score_train)\nprint(\"ROC AUC Score Test:\", roc_auc_score_test)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:04:51.920894Z","iopub.execute_input":"2022-07-14T06:04:51.921141Z","iopub.status.idle":"2022-07-14T06:06:48.712895Z","shell.execute_reply.started":"2022-07-14T06:04:51.921114Z","shell.execute_reply":"2022-07-14T06:06:48.712111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"joblib.dump(classifier, open('classifier2_jlib', 'wb'))\n\nword_vectorizer = joblib.load('classifier2_jlib')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:06:48.714449Z","iopub.execute_input":"2022-07-14T06:06:48.714771Z","iopub.status.idle":"2022-07-14T06:06:49.588718Z","shell.execute_reply.started":"2022-07-14T06:06:48.714734Z","shell.execute_reply":"2022-07-14T06:06:49.587951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def make_test_predictions(df,classifier):\n    df.comment_text = df.comment_text.apply(clean_text)\n    df.comment_text = df.comment_text.apply(stemmer)\n    X_test = df.comment_text\n    X_test =  X_test.to_numpy()\n    X_test_transformed = vectorizer.transform(X_test)\n    y_test_pred = classifier.predict_proba(X_test_transformed)\n    return y_test_pred\n    #y_test_pred_df = pd.DataFrame(y_test_pred,columns=comments.columns) \n    #submission_df = pd.concat([df.id, y_test_pred_df], axis=1)\n    #submission_df.to_csv('submission.csv', index = False)\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:06:49.589967Z","iopub.execute_input":"2022-07-14T06:06:49.590211Z","iopub.status.idle":"2022-07-14T06:06:49.597196Z","shell.execute_reply.started":"2022-07-14T06:06:49.590178Z","shell.execute_reply":"2022-07-14T06:06:49.596393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xx ={'id':[565],'comment_text':['Shut up your mouth bitch']}\nxx = pd.DataFrame(xx)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:06:49.599333Z","iopub.execute_input":"2022-07-14T06:06:49.599986Z","iopub.status.idle":"2022-07-14T06:06:49.613541Z","shell.execute_reply.started":"2022-07-14T06:06:49.599947Z","shell.execute_reply":"2022-07-14T06:06:49.612722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test 1 \nmake_test_predictions(xx,classifier)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:06:49.615153Z","iopub.execute_input":"2022-07-14T06:06:49.615340Z","iopub.status.idle":"2022-07-14T06:06:49.749973Z","shell.execute_reply.started":"2022-07-14T06:06:49.615311Z","shell.execute_reply":"2022-07-14T06:06:49.749287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xx ={'id':[565],'comment_text':['hi I am happy to be here']}\nxx = pd.DataFrame(xx)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:57:58.755377Z","iopub.execute_input":"2022-07-14T05:57:58.756118Z","iopub.status.idle":"2022-07-14T05:57:58.763356Z","shell.execute_reply.started":"2022-07-14T05:57:58.756081Z","shell.execute_reply":"2022-07-14T05:57:58.762609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test 2\nmake_test_predictions(xx,classifier)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T05:57:59.207271Z","iopub.execute_input":"2022-07-14T05:57:59.207821Z","iopub.status.idle":"2022-07-14T05:57:59.335086Z","shell.execute_reply.started":"2022-07-14T05:57:59.207783Z","shell.execute_reply":"2022-07-14T05:57:59.334344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def make_test_predictions(df,classifier):\n    df.comment_text = df.comment_text.apply(clean_text)\n    df.comment_text = df.comment_text.apply(stemmer)\n    X_test = df.comment_text\n    X_test =  X_test.to_numpy()\n    X_test_transformed = vectorizer.transform(X_test)\n    y_test_pred = classifier.predict_proba(X_test_transformed)\n    result =  sum(y_test_pred[0])\n    if result >=1 :\n       return(\"Offensive Comment\")\n    else :\n       return (\"Normal Comment\")\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:08:04.460585Z","iopub.execute_input":"2022-07-14T06:08:04.461017Z","iopub.status.idle":"2022-07-14T06:08:04.472710Z","shell.execute_reply.started":"2022-07-14T06:08:04.460973Z","shell.execute_reply":"2022-07-14T06:08:04.471927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"comment_text = \"fuck you\"\ncomment ={'id':[565],'comment_text':[comment_text]}\ncomment = pd.DataFrame(comment)\nresult = make_test_predictions(comment,classifier)\nprint(result)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:08:05.234927Z","iopub.execute_input":"2022-07-14T06:08:05.235187Z","iopub.status.idle":"2022-07-14T06:08:05.356016Z","shell.execute_reply.started":"2022-07-14T06:08:05.235156Z","shell.execute_reply":"2022-07-14T06:08:05.355136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"comment_text = \"thanks for your help\"\ncomment ={'id':[565],'comment_text':[comment_text]}\ncomment = pd.DataFrame(comment)\nresult = make_test_predictions(comment,classifier)\nprint(result)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:08:06.295977Z","iopub.execute_input":"2022-07-14T06:08:06.296800Z","iopub.status.idle":"2022-07-14T06:08:06.420493Z","shell.execute_reply.started":"2022-07-14T06:08:06.296747Z","shell.execute_reply":"2022-07-14T06:08:06.419601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"comment_text = \"I want to kill you\"\ncomment ={'id':[565],'comment_text':[comment_text]}\ncomment = pd.DataFrame(comment)\nresult = make_test_predictions(comment,classifier)\nprint(result)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:08:07.264972Z","iopub.execute_input":"2022-07-14T06:08:07.265662Z","iopub.status.idle":"2022-07-14T06:08:07.388396Z","shell.execute_reply.started":"2022-07-14T06:08:07.265623Z","shell.execute_reply":"2022-07-14T06:08:07.387634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"comment_text = \"I really like it\"\ncomment ={'id':[565],'comment_text':[comment_text]}\ncomment = pd.DataFrame(comment)\nresult = make_test_predictions(comment,classifier)\nprint(result)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T06:08:07.641772Z","iopub.execute_input":"2022-07-14T06:08:07.642369Z","iopub.status.idle":"2022-07-14T06:08:07.764288Z","shell.execute_reply.started":"2022-07-14T06:08:07.642332Z","shell.execute_reply":"2022-07-14T06:08:07.763324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}