{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-23T18:58:05.338425Z","iopub.execute_input":"2023-01-23T18:58:05.338929Z","iopub.status.idle":"2023-01-23T18:58:05.374172Z","shell.execute_reply.started":"2023-01-23T18:58:05.338826Z","shell.execute_reply":"2023-01-23T18:58:05.372726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport csv\nimport re \nimport string\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.feature_extraction.text import TfidfVectorizer","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:05.376025Z","iopub.execute_input":"2023-01-23T18:58:05.376403Z","iopub.status.idle":"2023-01-23T18:58:06.801786Z","shell.execute_reply.started":"2023-01-23T18:58:05.376373Z","shell.execute_reply":"2023-01-23T18:58:06.800152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/goodreads-books-reviews-290312/goodreads_train.csv\")\ntest = pd.read_csv(\"/kaggle/input/goodreads-books-reviews-290312/goodreads_test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:06.803751Z","iopub.execute_input":"2023-01-23T18:58:06.804183Z","iopub.status.idle":"2023-01-23T18:58:51.257398Z","shell.execute_reply.started":"2023-01-23T18:58:06.804140Z","shell.execute_reply":"2023-01-23T18:58:51.256361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0=train[train['rating']==0]\ntrain1=train[train['rating']==1]\ntrain2=train[train['rating']==2]\ntrain3=train[train['rating']==3]\ntrain4=train[train['rating']==4]\ntrain5=train[train['rating']==5]","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.259786Z","iopub.execute_input":"2023-01-23T18:58:51.260182Z","iopub.status.idle":"2023-01-23T18:58:51.553971Z","shell.execute_reply.started":"2023-01-23T18:58:51.260147Z","shell.execute_reply":"2023-01-23T18:58:51.552732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0.shape, train1.shape, train2.shape, train3.shape, train4.shape, train5.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.555945Z","iopub.execute_input":"2023-01-23T18:58:51.556302Z","iopub.status.idle":"2023-01-23T18:58:51.568784Z","shell.execute_reply.started":"2023-01-23T18:58:51.556271Z","shell.execute_reply":"2023-01-23T18:58:51.567573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0=train0[:int(train0.shape[0]/100)]\ntrain1=train1[:int(train1.shape[0]/100)]\ntrain2=train2[:int(train2.shape[0]/100)]\ntrain3=train3[:int(train3.shape[0]/100)]\ntrain4=train4[:int(train4.shape[0]/100)]\ntrain5=train5[:int(train5.shape[0]/100)]","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.570284Z","iopub.execute_input":"2023-01-23T18:58:51.571177Z","iopub.status.idle":"2023-01-23T18:58:51.581827Z","shell.execute_reply.started":"2023-01-23T18:58:51.571129Z","shell.execute_reply":"2023-01-23T18:58:51.580123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0.shape, train1.shape, train2.shape, train3.shape, train4.shape, train5.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.583732Z","iopub.execute_input":"2023-01-23T18:58:51.584154Z","iopub.status.idle":"2023-01-23T18:58:51.597571Z","shell.execute_reply.started":"2023-01-23T18:58:51.584121Z","shell.execute_reply":"2023-01-23T18:58:51.596162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.concat([train0,train1,train2,train3,train4,train5],axis=0)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.599549Z","iopub.execute_input":"2023-01-23T18:58:51.600342Z","iopub.status.idle":"2023-01-23T18:58:51.670537Z","shell.execute_reply.started":"2023-01-23T18:58:51.600289Z","shell.execute_reply":"2023-01-23T18:58:51.669387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.674010Z","iopub.execute_input":"2023-01-23T18:58:51.674433Z","iopub.status.idle":"2023-01-23T18:58:51.681621Z","shell.execute_reply.started":"2023-01-23T18:58:51.674398Z","shell.execute_reply":"2023-01-23T18:58:51.680686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.columns","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.683262Z","iopub.execute_input":"2023-01-23T18:58:51.683634Z","iopub.status.idle":"2023-01-23T18:58:51.696068Z","shell.execute_reply.started":"2023-01-23T18:58:51.683592Z","shell.execute_reply":"2023-01-23T18:58:51.694703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\n#plotting the heatmap for correlation\nax = sns.heatmap(train.corr(), annot=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:51.697342Z","iopub.execute_input":"2023-01-23T18:58:51.697688Z","iopub.status.idle":"2023-01-23T18:58:52.253218Z","shell.execute_reply.started":"2023-01-23T18:58:51.697659Z","shell.execute_reply":"2023-01-23T18:58:52.251997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(['user_id', 'book_id', 'review_id', 'date_added', 'date_updated', 'n_votes','read_at', 'started_at','n_comments'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:52.254638Z","iopub.execute_input":"2023-01-23T18:58:52.254995Z","iopub.status.idle":"2023-01-23T18:58:52.268214Z","shell.execute_reply.started":"2023-01-23T18:58:52.254963Z","shell.execute_reply":"2023-01-23T18:58:52.266879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:52.270281Z","iopub.execute_input":"2023-01-23T18:58:52.270842Z","iopub.status.idle":"2023-01-23T18:58:52.294031Z","shell.execute_reply.started":"2023-01-23T18:58:52.270716Z","shell.execute_reply":"2023-01-23T18:58:52.292434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.columns\n","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:52.295406Z","iopub.execute_input":"2023-01-23T18:58:52.295772Z","iopub.status.idle":"2023-01-23T18:58:52.303837Z","shell.execute_reply.started":"2023-01-23T18:58:52.295733Z","shell.execute_reply":"2023-01-23T18:58:52.302567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.drop(['user_id', 'book_id', 'review_id', 'date_added','date_updated', 'read_at', 'started_at','n_comments'], axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:52.305693Z","iopub.execute_input":"2023-01-23T18:58:52.306199Z","iopub.status.idle":"2023-01-23T18:58:52.380812Z","shell.execute_reply.started":"2023-01-23T18:58:52.306162Z","shell.execute_reply":"2023-01-23T18:58:52.379764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:52.382430Z","iopub.execute_input":"2023-01-23T18:58:52.382839Z","iopub.status.idle":"2023-01-23T18:58:52.399202Z","shell.execute_reply.started":"2023-01-23T18:58:52.382792Z","shell.execute_reply":"2023-01-23T18:58:52.397818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Remove Hashtags\ntrain['review_text'].replace( { r\"#(\\w+)\" : '' }, inplace= True, regex = True)\n\n#Remove Mention\ntrain['review_text'].replace( { r\"@(\\w+)\" : '' }, inplace= True, regex = True)\n\n#Remove URL\ntrain['review_text'].astype(str).replace( { r\"http\\S+\" : '' }, inplace= True, regex = True)\n\ntrain['review_text']=train['review_text'].str.lower()","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:52.400829Z","iopub.execute_input":"2023-01-23T18:58:52.401316Z","iopub.status.idle":"2023-01-23T18:58:52.496023Z","shell.execute_reply.started":"2023-01-23T18:58:52.401268Z","shell.execute_reply":"2023-01-23T18:58:52.494567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Remove Hashtags\ntest['review_text'].replace( { r\"#(\\w+)\" : '' }, inplace= True, regex = True)\n\n#Remove Mention\ntest['review_text'].replace( { r\"@(\\w+)\" : '' }, inplace= True, regex = True)\n\n#Remove URL\ntest['review_text'].astype(str).replace( { r\"http\\S+\" : '' }, inplace= True, regex = True)\n\ntest['review_text'] = test['review_text'].str.lower()","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:52.497698Z","iopub.execute_input":"2023-01-23T18:58:52.498100Z","iopub.status.idle":"2023-01-23T18:58:57.189794Z","shell.execute_reply.started":"2023-01-23T18:58:52.498066Z","shell.execute_reply":"2023-01-23T18:58:57.188893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Import stopwords with nltk.\nfrom nltk.corpus import stopwords\nstop = stopwords.words('english')","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:57.195480Z","iopub.execute_input":"2023-01-23T18:58:57.196112Z","iopub.status.idle":"2023-01-23T18:58:57.848165Z","shell.execute_reply.started":"2023-01-23T18:58:57.196077Z","shell.execute_reply":"2023-01-23T18:58:57.846940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['review_text'] = train['review_text'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stop)]))\n\ntest['review_text'] = test['review_text'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stop)]))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T18:58:57.849637Z","iopub.execute_input":"2023-01-23T18:58:57.850019Z","iopub.status.idle":"2023-01-23T19:02:26.095139Z","shell.execute_reply.started":"2023-01-23T18:58:57.849986Z","shell.execute_reply":"2023-01-23T19:02:26.093872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:02:26.096894Z","iopub.execute_input":"2023-01-23T19:02:26.097265Z","iopub.status.idle":"2023-01-23T19:02:26.109332Z","shell.execute_reply.started":"2023-01-23T19:02:26.097234Z","shell.execute_reply":"2023-01-23T19:02:26.107859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:02:26.111368Z","iopub.execute_input":"2023-01-23T19:02:26.112184Z","iopub.status.idle":"2023-01-23T19:02:26.127608Z","shell.execute_reply.started":"2023-01-23T19:02:26.112134Z","shell.execute_reply":"2023-01-23T19:02:26.125959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:02:26.129424Z","iopub.execute_input":"2023-01-23T19:02:26.130646Z","iopub.status.idle":"2023-01-23T19:02:26.139506Z","shell.execute_reply.started":"2023-01-23T19:02:26.130601Z","shell.execute_reply":"2023-01-23T19:02:26.138378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:02:26.143998Z","iopub.execute_input":"2023-01-23T19:02:26.144386Z","iopub.status.idle":"2023-01-23T19:02:26.151830Z","shell.execute_reply.started":"2023-01-23T19:02:26.144356Z","shell.execute_reply":"2023-01-23T19:02:26.150951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['rating'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:02:26.153377Z","iopub.execute_input":"2023-01-23T19:02:26.154167Z","iopub.status.idle":"2023-01-23T19:02:26.167694Z","shell.execute_reply.started":"2023-01-23T19:02:26.154130Z","shell.execute_reply":"2023-01-23T19:02:26.166500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = train['rating']\nx = train['review_text']","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:03:25.732428Z","iopub.execute_input":"2023-01-23T19:03:25.732933Z","iopub.status.idle":"2023-01-23T19:03:25.739255Z","shell.execute_reply.started":"2023-01-23T19:03:25.732896Z","shell.execute_reply":"2023-01-23T19:03:25.737888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:03:55.551547Z","iopub.execute_input":"2023-01-23T19:03:55.552521Z","iopub.status.idle":"2023-01-23T19:03:55.561654Z","shell.execute_reply.started":"2023-01-23T19:03:55.552447Z","shell.execute_reply":"2023-01-23T19:03:55.560219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating a word corpus for vectorization\ncorpus = []\nfor i in range(x.shape[0]):\n    corpus.append(x.iloc[i])","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:18:20.704200Z","iopub.execute_input":"2023-01-23T19:18:20.704586Z","iopub.status.idle":"2023-01-23T19:18:20.782376Z","shell.execute_reply.started":"2023-01-23T19:18:20.704555Z","shell.execute_reply":"2023-01-23T19:18:20.781327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vectorizer1 = TfidfVectorizer(max_features=1000)\nX1 = vectorizer1.fit_transform(x)\nfeature_names1 = vectorizer1.get_feature_names()\ndenselist1 = X1.todense().tolist()\ntrain = pd.DataFrame(denselist1, columns=feature_names1)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:06:29.422102Z","iopub.execute_input":"2023-01-23T19:06:29.422562Z","iopub.status.idle":"2023-01-23T19:06:33.858711Z","shell.execute_reply.started":"2023-01-23T19:06:29.422526Z","shell.execute_reply":"2023-01-23T19:06:33.857275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# splitting the training and testing part from the data\nX_temp, X_test, y_temp, y_test = train_test_split(train, y, test_size=0.2, random_state=0)","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:06:37.375788Z","iopub.execute_input":"2023-01-23T19:06:37.376226Z","iopub.status.idle":"2023-01-23T19:06:37.449195Z","shell.execute_reply.started":"2023-01-23T19:06:37.376191Z","shell.execute_reply":"2023-01-23T19:06:37.447972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_temp.shape, X_test.shape, y_temp.shape, y_test.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:07:12.343429Z","iopub.execute_input":"2023-01-23T19:07:12.343916Z","iopub.status.idle":"2023-01-23T19:07:12.353582Z","shell.execute_reply.started":"2023-01-23T19:07:12.343874Z","shell.execute_reply":"2023-01-23T19:07:12.352133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.ensemble import GradientBoostingClassifier\n\nfrom sklearn import metrics\nimport matplotlib.pyplot as plt\n%matplotlib inline\nfrom sklearn.metrics import plot_confusion_matrix\nfrom sklearn.metrics import precision_score, recall_score, f1_score\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:07:37.813421Z","iopub.execute_input":"2023-01-23T19:07:37.813872Z","iopub.status.idle":"2023-01-23T19:07:38.002197Z","shell.execute_reply.started":"2023-01-23T19:07:37.813838Z","shell.execute_reply":"2023-01-23T19:07:38.001024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = {'TF-IDF':[]}","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:08:14.753130Z","iopub.execute_input":"2023-01-23T19:08:14.753526Z","iopub.status.idle":"2023-01-23T19:08:14.759341Z","shell.execute_reply.started":"2023-01-23T19:08:14.753495Z","shell.execute_reply":"2023-01-23T19:08:14.757867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Logistic Regression","metadata":{}},{"cell_type":"code","source":"#TF-IDF\nregressor_LR_tf = LogisticRegression(C=1.0,penalty='l2',solver='newton-cg')\nregressor_LR_tf.fit(X_temp, y_temp)\ny_predict_LR_tf = regressor_LR_tf.predict(X_test)\na=(regressor_LR_tf.score(X_test, y_test))\naccuracy['TF-IDF'].append(a)\n\nprint(metrics.confusion_matrix(y_test, y_predict_LR_tf))\nprint(metrics.classification_report(y_test, y_predict_LR_tf))\nprint(metrics.accuracy_score(y_test, y_predict_LR_tf))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:09:11.264146Z","iopub.execute_input":"2023-01-23T19:09:11.264607Z","iopub.status.idle":"2023-01-23T19:09:15.496731Z","shell.execute_reply.started":"2023-01-23T19:09:11.264571Z","shell.execute_reply":"2023-01-23T19:09:15.495109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Decision Tree","metadata":{}},{"cell_type":"code","source":"#TF-IDF\nmodel_DT_tf = DecisionTreeClassifier(criterion = 'gini', max_depth=2) \nmodel_DT_tf.fit(X_temp, y_temp)\ny_predict_DT_tf = model_DT_tf.predict(X_test)\na=(model_DT_tf.score(X_test,y_test))\naccuracy['TF-IDF'].append(a)\n\nprint(metrics.confusion_matrix(y_test, y_predict_DT_tf))\nprint(metrics.classification_report(y_test, y_predict_DT_tf))\nprint(metrics.accuracy_score(y_test, y_predict_DT_tf))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:11:43.674129Z","iopub.execute_input":"2023-01-23T19:11:43.674641Z","iopub.status.idle":"2023-01-23T19:11:43.901664Z","shell.execute_reply.started":"2023-01-23T19:11:43.674603Z","shell.execute_reply":"2023-01-23T19:11:43.900248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Gradient Boosting","metadata":{}},{"cell_type":"code","source":"#TF-IDF\nmodel_GB_tf = GradientBoostingClassifier(learning_rate= 0.1, max_depth=3, n_estimators= 100,subsample=1.0) \nmodel_GB_tf.fit(X_temp, y_temp)\ny_predict_GB_tf = model_GB_tf.predict(X_test)\na=(model_GB_tf.score(X_test,y_test))\naccuracy['TF-IDF'].append(a)\nprint(metrics.confusion_matrix(y_test, y_predict_GB_tf))\nprint(metrics.classification_report(y_test, y_predict_GB_tf))\nprint(metrics.accuracy_score(y_test, y_predict_GB_tf))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:12:06.389025Z","iopub.execute_input":"2023-01-23T19:12:06.389500Z","iopub.status.idle":"2023-01-23T19:13:58.735193Z","shell.execute_reply.started":"2023-01-23T19:12:06.389463Z","shell.execute_reply":"2023-01-23T19:13:58.733996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Random Forest","metadata":{}},{"cell_type":"code","source":"#TF-IDF\nmodel_RF_tf = RandomForestClassifier(n_estimators= 100, max_features = 'log2')\nmodel_RF_tf.fit(X_temp, y_temp)\ny_predict_RF_tf = model_RF_tf.predict(X_test)\na=(model_RF_tf.score(X_test,y_test))\naccuracy['TF-IDF'].append(a)\n\nprint(metrics.confusion_matrix(y_test, y_predict_RF_tf))\nprint(metrics.classification_report(y_test, y_predict_RF_tf))\nprint(metrics.accuracy_score(y_test, y_predict_RF_tf))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:14:13.650726Z","iopub.execute_input":"2023-01-23T19:14:13.651161Z","iopub.status.idle":"2023-01-23T19:14:17.793749Z","shell.execute_reply.started":"2023-01-23T19:14:13.651127Z","shell.execute_reply":"2023-01-23T19:14:17.792721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# K Nearest Neighbours","metadata":{}},{"cell_type":"code","source":"#TF-IDF\nmodel_KN_tf = KNeighborsClassifier(metric= 'manhattan', n_neighbors= 5, weights= 'distance') \nmodel_KN_tf.fit(X_temp, y_temp)\ny_predict_KN_tf = model_KN_tf.predict(X_test)\na=(model_KN_tf.score(X_test,y_test))\naccuracy['TF-IDF'].append(a)\nprint(metrics.confusion_matrix(y_test, y_predict_KN_tf))\nprint(metrics.classification_report(y_test, y_predict_KN_tf))\nprint(metrics.accuracy_score(y_test, y_predict_KN_tf))","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:14:34.279025Z","iopub.execute_input":"2023-01-23T19:14:34.279458Z","iopub.status.idle":"2023-01-23T19:17:00.953403Z","shell.execute_reply.started":"2023-01-23T19:14:34.279422Z","shell.execute_reply":"2023-01-23T19:17:00.952030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EVALUATION","metadata":{}},{"cell_type":"code","source":"model = ['LR','DT','GB','RF','KN']\ndata = {'model':model,'accuracy':accuracy['TF-IDF']}\ncompare_models = pd.DataFrame(data)\ncompare_models","metadata":{"execution":{"iopub.status.busy":"2023-01-23T19:17:00.955223Z","iopub.execute_input":"2023-01-23T19:17:00.955586Z","iopub.status.idle":"2023-01-23T19:17:00.968743Z","shell.execute_reply.started":"2023-01-23T19:17:00.955555Z","shell.execute_reply":"2023-01-23T19:17:00.967725Z"},"trusted":true},"execution_count":null,"outputs":[]}]}