{"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 warnings #Used to ignore the warning given as output of the code.\nwarnings.filterwarnings('ignore')\n\nimport math, re, os\nimport numpy as np\nimport pandas as pd\nfrom matplotlib import pyplot as plt\nfrom sklearn.metrics import f1_score, precision_score, recall_score, confusion_matrix\n\nfrom collections import defaultdict\n\nimport matplotlib.pyplot as plt #Basic library for data visualization.\nimport seaborn as sns #Slightly advanced library for data visualization\n\n# Import necessary libraries\n# To compute the accuracy of models\nfrom surprise import accuracy\n\n# class is used to parse a file containing play_counts, data should be in structure - user; item ; play_count\nfrom surprise.reader import Reader\n\n# class for loading datasets\nfrom surprise.dataset import Dataset\n\n# for tuning model hyperparameters\nfrom surprise.model_selection import GridSearchCV\n\n# for splitting the data in train and test dataset\nfrom surprise.model_selection import train_test_split\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":"2022-12-25T14:58:35.302788Z","iopub.execute_input":"2022-12-25T14:58:35.303756Z","iopub.status.idle":"2022-12-25T14:58:35.514304Z","shell.execute_reply.started":"2022-12-25T14:58:35.303716Z","shell.execute_reply":"2022-12-25T14:58:35.513107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/goodreads-books-reviews-290312/goodreads_train.csv\")\nprint(f'Shape of Training Data is : {train_data.shape[0]} rows and {train_data.shape[1]} columns')\ntest_data = pd.read_csv(\"/kaggle/input/goodreads-books-reviews-290312/goodreads_test.csv\")\nprint(f'Shape of Test Data is : {test_data.shape[0]} rows and {test_data.shape[1]} columns')\n\nsample_data = pd.read_csv(\"/kaggle/input/goodreads-books-reviews-290312/goodreads_sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:54:20.511324Z","iopub.execute_input":"2022-12-25T17:54:20.512270Z","iopub.status.idle":"2022-12-25T17:54:40.440127Z","shell.execute_reply.started":"2022-12-25T17:54:20.512214Z","shell.execute_reply":"2022-12-25T17:54:40.438988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Visualisation","metadata":{}},{"cell_type":"code","source":"def summary_report(data):\n  r, c = data.shape\n  t_sparce = 0\n  t_nunique = 0\n  for n in data.columns:\n    col = data[n]\n    sparce = round(round(col.isna().sum() / r, 2) * 100, 2)\n    nunique = col.nunique()\n\n    t_sparce = t_sparce + sparce\n    t_nunique = t_nunique + nunique\n\n    print(str(n) + \" is \" + str(sparce) + \"% empty. (\" + str(data[n].isna().sum()) + \" null values)\")\n    print(f\"The column has \" + str(nunique) + \" unique elements.\")\n    print(\"\\n\")\n\n  data.info()\n  print(f\"The shape of the dataset is \" + str(r) + \" rows and \" + str(c) + \" columns.\")\n  print(f\"The dataset is \" + str(round(t_sparce / c, 2)) + \"% sparse and contains \" + str(t_nunique) + \" unique elements.\" )","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:54:12.457752Z","iopub.execute_input":"2022-12-25T17:54:12.458173Z","iopub.status.idle":"2022-12-25T17:54:12.468559Z","shell.execute_reply.started":"2022-12-25T17:54:12.458141Z","shell.execute_reply":"2022-12-25T17:54:12.467491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:54:49.544421Z","iopub.execute_input":"2022-12-25T17:54:49.545230Z","iopub.status.idle":"2022-12-25T17:54:49.600746Z","shell.execute_reply.started":"2022-12-25T17:54:49.545183Z","shell.execute_reply":"2022-12-25T17:54:49.599559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:54:55.373448Z","iopub.execute_input":"2022-12-25T17:54:55.373873Z","iopub.status.idle":"2022-12-25T17:54:55.507491Z","shell.execute_reply.started":"2022-12-25T17:54:55.373840Z","shell.execute_reply":"2022-12-25T17:54:55.506329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"summary_report(train_data)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:54:57.836607Z","iopub.execute_input":"2022-12-25T17:54:57.837345Z","iopub.status.idle":"2022-12-25T17:55:03.102652Z","shell.execute_reply.started":"2022-12-25T17:54:57.837305Z","shell.execute_reply":"2022-12-25T17:55:03.101334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Cleaning","metadata":{}},{"cell_type":"code","source":"train_data = train_data.drop(['user_id','review_id','date_added','date_updated','read_at','started_at','n_votes','n_comments'], axis=1)\ntest_data_edit = test_data.drop(['date_added','date_updated','read_at','started_at','n_votes','n_comments'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T18:15:11.032063Z","iopub.execute_input":"2022-12-25T18:15:11.032961Z","iopub.status.idle":"2022-12-25T18:15:11.173507Z","shell.execute_reply.started":"2022-12-25T18:15:11.032919Z","shell.execute_reply":"2022-12-25T18:15:11.172244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_data_edit)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T18:15:15.324208Z","iopub.execute_input":"2022-12-25T18:15:15.325066Z","iopub.status.idle":"2022-12-25T18:15:15.334169Z","shell.execute_reply.started":"2022-12-25T18:15:15.325016Z","shell.execute_reply":"2022-12-25T18:15:15.331981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.rating.hist()","metadata":{"execution":{"iopub.status.busy":"2022-12-25T14:59:31.568912Z","iopub.execute_input":"2022-12-25T14:59:31.569399Z","iopub.status.idle":"2022-12-25T14:59:31.869381Z","shell.execute_reply.started":"2022-12-25T14:59:31.569356Z","shell.execute_reply":"2022-12-25T14:59:31.868070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# delete all rows with column 'rating' has value 0\nindex = train_data[ (train_data['rating'] == 0)].index\ntrain_data.drop(index , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:55:48.672350Z","iopub.execute_input":"2022-12-25T17:55:48.672771Z","iopub.status.idle":"2022-12-25T17:55:48.935946Z","shell.execute_reply.started":"2022-12-25T17:55:48.672739Z","shell.execute_reply":"2022-12-25T17:55:48.934957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Get the column containing the books\nbooks = train_data.book_id\nratings_count = dict()\nfor book in books:\n    # If we already have the book, just add 1 to their rating count\n    if book in ratings_count:\n        ratings_count[book] += 1\n    # Otherwise, set the books rating count to 1\n    else:\n        ratings_count[book] = 1","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:55:50.501146Z","iopub.execute_input":"2022-12-25T17:55:50.502302Z","iopub.status.idle":"2022-12-25T17:55:50.922158Z","shell.execute_reply.started":"2022-12-25T17:55:50.502223Z","shell.execute_reply":"2022-12-25T17:55:50.921044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(ratings_count.values())","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:55:58.053142Z","iopub.execute_input":"2022-12-25T17:55:58.053587Z","iopub.status.idle":"2022-12-25T17:56:00.875207Z","shell.execute_reply.started":"2022-12-25T17:55:58.053551Z","shell.execute_reply":"2022-12-25T17:56:00.874310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# We want our books to have listened at least 10 - 100 reviews\nlower = 10\nupper = 100\nremove_books = []\nfor book, num_ratings in ratings_count.items():\n    if num_ratings < lower or num_ratings > upper:\n        remove_books.append(book)\ntrain_data_edit = train_data.loc[~train_data.book_id.isin(remove_books)]","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:56:53.606204Z","iopub.execute_input":"2022-12-25T17:56:53.606843Z","iopub.status.idle":"2022-12-25T17:56:53.726913Z","shell.execute_reply.started":"2022-12-25T17:56:53.606809Z","shell.execute_reply":"2022-12-25T17:56:53.725711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"summary_report(train_data_edit)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:56:54.599162Z","iopub.execute_input":"2022-12-25T17:56:54.599647Z","iopub.status.idle":"2022-12-25T17:56:57.658221Z","shell.execute_reply.started":"2022-12-25T17:56:54.599609Z","shell.execute_reply":"2022-12-25T17:56:57.657342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Get the column containing the books\nbooks = train_data_edit.book_id\nratings_count_edit = dict()\nfor book in books:\n    # If we already have the book, just add 1 to their rating count\n    if book in ratings_count_edit:\n        ratings_count_edit[book] += 1\n    # Otherwise, set the books rating count to 1\n    else:\n        ratings_count_edit[book] = 1","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:57:04.567194Z","iopub.execute_input":"2022-12-25T17:57:04.567658Z","iopub.status.idle":"2022-12-25T17:57:04.791204Z","shell.execute_reply.started":"2022-12-25T17:57:04.567623Z","shell.execute_reply":"2022-12-25T17:57:04.789851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(ratings_count_edit.values())","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:57:06.749206Z","iopub.execute_input":"2022-12-25T17:57:06.749659Z","iopub.status.idle":"2022-12-25T17:57:07.144276Z","shell.execute_reply.started":"2022-12-25T17:57:06.749620Z","shell.execute_reply":"2022-12-25T17:57:07.143015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# NLTK","metadata":{}},{"cell_type":"code","source":"#importing nlp library\nimport nltk\n\nnltk.download('wordnet')\nnltk.download('omw-1.4')\nnltk.download('vader_lexicon')\n\n#Stop words present in the library\nimport pandas as pd\nimport nltk.corpus\nnltk.download('stopwords')\nfrom nltk.corpus import stopwords\nstop_words = stopwords.words('english')\n\n#library that contains punctuation\nimport string\n\n#importing the Stemming function from nltk library\nfrom nltk.stem.porter import PorterStemmer\n#defining the object for stemming\nporter_stemmer = PorterStemmer()\n\nfrom nltk.sentiment.vader import SentimentIntensityAnalyzer","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:57:13.743840Z","iopub.execute_input":"2022-12-25T17:57:13.744314Z","iopub.status.idle":"2022-12-25T17:57:14.120585Z","shell.execute_reply.started":"2022-12-25T17:57:13.744216Z","shell.execute_reply":"2022-12-25T17:57:14.119339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define the function to remove the punctuation\ndef remove_punctuations(text):\n    for punctuation in string.punctuation:\n        text = text.replace(punctuation, '')\n    return text","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:57:18.409405Z","iopub.execute_input":"2022-12-25T17:57:18.409796Z","iopub.status.idle":"2022-12-25T17:57:18.415049Z","shell.execute_reply.started":"2022-12-25T17:57:18.409765Z","shell.execute_reply":"2022-12-25T17:57:18.413918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def tokenize_data(text):\n    tokens=re.split('w+',text)\n    return tokens","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:57:18.859084Z","iopub.execute_input":"2022-12-25T17:57:18.859537Z","iopub.status.idle":"2022-12-25T17:57:18.865681Z","shell.execute_reply.started":"2022-12-25T17:57:18.859502Z","shell.execute_reply":"2022-12-25T17:57:18.864510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def stemmer(text):\n    data_steemer=[porter_stemmer.stem(word)for word in text]\n    return data_steemer","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:57:19.539978Z","iopub.execute_input":"2022-12-25T17:57:19.540731Z","iopub.status.idle":"2022-12-25T17:57:19.545703Z","shell.execute_reply.started":"2022-12-25T17:57:19.540691Z","shell.execute_reply":"2022-12-25T17:57:19.544445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_edit['review_text'] = train_data_edit['review_text'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stop_words)]))\ntrain_data_edit['review_text'] = train_data_edit['review_text'].apply(lambda x: x.lower())\ntrain_data_edit['review_text'] = train_data_edit['review_text'].replace(r'http\\S+', '', regex=True).replace(r'www\\S+', '', regex=True)\ntrain_data_edit['review_text'] = train_data_edit['review_text'].str.replace('\\d+', '')\ntrain_data_edit['review_text'] = train_data_edit['review_text'].apply(lambda x : remove_punctuations(x))\ntrain_data_edit['review_text'] = train_data_edit['review_text'].apply(lambda x : tokenize_data(x))\ntrain_data_edit['review_text'] = train_data_edit['review_text'].apply(lambda x : stemmer(x))\ntrain_data_edit['review_text'] = [','.join(map(str, l)) for l in train_data_edit['review_text']]","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:57:23.388190Z","iopub.execute_input":"2022-12-25T17:57:23.389069Z","iopub.status.idle":"2022-12-25T18:08:01.676759Z","shell.execute_reply.started":"2022-12-25T17:57:23.389025Z","shell.execute_reply":"2022-12-25T18:08:01.675306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data_edit['review_text'] = test_data_edit['review_text'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stop_words)]))\ntest_data_edit['review_text'] = test_data_edit['review_text'].apply(lambda x: x.lower())\ntest_data_edit['review_text'] = test_data_edit['review_text'].replace(r'http\\S+', '', regex=True).replace(r'www\\S+', '', regex=True)\ntest_data_edit['review_text'] = test_data_edit['review_text'].str.replace('\\d+', '')\ntest_data_edit['review_text'] = test_data_edit['review_text'].apply(lambda x : remove_punctuations(x))\ntest_data_edit['review_text'] = test_data_edit['review_text'].apply(lambda x : tokenize_data(x))\ntest_data_edit['review_text'] = test_data_edit['review_text'].apply(lambda x : stemmer(x))\ntest_data_edit['review_text'] = [','.join(map(str, l)) for l in test_data_edit['review_text']]","metadata":{"execution":{"iopub.status.busy":"2022-12-25T18:15:52.739608Z","iopub.execute_input":"2022-12-25T18:15:52.740004Z","iopub.status.idle":"2022-12-25T18:22:39.070822Z","shell.execute_reply.started":"2022-12-25T18:15:52.739973Z","shell.execute_reply":"2022-12-25T18:22:39.069522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"analyzer = SentimentIntensityAnalyzer()\ntrain_data_edit['neg'] = [analyzer.polarity_scores(x)['neg'] for x in train_data_edit['review_text']]\ntrain_data_edit['pos'] = [analyzer.polarity_scores(x)['pos'] for x in train_data_edit['review_text']]\ntrain_data_edit['neutral'] = [analyzer.polarity_scores(x)['neu'] for x in train_data_edit['review_text']]","metadata":{"execution":{"iopub.status.busy":"2022-12-25T18:23:23.566783Z","iopub.execute_input":"2022-12-25T18:23:23.567214Z","iopub.status.idle":"2022-12-25T19:08:13.491183Z","shell.execute_reply.started":"2022-12-25T18:23:23.567177Z","shell.execute_reply":"2022-12-25T19:08:13.490034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data_edit['neg'] = [analyzer.polarity_scores(x)['neg'] for x in test_data_edit['review_text']]\ntest_data_edit['pos'] = [analyzer.polarity_scores(x)['pos'] for x in test_data_edit['review_text']]\ntest_data_edit['neutral'] = [analyzer.polarity_scores(x)['neu'] for x in test_data_edit['review_text']]","metadata":{"execution":{"iopub.status.busy":"2022-12-25T19:16:45.313617Z","iopub.execute_input":"2022-12-25T19:16:45.314854Z","iopub.status.idle":"2022-12-25T20:00:07.374600Z","shell.execute_reply.started":"2022-12-25T19:16:45.314811Z","shell.execute_reply":"2022-12-25T20:00:07.373454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data_edit.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T20:05:17.181685Z","iopub.execute_input":"2022-12-25T20:05:17.184163Z","iopub.status.idle":"2022-12-25T20:05:17.224446Z","shell.execute_reply.started":"2022-12-25T20:05:17.184117Z","shell.execute_reply":"2022-12-25T20:05:17.223324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nfrom sklearn import svm\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn.metrics import classification_report\nfrom sklearn import tree","metadata":{"execution":{"iopub.status.busy":"2022-12-25T20:05:26.311284Z","iopub.execute_input":"2022-12-25T20:05:26.311957Z","iopub.status.idle":"2022-12-25T20:05:26.318026Z","shell.execute_reply.started":"2022-12-25T20:05:26.311909Z","shell.execute_reply":"2022-12-25T20:05:26.317115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Labels are the values we want to predict\nlabels = np.array(train_data_edit['rating'])\n\n# Remove the labels from the features\n# axis 1 refers to the columns\nfeatures = train_data_edit.drop(['review_id','rating','review_text','book_id','n_votes','n_comments'], axis = 1)\n# test_data_edit = test_data_edit.drop(['user_id','book_id','review_text'], axis=1)\n# Saving feature names for later use\nfeature_list = list(features.columns)\nfeatures.corr()","metadata":{"execution":{"iopub.status.busy":"2022-12-25T20:10:33.894190Z","iopub.execute_input":"2022-12-25T20:10:33.894954Z","iopub.status.idle":"2022-12-25T20:10:34.006195Z","shell.execute_reply.started":"2022-12-25T20:10:33.894917Z","shell.execute_reply":"2022-12-25T20:10:34.004985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features = np.array(features)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T20:09:21.985446Z","iopub.execute_input":"2022-12-25T20:09:21.986132Z","iopub.status.idle":"2022-12-25T20:09:22.288695Z","shell.execute_reply.started":"2022-12-25T20:09:21.986091Z","shell.execute_reply":"2022-12-25T20:09:22.287707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\n# Split the data into training and testing sets\ntrain_features, test_features, train_labels, test_labels = train_test_split(features, labels, test_size=.75, random_state=42)\n\nprint('Training Features Shape:', train_features.shape)\nprint('Training Labels Shape:', train_labels.shape)\nprint('Testing Features Shape:', test_features.shape)\nprint('Testing Labels Shape:', test_labels.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T20:09:25.120820Z","iopub.execute_input":"2022-12-25T20:09:25.121262Z","iopub.status.idle":"2022-12-25T20:09:25.669184Z","shell.execute_reply.started":"2022-12-25T20:09:25.121168Z","shell.execute_reply":"2022-12-25T20:09:25.668079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Random Forest","metadata":{}},{"cell_type":"code","source":"# Random Forest Classifier\n# rf = RandomForestClassifier(n_jobs=-1).fit(train_features, train_labels)\n# print(classification_report(test_labels,rf.predict(test_features)))\n\ntrain_features","metadata":{"execution":{"iopub.status.busy":"2022-12-25T20:11:16.183512Z","iopub.execute_input":"2022-12-25T20:11:16.183908Z","iopub.status.idle":"2022-12-25T20:11:16.190913Z","shell.execute_reply.started":"2022-12-25T20:11:16.183874Z","shell.execute_reply":"2022-12-25T20:11:16.189817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Naive Bayes","metadata":{}},{"cell_type":"code","source":"# Naive bayes\nmnb = MultinomialNB().fit(train_features, train_labels)\nprint(classification_report(test_labels,mnb.predict(test_features)))","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:02:20.494217Z","iopub.execute_input":"2022-12-25T17:02:20.494639Z","iopub.status.idle":"2022-12-25T17:02:21.208462Z","shell.execute_reply.started":"2022-12-25T17:02:20.494605Z","shell.execute_reply":"2022-12-25T17:02:21.207120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Decision Tree","metadata":{}},{"cell_type":"code","source":"# Decision Tree\ndt = tree.DecisionTreeClassifier(max_depth = 3, random_state = 42).fit(train_features, train_labels)\nprint(classification_report(test_labels,np.round(dt.predict(test_features))))","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:02:16.537874Z","iopub.execute_input":"2022-12-25T17:02:16.538321Z","iopub.status.idle":"2022-12-25T17:02:17.271584Z","shell.execute_reply.started":"2022-12-25T17:02:16.538286Z","shell.execute_reply":"2022-12-25T17:02:17.270495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rating = dt.predict(test_data_edit_final)\noutput = pd.DataFrame({'review_id': test_data_edit_final.review_id, 'rating': rating})\noutput.to_csv('submission.csv', index=False)\nprint(\"Your submission was successfully saved!\")","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:26:31.758206Z","iopub.execute_input":"2022-12-25T17:26:31.758702Z","iopub.status.idle":"2022-12-25T17:26:31.963545Z","shell.execute_reply.started":"2022-12-25T17:26:31.758669Z","shell.execute_reply":"2022-12-25T17:26:31.961709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(sample_data)","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:20:29.217152Z","iopub.execute_input":"2022-12-25T17:20:29.218027Z","iopub.status.idle":"2022-12-25T17:20:29.229048Z","shell.execute_reply.started":"2022-12-25T17:20:29.217974Z","shell.execute_reply":"2022-12-25T17:20:29.227759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_edit","metadata":{"execution":{"iopub.status.busy":"2022-12-25T17:37:15.677305Z","iopub.execute_input":"2022-12-25T17:37:15.677689Z","iopub.status.idle":"2022-12-25T17:37:15.699187Z","shell.execute_reply.started":"2022-12-25T17:37:15.677659Z","shell.execute_reply":"2022-12-25T17:37:15.697322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}