{"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":"markdown","source":"# **Imports**","metadata":{"id":"tXOm4z48mhPg"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport tensorflow as tf\nfrom tensorflow.keras import layers\nimport matplotlib.pyplot as plt\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.model_selection import train_test_split\nimport spacy as sps\nimport scipy","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","id":"zTKeO7j8ZPet","execution":{"iopub.status.busy":"2022-08-12T14:46:39.325261Z","iopub.execute_input":"2022-08-12T14:46:39.325796Z","iopub.status.idle":"2022-08-12T14:46:52.325028Z","shell.execute_reply.started":"2022-08-12T14:46:39.325690Z","shell.execute_reply":"2022-08-12T14:46:52.323535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from keras.backend import set_session\n# import tensorflow as tf\n# config = tf.ConfigProto()\n# config.gpu_options.allow_growth = True\n# sess = tf.Session(config=config)\n# set_session(sess)\n","metadata":{"id":"5rhNUC_ZZPex","outputId":"26693d58-1329-4308-92e4-e9fefb9fa6fc","execution":{"iopub.status.busy":"2022-08-12T14:46:52.327746Z","iopub.execute_input":"2022-08-12T14:46:52.328392Z","iopub.status.idle":"2022-08-12T14:46:52.334816Z","shell.execute_reply.started":"2022-08-12T14:46:52.328358Z","shell.execute_reply":"2022-08-12T14:46:52.332760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nlp_spacy = sps.load('en_core_web_sm')\ncount_ = CountVectorizer()","metadata":{"id":"QMZKiGgyZPey","execution":{"iopub.status.busy":"2022-08-12T14:46:52.336768Z","iopub.execute_input":"2022-08-12T14:46:52.338034Z","iopub.status.idle":"2022-08-12T14:46:53.297336Z","shell.execute_reply.started":"2022-08-12T14:46:52.337995Z","shell.execute_reply":"2022-08-12T14:46:53.295528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Preprocessing Function and EDA**","metadata":{"id":"oPkYHbVNZPey"}},{"cell_type":"code","source":"def text_preprocessing(data_sets):\n  \"\"\"\n  This function is used to preprocess the text, the data should be passed in the form of list.\n  function it performs: remove punctuation, stop words and numeric values.\n  input : list of text\n  output: refined words of text\n  \"\"\"\n  import re\n  nlp_spacy = sps.load('en_core_web_sm')\n  cleaned = []\n  for sentence in data_sets:\n    cln_sent = []\n    for token in nlp_spacy(sentence):\n      if token.is_punct or token.is_stop or token.is_digit:\n        pass\n      else:\n        cln_sent.append(str(token.lemma_))\n\n    sen = ' '.join(cln_sent)\n    result = re.sub('([0-9])+[a-z]+','', sen)\n    result = re.sub('\\W{2,}','', result)\n    cleaned.append(result)\n  return cleaned","metadata":{"id":"9MPYDNWZZPe0","execution":{"iopub.status.busy":"2022-08-12T14:46:53.299961Z","iopub.execute_input":"2022-08-12T14:46:53.300277Z","iopub.status.idle":"2022-08-12T14:46:53.309022Z","shell.execute_reply.started":"2022-08-12T14:46:53.300245Z","shell.execute_reply":"2022-08-12T14:46:53.307523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_path = '../input/feedback-prize-effectiveness'","metadata":{"id":"Gn_zTKIdZPe0","execution":{"iopub.status.busy":"2022-08-12T14:46:53.311788Z","iopub.execute_input":"2022-08-12T14:46:53.312758Z","iopub.status.idle":"2022-08-12T14:46:53.322334Z","shell.execute_reply.started":"2022-08-12T14:46:53.312720Z","shell.execute_reply":"2022-08-12T14:46:53.320848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(data_path+'/train.csv')\ntest_data = pd.read_csv(data_path+'/test.csv')","metadata":{"id":"CtqZQ3_KZPe1","execution":{"iopub.status.busy":"2022-08-12T14:46:53.325288Z","iopub.execute_input":"2022-08-12T14:46:53.325825Z","iopub.status.idle":"2022-08-12T14:46:53.667983Z","shell.execute_reply.started":"2022-08-12T14:46:53.325777Z","shell.execute_reply":"2022-08-12T14:46:53.666901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(5)","metadata":{"id":"WQLVppvLZPe1","outputId":"fea66cbf-97fa-4d2a-ed60-6135325d2209","execution":{"iopub.status.busy":"2022-08-12T14:46:53.669167Z","iopub.execute_input":"2022-08-12T14:46:53.669769Z","iopub.status.idle":"2022-08-12T14:46:53.693429Z","shell.execute_reply.started":"2022-08-12T14:46:53.669733Z","shell.execute_reply":"2022-08-12T14:46:53.691994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"id":"5caEUeRuZPe2","outputId":"cc7988f9-036d-4e27-a47e-86a34f64f411","execution":{"iopub.status.busy":"2022-08-12T14:46:53.695151Z","iopub.execute_input":"2022-08-12T14:46:53.695539Z","iopub.status.idle":"2022-08-12T14:46:53.719336Z","shell.execute_reply.started":"2022-08-12T14:46:53.695490Z","shell.execute_reply":"2022-08-12T14:46:53.717757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.discourse_effectiveness.value_counts()","metadata":{"id":"Mt73bdPaZPe2","outputId":"3d427e37-810d-4c3f-aa19-616f2086a294","execution":{"iopub.status.busy":"2022-08-12T14:46:53.721275Z","iopub.execute_input":"2022-08-12T14:46:53.722083Z","iopub.status.idle":"2022-08-12T14:46:53.741059Z","shell.execute_reply.started":"2022-08-12T14:46:53.722043Z","shell.execute_reply":"2022-08-12T14:46:53.739289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.discourse_effectiveness.value_counts()","metadata":{"id":"oj8t8RNdZPe3","outputId":"7397ee3b-132a-4305-cb13-4105c29be651","execution":{"iopub.status.busy":"2022-08-12T14:46:53.746084Z","iopub.execute_input":"2022-08-12T14:46:53.746806Z","iopub.status.idle":"2022-08-12T14:46:53.756328Z","shell.execute_reply.started":"2022-08-12T14:46:53.746758Z","shell.execute_reply":"2022-08-12T14:46:53.755331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.discourse_effectiveness.value_counts()/train_data.shape[0]*100","metadata":{"id":"zU4YOIRIZPe3","outputId":"92635856-a34d-4441-da34-e19ae626b338","execution":{"iopub.status.busy":"2022-08-12T14:46:53.757706Z","iopub.execute_input":"2022-08-12T14:46:53.758487Z","iopub.status.idle":"2022-08-12T14:46:53.778212Z","shell.execute_reply.started":"2022-08-12T14:46:53.758434Z","shell.execute_reply":"2022-08-12T14:46:53.776205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.discourse_effectiveness.replace({'Ineffective':0, 'Adequate':1, 'Effective':2}, inplace=True)","metadata":{"id":"tszDMLCaZPe3","execution":{"iopub.status.busy":"2022-08-12T14:46:53.780342Z","iopub.execute_input":"2022-08-12T14:46:53.780917Z","iopub.status.idle":"2022-08-12T14:46:53.804435Z","shell.execute_reply.started":"2022-08-12T14:46:53.780869Z","shell.execute_reply":"2022-08-12T14:46:53.803237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**It appears that the dataset is imbalanced, so we will make it balanced**","metadata":{"id":"PkCarCvuZPe3"}},{"cell_type":"code","source":"datafor_0 = train_data.loc[train_data.discourse_effectiveness==0,:]","metadata":{"id":"Tx_dYlGyZPe4","execution":{"iopub.status.busy":"2022-08-12T14:46:53.805935Z","iopub.execute_input":"2022-08-12T14:46:53.806756Z","iopub.status.idle":"2022-08-12T14:46:53.819162Z","shell.execute_reply.started":"2022-08-12T14:46:53.806683Z","shell.execute_reply":"2022-08-12T14:46:53.817766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datafor_0","metadata":{"id":"OYWiNC1xZPe4","outputId":"27b57b58-29c9-485a-ee57-f6a101268c6f","execution":{"iopub.status.busy":"2022-08-12T14:46:53.821392Z","iopub.execute_input":"2022-08-12T14:46:53.822441Z","iopub.status.idle":"2022-08-12T14:46:53.843162Z","shell.execute_reply.started":"2022-08-12T14:46:53.822392Z","shell.execute_reply":"2022-08-12T14:46:53.842062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datafor_2 = train_data.loc[train_data.discourse_effectiveness==2,:]","metadata":{"id":"Wc_xGqXcZPe4","execution":{"iopub.status.busy":"2022-08-12T14:46:53.845050Z","iopub.execute_input":"2022-08-12T14:46:53.845545Z","iopub.status.idle":"2022-08-12T14:46:53.855205Z","shell.execute_reply.started":"2022-08-12T14:46:53.845487Z","shell.execute_reply":"2022-08-12T14:46:53.853921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datafor_2","metadata":{"id":"NwMOc0rAZPe4","outputId":"40419fc9-e36f-45c1-ea08-f2928287faf0","execution":{"iopub.status.busy":"2022-08-12T14:46:53.856943Z","iopub.execute_input":"2022-08-12T14:46:53.857270Z","iopub.status.idle":"2022-08-12T14:46:53.881243Z","shell.execute_reply.started":"2022-08-12T14:46:53.857236Z","shell.execute_reply":"2022-08-12T14:46:53.879672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datafor_1 = train_data.loc[train_data.discourse_effectiveness==1,:]","metadata":{"id":"wWBj64mnZPe4","execution":{"iopub.status.busy":"2022-08-12T14:46:53.883803Z","iopub.execute_input":"2022-08-12T14:46:53.884172Z","iopub.status.idle":"2022-08-12T14:46:53.895393Z","shell.execute_reply.started":"2022-08-12T14:46:53.884139Z","shell.execute_reply":"2022-08-12T14:46:53.894383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced = pd.concat([datafor_1,datafor_2,datafor_2,datafor_0,datafor_0,datafor_0], axis=0)","metadata":{"id":"_yAV-vjrZPe4","execution":{"iopub.status.busy":"2022-08-12T14:46:53.896399Z","iopub.execute_input":"2022-08-12T14:46:53.896806Z","iopub.status.idle":"2022-08-12T14:46:53.910205Z","shell.execute_reply.started":"2022-08-12T14:46:53.896773Z","shell.execute_reply":"2022-08-12T14:46:53.909023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced","metadata":{"id":"XIr1lkBLZPe5","outputId":"7387143a-ef41-41ce-a8e1-42da1358fb0f","execution":{"iopub.status.busy":"2022-08-12T14:46:53.911201Z","iopub.execute_input":"2022-08-12T14:46:53.913154Z","iopub.status.idle":"2022-08-12T14:46:53.932989Z","shell.execute_reply.started":"2022-08-12T14:46:53.913109Z","shell.execute_reply":"2022-08-12T14:46:53.931397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(train_data_balanced.discourse_effectiveness.value_counts()/train_data_balanced.shape[0])* 100","metadata":{"id":"0wzu9crkZPe5","outputId":"c50e7d93-3c84-409b-cbe6-09f9dbaa7bd3","execution":{"iopub.status.busy":"2022-08-12T14:46:53.934990Z","iopub.execute_input":"2022-08-12T14:46:53.935350Z","iopub.status.idle":"2022-08-12T14:46:53.946655Z","shell.execute_reply.started":"2022-08-12T14:46:53.935317Z","shell.execute_reply":"2022-08-12T14:46:53.945208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced.reset_index(inplace=True)","metadata":{"id":"9CCNYnicZPe5","execution":{"iopub.status.busy":"2022-08-12T14:46:53.948255Z","iopub.execute_input":"2022-08-12T14:46:53.948806Z","iopub.status.idle":"2022-08-12T14:46:53.959604Z","shell.execute_reply.started":"2022-08-12T14:46:53.948759Z","shell.execute_reply":"2022-08-12T14:46:53.958302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced.drop('index', axis=1, inplace=True)","metadata":{"id":"jljT9lgSZPe5","execution":{"iopub.status.busy":"2022-08-12T14:46:53.961612Z","iopub.execute_input":"2022-08-12T14:46:53.962100Z","iopub.status.idle":"2022-08-12T14:46:53.978118Z","shell.execute_reply.started":"2022-08-12T14:46:53.962055Z","shell.execute_reply":"2022-08-12T14:46:53.976501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced","metadata":{"id":"8In3fpF0ZPe6","outputId":"ecd8ae09-6962-4260-dd49-967e8036f465","execution":{"iopub.status.busy":"2022-08-12T14:46:53.979275Z","iopub.execute_input":"2022-08-12T14:46:53.979794Z","iopub.status.idle":"2022-08-12T14:46:53.998379Z","shell.execute_reply.started":"2022-08-12T14:46:53.979751Z","shell.execute_reply":"2022-08-12T14:46:53.996969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**Pre Processing the Data**","metadata":{"id":"by8cFDwAm3m7"}},{"cell_type":"markdown","source":"\nSince the preprocessing is very time consuming, I saved the output list in a text file and access the file instead of preprocessing the data everytime I start a new runtime.","metadata":{"id":"33Y4SshXm-ys"}},{"cell_type":"code","source":"# %%time\n# output = text_preprocessing(train_data_balanced.discourse_text.to_list())","metadata":{"id":"DKrE815wZPe6","execution":{"iopub.status.busy":"2022-08-12T14:46:53.999522Z","iopub.execute_input":"2022-08-12T14:46:53.999861Z","iopub.status.idle":"2022-08-12T14:46:54.009431Z","shell.execute_reply.started":"2022-08-12T14:46:53.999829Z","shell.execute_reply":"2022-08-12T14:46:54.008132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# with open(r'sales.txt', 'w', encoding=\"utf-8\") as fp:\n#     for item in output:\n#         # write each item on a new line\n#         fp.write(\"%s\\n\" % item)\n#     print('Done')","metadata":{"id":"9GQHDCXGZPe6","execution":{"iopub.status.busy":"2022-08-12T14:46:54.011155Z","iopub.execute_input":"2022-08-12T14:46:54.011555Z","iopub.status.idle":"2022-08-12T14:46:54.021793Z","shell.execute_reply.started":"2022-08-12T14:46:54.011519Z","shell.execute_reply":"2022-08-12T14:46:54.020366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = []\nwith open(r'../input/salesfordataset/sales.txt', 'r') as fp:\n    for line in fp:\n        # remove linebreak from a current name\n        # linebreak is the last character of each line\n        x = line[:-1]\n\n        # add current item to the list\n        output.append(x)\n\n# display list\nprint(output[2000])","metadata":{"id":"KRWqPj1rZPe7","outputId":"08bb2790-429b-4b72-dd7c-fae2a82f4450","execution":{"iopub.status.busy":"2022-08-12T14:46:54.022964Z","iopub.execute_input":"2022-08-12T14:46:54.023320Z","iopub.status.idle":"2022-08-12T14:46:54.179913Z","shell.execute_reply.started":"2022-08-12T14:46:54.023270Z","shell.execute_reply":"2022-08-12T14:46:54.178562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced['cleaned_data'] = output","metadata":{"id":"pO9OF__rZPe7","execution":{"iopub.status.busy":"2022-08-12T14:46:54.181690Z","iopub.execute_input":"2022-08-12T14:46:54.182179Z","iopub.status.idle":"2022-08-12T14:46:54.193139Z","shell.execute_reply.started":"2022-08-12T14:46:54.182131Z","shell.execute_reply":"2022-08-12T14:46:54.191750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced['word_count'] = train_data_balanced.cleaned_data.apply(lambda x: len(x.split(' ')))","metadata":{"id":"yLfgPRCkZPe7","execution":{"iopub.status.busy":"2022-08-12T14:46:54.203870Z","iopub.execute_input":"2022-08-12T14:46:54.204312Z","iopub.status.idle":"2022-08-12T14:46:54.305417Z","shell.execute_reply.started":"2022-08-12T14:46:54.204277Z","shell.execute_reply":"2022-08-12T14:46:54.303988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced","metadata":{"id":"Yr0WAIklZPe7","outputId":"26a10453-134a-44d0-81b8-ef39a310d4e7","execution":{"iopub.status.busy":"2022-08-12T14:46:54.307850Z","iopub.execute_input":"2022-08-12T14:46:54.309005Z","iopub.status.idle":"2022-08-12T14:46:54.330982Z","shell.execute_reply.started":"2022-08-12T14:46:54.308954Z","shell.execute_reply":"2022-08-12T14:46:54.329788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced.discourse_text[200]","metadata":{"id":"IBlkwpeBZPe7","outputId":"01b76a9a-51a9-4808-ccb8-fbb7759c9ec7","execution":{"iopub.status.busy":"2022-08-12T14:46:54.332937Z","iopub.execute_input":"2022-08-12T14:46:54.333295Z","iopub.status.idle":"2022-08-12T14:46:54.345856Z","shell.execute_reply.started":"2022-08-12T14:46:54.333260Z","shell.execute_reply":"2022-08-12T14:46:54.344551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced.cleaned_data[200]","metadata":{"id":"3Wsnfe8nZPe7","outputId":"f9a8a26d-465a-4f8c-a7cb-c55f8063ae13","execution":{"iopub.status.busy":"2022-08-12T14:46:54.348745Z","iopub.execute_input":"2022-08-12T14:46:54.349689Z","iopub.status.idle":"2022-08-12T14:46:54.359228Z","shell.execute_reply.started":"2022-08-12T14:46:54.349639Z","shell.execute_reply":"2022-08-12T14:46:54.357835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Average Word Count for sentence is {}'.format(np.mean(train_data_balanced['word_count'])))","metadata":{"id":"M1fpvdqiZPe7","outputId":"87afb17c-a52d-418e-9989-419e6b356d7b","execution":{"iopub.status.busy":"2022-08-12T14:46:54.361386Z","iopub.execute_input":"2022-08-12T14:46:54.361831Z","iopub.status.idle":"2022-08-12T14:46:54.372425Z","shell.execute_reply.started":"2022-08-12T14:46:54.361788Z","shell.execute_reply":"2022-08-12T14:46:54.371372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Text Vectorization**\n\nThe features must be float and not string datatype in order for the model to process it.","metadata":{"id":"SlWVcvWynHfU"}},{"cell_type":"code","source":"np.max(train_data_balanced['word_count'])","metadata":{"id":"yBt8h7lJZPe8","outputId":"4173f686-46f0-4625-a9e6-6508174cc716","execution":{"iopub.status.busy":"2022-08-12T14:46:54.374071Z","iopub.execute_input":"2022-08-12T14:46:54.374417Z","iopub.status.idle":"2022-08-12T14:46:54.385915Z","shell.execute_reply.started":"2022-08-12T14:46:54.374385Z","shell.execute_reply":"2022-08-12T14:46:54.384834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.median(train_data_balanced['word_count'])","metadata":{"id":"4hkb0VEUZPe8","outputId":"3aabf2bb-c4b1-49ba-a45e-96ba01cd4e0b","execution":{"iopub.status.busy":"2022-08-12T14:46:54.388029Z","iopub.execute_input":"2022-08-12T14:46:54.388552Z","iopub.status.idle":"2022-08-12T14:46:54.404179Z","shell.execute_reply.started":"2022-08-12T14:46:54.388492Z","shell.execute_reply":"2022-08-12T14:46:54.402980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scipy.stats.mode(train_data_balanced['word_count'])","metadata":{"id":"z6ji-M_jZPe8","outputId":"81753af1-aab7-4ec7-af77-2f487e8dba54","execution":{"iopub.status.busy":"2022-08-12T14:46:54.406105Z","iopub.execute_input":"2022-08-12T14:46:54.406733Z","iopub.status.idle":"2022-08-12T14:46:54.419578Z","shell.execute_reply.started":"2022-08-12T14:46:54.406698Z","shell.execute_reply":"2022-08-12T14:46:54.417874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced['word_count'].value_counts()","metadata":{"id":"qUIipZWbZPe8","outputId":"41fd9062-3e58-447d-f341-adc129ab048d","execution":{"iopub.status.busy":"2022-08-12T14:46:54.421193Z","iopub.execute_input":"2022-08-12T14:46:54.421573Z","iopub.status.idle":"2022-08-12T14:46:54.432834Z","shell.execute_reply.started":"2022-08-12T14:46:54.421539Z","shell.execute_reply":"2022-08-12T14:46:54.431821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_.fit(train_data_balanced.cleaned_data)","metadata":{"id":"zwtsJpWnZPe8","outputId":"8fd7335d-3fea-4be8-a16c-85ce127fa325","execution":{"iopub.status.busy":"2022-08-12T14:46:54.434554Z","iopub.execute_input":"2022-08-12T14:46:54.434962Z","iopub.status.idle":"2022-08-12T14:46:55.697385Z","shell.execute_reply.started":"2022-08-12T14:46:54.434925Z","shell.execute_reply":"2022-08-12T14:46:55.695862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(count_.vocabulary_)","metadata":{"id":"J1kZqyPZZPe8","outputId":"fa3ca1fe-e4d3-4d14-fb93-7f56c2f8e46f","execution":{"iopub.status.busy":"2022-08-12T14:46:55.699272Z","iopub.execute_input":"2022-08-12T14:46:55.699683Z","iopub.status.idle":"2022-08-12T14:46:55.707347Z","shell.execute_reply.started":"2022-08-12T14:46:55.699649Z","shell.execute_reply":"2022-08-12T14:46:55.706001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vocabulary_training = 25000\nlength_of_sentence = 40","metadata":{"id":"XPtZIVzOZPe8","execution":{"iopub.status.busy":"2022-08-12T14:46:55.708745Z","iopub.execute_input":"2022-08-12T14:46:55.710085Z","iopub.status.idle":"2022-08-12T14:46:55.723186Z","shell.execute_reply.started":"2022-08-12T14:46:55.710050Z","shell.execute_reply":"2022-08-12T14:46:55.722228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"text_vectorizer = tf.keras.layers.TextVectorization(max_tokens=vocabulary_training,\n                                                   output_sequence_length=length_of_sentence,\n                                                   standardize='lower_and_strip_punctuation',\n                                                   output_mode='int')","metadata":{"id":"4q8EH9_KZPe8","execution":{"iopub.status.busy":"2022-08-12T14:46:55.725232Z","iopub.execute_input":"2022-08-12T14:46:55.726208Z","iopub.status.idle":"2022-08-12T14:46:55.804019Z","shell.execute_reply.started":"2022-08-12T14:46:55.726158Z","shell.execute_reply":"2022-08-12T14:46:55.802890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"text_vectorizer.adapt(train_data_balanced.cleaned_data)","metadata":{"id":"0CYH1vPYZPe9","execution":{"iopub.status.busy":"2022-08-12T14:46:55.805492Z","iopub.execute_input":"2022-08-12T14:46:55.806361Z","iopub.status.idle":"2022-08-12T14:46:57.822939Z","shell.execute_reply.started":"2022-08-12T14:46:55.806321Z","shell.execute_reply":"2022-08-12T14:46:57.821570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_balanced.cleaned_data[200]","metadata":{"id":"4-AxR3_bZPe9","outputId":"7a779e7a-b965-454d-dde2-e776af3ec37f","execution":{"iopub.status.busy":"2022-08-12T14:46:57.824385Z","iopub.execute_input":"2022-08-12T14:46:57.824805Z","iopub.status.idle":"2022-08-12T14:46:57.834360Z","shell.execute_reply.started":"2022-08-12T14:46:57.824721Z","shell.execute_reply":"2022-08-12T14:46:57.832884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"text_vectorizer(train_data_balanced.cleaned_data[200])","metadata":{"id":"RZIU4uEGZPe9","outputId":"db4fcc33-789f-4f77-b514-177e84a76701","execution":{"iopub.status.busy":"2022-08-12T14:46:57.835879Z","iopub.execute_input":"2022-08-12T14:46:57.836344Z","iopub.status.idle":"2022-08-12T14:46:57.918097Z","shell.execute_reply.started":"2022-08-12T14:46:57.836276Z","shell.execute_reply":"2022-08-12T14:46:57.916808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"text_embedding = tf.keras.layers.Embedding(mask_zero=True,\n                         input_dim=vocabulary_training,\n                         output_dim=64)","metadata":{"id":"NRgdNy_qZPe9","execution":{"iopub.status.busy":"2022-08-12T14:46:57.919203Z","iopub.execute_input":"2022-08-12T14:46:57.919539Z","iopub.status.idle":"2022-08-12T14:46:57.928846Z","shell.execute_reply.started":"2022-08-12T14:46:57.919507Z","shell.execute_reply":"2022-08-12T14:46:57.927151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"text_embedding(text_vectorizer(train_data_balanced.cleaned_data[100]))","metadata":{"id":"6YbJk14YZPe9","outputId":"7788d217-16aa-4ea7-c4bc-3b95a3ac3628","execution":{"iopub.status.busy":"2022-08-12T14:46:57.930691Z","iopub.execute_input":"2022-08-12T14:46:57.931030Z","iopub.status.idle":"2022-08-12T14:46:57.988065Z","shell.execute_reply.started":"2022-08-12T14:46:57.930998Z","shell.execute_reply":"2022-08-12T14:46:57.986660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y = tf.keras.utils.to_categorical(train_data_balanced.discourse_effectiveness)","metadata":{"id":"Hum9nmMFZPe9","execution":{"iopub.status.busy":"2022-08-12T14:46:57.989457Z","iopub.execute_input":"2022-08-12T14:46:57.989794Z","iopub.status.idle":"2022-08-12T14:46:57.996516Z","shell.execute_reply.started":"2022-08-12T14:46:57.989763Z","shell.execute_reply":"2022-08-12T14:46:57.995612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train_data_balanced.cleaned_data","metadata":{"id":"pTq9BBpFZPe-","execution":{"iopub.status.busy":"2022-08-12T14:46:57.997829Z","iopub.execute_input":"2022-08-12T14:46:57.998506Z","iopub.status.idle":"2022-08-12T14:46:58.008385Z","shell.execute_reply.started":"2022-08-12T14:46:57.998421Z","shell.execute_reply":"2022-08-12T14:46:58.007160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train, x_test, y_train, y_test= train_test_split(X, Y)","metadata":{"id":"MqgAM2K8ZPe-","execution":{"iopub.status.busy":"2022-08-12T14:46:58.010370Z","iopub.execute_input":"2022-08-12T14:46:58.011026Z","iopub.status.idle":"2022-08-12T14:46:58.034118Z","shell.execute_reply.started":"2022-08-12T14:46:58.010978Z","shell.execute_reply":"2022-08-12T14:46:58.032824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train","metadata":{"id":"mnWfxx1d8-pJ","outputId":"74ba89e3-1395-4101-fd09-6028cfad7fc9","execution":{"iopub.status.busy":"2022-08-12T14:46:58.035718Z","iopub.execute_input":"2022-08-12T14:46:58.036224Z","iopub.status.idle":"2022-08-12T14:46:58.047801Z","shell.execute_reply.started":"2022-08-12T14:46:58.036176Z","shell.execute_reply":"2022-08-12T14:46:58.046058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.sum(axis=0)/len(y_train)*100","metadata":{"id":"ZJH1K1JjZPe-","outputId":"470aa139-ba6c-44bf-d9e2-91f5ecf95099","execution":{"iopub.status.busy":"2022-08-12T14:46:58.050320Z","iopub.execute_input":"2022-08-12T14:46:58.051159Z","iopub.status.idle":"2022-08-12T14:46:58.063095Z","shell.execute_reply.started":"2022-08-12T14:46:58.051109Z","shell.execute_reply":"2022-08-12T14:46:58.061458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test.sum(axis=0)/len(y_test)*100","metadata":{"id":"0zwVaPzhZPe-","outputId":"8f511c69-a80b-4aa0-e8f7-d52a1f614e69","execution":{"iopub.status.busy":"2022-08-12T14:46:58.065152Z","iopub.execute_input":"2022-08-12T14:46:58.065569Z","iopub.status.idle":"2022-08-12T14:46:58.077089Z","shell.execute_reply.started":"2022-08-12T14:46:58.065529Z","shell.execute_reply":"2022-08-12T14:46:58.075414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))\ntesting_dataset = tf.data.Dataset.from_tensor_slices((x_test, y_test))","metadata":{"id":"DtNjuZ7KZPe-","execution":{"iopub.status.busy":"2022-08-12T14:46:58.078806Z","iopub.execute_input":"2022-08-12T14:46:58.079380Z","iopub.status.idle":"2022-08-12T14:46:58.114273Z","shell.execute_reply.started":"2022-08-12T14:46:58.079337Z","shell.execute_reply":"2022-08-12T14:46:58.112989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_dataset = training_dataset.batch(32).prefetch(tf.data.AUTOTUNE)\ntesting_dataset = testing_dataset.batch(32).prefetch(tf.data.AUTOTUNE)","metadata":{"id":"sxPUXxvUZPe_","execution":{"iopub.status.busy":"2022-08-12T14:46:58.115979Z","iopub.execute_input":"2022-08-12T14:46:58.116458Z","iopub.status.idle":"2022-08-12T14:46:58.126218Z","shell.execute_reply.started":"2022-08-12T14:46:58.116411Z","shell.execute_reply":"2022-08-12T14:46:58.125031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**A big problem I faced was when the input data 'x_train' has 3 dimensions but the labels 'y_train' had just 2 dimensions. In order to fix this, I wrote a function to convert 'x_train' into 2 dimensions.**","metadata":{"id":"tWpOMbwYnYTf"}},{"cell_type":"markdown","source":"**This function converts any string data into float datatype** ","metadata":{"id":"8l3Xc_E6n-yF"}},{"cell_type":"code","source":"\nfrom tensorflow.python.ops.numpy_ops import np_config\nnp_config.enable_numpy_behavior()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:46:58.128102Z","iopub.execute_input":"2022-08-12T14:46:58.128521Z","iopub.status.idle":"2022-08-12T14:46:58.137541Z","shell.execute_reply.started":"2022-08-12T14:46:58.128450Z","shell.execute_reply":"2022-08-12T14:46:58.136155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def embedder(data):\n  vectorizer_layer = text_vectorizer(data)\n  embedding_layer = text_embedding(vectorizer_layer)\n  nsamples, nx, ny = embedding_layer.shape\n  d2_train_dataset = embedding_layer.reshape((nsamples,nx*ny))\n  return d2_train_dataset","metadata":{"id":"iA9wva8fFSmJ","execution":{"iopub.status.busy":"2022-08-12T14:46:58.138924Z","iopub.execute_input":"2022-08-12T14:46:58.139388Z","iopub.status.idle":"2022-08-12T14:46:58.151146Z","shell.execute_reply.started":"2022-08-12T14:46:58.139344Z","shell.execute_reply":"2022-08-12T14:46:58.149812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = embedder(x_train)\nX_test = embedder(x_test)","metadata":{"id":"xtJAkgDgFrw_","execution":{"iopub.status.busy":"2022-08-12T14:46:58.152982Z","iopub.execute_input":"2022-08-12T14:46:58.153371Z","iopub.status.idle":"2022-08-12T14:46:58.869442Z","shell.execute_reply.started":"2022-08-12T14:46:58.153339Z","shell.execute_reply":"2022-08-12T14:46:58.868396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"id":"LtXAv3PlF4uU","outputId":"b411cde5-bb32-45e3-b522-6e8811f57cad","execution":{"iopub.status.busy":"2022-08-12T14:46:58.870443Z","iopub.execute_input":"2022-08-12T14:46:58.870831Z","iopub.status.idle":"2022-08-12T14:46:58.878384Z","shell.execute_reply.started":"2022-08-12T14:46:58.870797Z","shell.execute_reply":"2022-08-12T14:46:58.877155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.shape","metadata":{"id":"4N3qHjmfF-tP","outputId":"af10a151-959d-4ba5-ad7d-b83a70599fbb","execution":{"iopub.status.busy":"2022-08-12T14:46:58.879907Z","iopub.execute_input":"2022-08-12T14:46:58.880517Z","iopub.status.idle":"2022-08-12T14:46:58.892420Z","shell.execute_reply.started":"2022-08-12T14:46:58.880443Z","shell.execute_reply":"2022-08-12T14:46:58.891016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Predictive Modelling**\n\nThis function trains our data on different important models and their accuracies","metadata":{"id":"RGTqx-o0oqX9"}},{"cell_type":"code","source":"from sklearn.model_selection import KFold\nfrom sklearn.model_selection import cross_val_score\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.linear_model import Lasso\nfrom sklearn.linear_model import ElasticNet\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.neighbors import KNeighborsRegressor\nfrom sklearn.ensemble import GradientBoostingRegressor\nfrom sklearn.ensemble import RandomForestRegressor","metadata":{"id":"3up1jzhcq96K","execution":{"iopub.status.busy":"2022-08-12T14:46:58.894059Z","iopub.execute_input":"2022-08-12T14:46:58.894807Z","iopub.status.idle":"2022-08-12T14:46:59.133566Z","shell.execute_reply.started":"2022-08-12T14:46:58.894768Z","shell.execute_reply":"2022-08-12T14:46:59.131673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_x = X_train[1000:]\npred_y = y_train[1000:]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:46:59.135678Z","iopub.execute_input":"2022-08-12T14:46:59.136530Z","iopub.status.idle":"2022-08-12T14:46:59.144687Z","shell.execute_reply.started":"2022-08-12T14:46:59.136456Z","shell.execute_reply":"2022-08-12T14:46:59.143022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import StandardScaler\nmy_pipeline = Pipeline([\n    ('std_scaler', StandardScaler()),\n])\npipelines = []\npipelines.append(('ScaledLR', Pipeline([('Scaler', StandardScaler()),('LR',LinearRegression())])))\npipelines.append(('ScaledLASSO', Pipeline([('Scaler', StandardScaler()),('LASSO', Lasso())])))\npipelines.append(('ScaledEN', Pipeline([('Scaler', StandardScaler()),('EN', ElasticNet())])))\npipelines.append(('ScaledKNN', Pipeline([('Scaler', StandardScaler()),('KNN', KNeighborsRegressor())])))\npipelines.append(('ScaledCART', Pipeline([('Scaler', StandardScaler()),('CART', DecisionTreeRegressor())])))\n# pipelines.append(('ScaledGBM', Pipeline([('Scaler', StandardScaler()),('GBM', GradientBoostingRegressor())])))\n# pipelines.append(('ScaledRDF', Pipeline([('Scaler', StandardScaler()),('RDF', RandomForestRegressor())])))\n\nresults = []\nnames = []\nfor name, model in pipelines:\n    kfold = KFold(n_splits=10)\n    cv_results = cross_val_score(model, X_train, y_train, scoring=\"neg_mean_squared_error\", cv=10)\n    results.append(cv_results)\n    names.append(name)\n    msg = \"%s: %f (%f)\" % (name, cv_results.mean(), cv_results.std())\n    print(msg)","metadata":{"id":"mGKilYJjrBsY","outputId":"dbc06e84-32de-4976-b471-61f9b7f34f49","execution":{"iopub.status.busy":"2022-08-12T14:46:59.147460Z","iopub.execute_input":"2022-08-12T14:46:59.148732Z","iopub.status.idle":"2022-08-12T15:12:43.743660Z","shell.execute_reply.started":"2022-08-12T14:46:59.148680Z","shell.execute_reply":"2022-08-12T15:12:43.741844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**You can also do the process for just 1,000 rows of the dataset for faster results but I took the entire data for higher precision.**\n","metadata":{"id":"cR8xvVmio7aq"}},{"cell_type":"markdown","source":"**Since Random Forest and GBM failed for some reason, I will simply implement them seperately**","metadata":{}},{"cell_type":"markdown","source":"# **Random Forest**","metadata":{"id":"3Fv79K1YqFeo"}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier as RFC\nfrom sklearn.metrics import accuracy_score\nrfc_b = RFC()\nrfc_b.fit(X_train,y_train)\ny_pred = rfc_b.predict(X_train)\nprint('Train accuracy score:',accuracy_score(y_train,y_pred))\nprint('Test accuracy score:', accuracy_score(y_test,rfc_b.predict(X_test)))","metadata":{"id":"a-7Or4H9Dq0j","outputId":"9f3e9b22-e087-4fe2-dbe9-10e702a7e7ca","execution":{"iopub.status.busy":"2022-08-12T15:12:43.747964Z","iopub.execute_input":"2022-08-12T15:12:43.748433Z","iopub.status.idle":"2022-08-12T15:15:46.655135Z","shell.execute_reply.started":"2022-08-12T15:12:43.748397Z","shell.execute_reply":"2022-08-12T15:15:46.653559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**K-fold validation score**","metadata":{"id":"OtplGswqpJYG"}},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nscore=cross_val_score(rfc_b, X_train, y_train)","metadata":{"id":"pUfvoLEBApuA","execution":{"iopub.status.busy":"2022-08-12T15:15:46.657806Z","iopub.execute_input":"2022-08-12T15:15:46.658392Z","iopub.status.idle":"2022-08-12T15:28:37.031757Z","shell.execute_reply.started":"2022-08-12T15:15:46.658341Z","shell.execute_reply":"2022-08-12T15:28:37.030261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score","metadata":{"id":"G-9lheL6EkeS","outputId":"cf7bdbb5-d7b2-4485-c3c3-7fcbefdd34e8","execution":{"iopub.status.busy":"2022-08-12T15:28:37.034036Z","iopub.execute_input":"2022-08-12T15:28:37.034558Z","iopub.status.idle":"2022-08-12T15:28:37.044057Z","shell.execute_reply.started":"2022-08-12T15:28:37.034507Z","shell.execute_reply":"2022-08-12T15:28:37.042664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score.mean()","metadata":{"id":"J9OFAd0CEoAL","outputId":"c82ac895-a694-4b06-94b7-6d52873b03a3","execution":{"iopub.status.busy":"2022-08-12T15:28:37.046214Z","iopub.execute_input":"2022-08-12T15:28:37.047717Z","iopub.status.idle":"2022-08-12T15:28:37.057527Z","shell.execute_reply.started":"2022-08-12T15:28:37.047678Z","shell.execute_reply":"2022-08-12T15:28:37.056533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Rmse**","metadata":{"id":"we1t3QQUpcAc"}},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error\nimport numpy as np\nmodel = rfc_b\npredictions = model.predict(X_train)\nmse = mean_squared_error(y_train, y_pred)\nrmse = np.sqrt(mse)","metadata":{"id":"vi0SVTAVPCCu","execution":{"iopub.status.busy":"2022-08-12T15:28:37.059502Z","iopub.execute_input":"2022-08-12T15:28:37.060246Z","iopub.status.idle":"2022-08-12T15:28:41.009204Z","shell.execute_reply.started":"2022-08-12T15:28:37.060211Z","shell.execute_reply":"2022-08-12T15:28:41.007548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rmse","metadata":{"id":"9se3Ikc6Pg5w","outputId":"252cad54-dcd1-4cbb-ff62-cc0d6ef62501","execution":{"iopub.status.busy":"2022-08-12T15:28:41.010969Z","iopub.execute_input":"2022-08-12T15:28:41.011366Z","iopub.status.idle":"2022-08-12T15:28:41.021215Z","shell.execute_reply.started":"2022-08-12T15:28:41.011332Z","shell.execute_reply":"2022-08-12T15:28:41.019739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**XGBoost**","metadata":{"id":"jHAa6eRUpQ4r"}},{"cell_type":"code","source":"# import xgboost as xgb\n# xg_train = xgb.DMatrix(X_train, label=y_train)\n# xg_test = xgb.DMatrix(X_test, label=y_test)\n# xg_train.save_binary('train.buffer')\n# xg_test.save_binary('train.buffer')\n# # setup parameters for xgboost\n# param = {}\n# # use softmax multi-class classification\n# param['objective'] = 'multi:softmax'\n# param['silent'] = 1 # cleans up the output\n# param['num_class'] = 3 # number of classes in target label\n# watchlist = [(xg_train, 'train'), (xg_test, 'test')]\n# num_round = 30\n# bst = xgb.train(param, xg_train, num_round, watchlist)","metadata":{"id":"jqV1eMOW8A_C","outputId":"fdcb416b-825e-448b-f68a-1e5d9dfd0e3d","execution":{"iopub.status.busy":"2022-08-12T15:28:41.022950Z","iopub.execute_input":"2022-08-12T15:28:41.023338Z","iopub.status.idle":"2022-08-12T15:28:41.028741Z","shell.execute_reply.started":"2022-08-12T15:28:41.023304Z","shell.execute_reply":"2022-08-12T15:28:41.027642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Please note that this code snippet works on any other platform but kaggle does not support it, hence is unresolved.\nFor more information: https://github.com/dmlc/xgboost/issues/2087\nHowever, this model could not yet outstand against most of the other models and could not be considered with our current data.","metadata":{}},{"cell_type":"code","source":"# y_pred1 = bst.predict(xg_train)\n# y_pred2 = bst.predict(xg_test)","metadata":{"id":"F0N8gKor-K2W","execution":{"iopub.status.busy":"2022-08-12T15:28:41.030553Z","iopub.execute_input":"2022-08-12T15:28:41.031226Z","iopub.status.idle":"2022-08-12T15:28:41.044484Z","shell.execute_reply.started":"2022-08-12T15:28:41.031181Z","shell.execute_reply":"2022-08-12T15:28:41.043282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import numpy as np\n# rounded_labels=np.argmax(y_train, axis=1)\n# rounded_labels[1]","metadata":{"id":"YP7x9_7h_ceV","outputId":"d582ad4a-ccd8-4a9d-c7db-897584848fb8","execution":{"iopub.status.busy":"2022-08-12T15:28:41.046329Z","iopub.execute_input":"2022-08-12T15:28:41.046715Z","iopub.status.idle":"2022-08-12T15:28:41.055380Z","shell.execute_reply.started":"2022-08-12T15:28:41.046672Z","shell.execute_reply":"2022-08-12T15:28:41.054106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import numpy as np\n# Y_test=np.argmax(y_test, axis=1)\n# Y_test[1]","metadata":{"id":"PgKjvKlUAKcM","outputId":"ad1de916-31a2-49e6-81b2-85c148653e9f","execution":{"iopub.status.busy":"2022-08-12T15:28:41.057364Z","iopub.execute_input":"2022-08-12T15:28:41.058742Z","iopub.status.idle":"2022-08-12T15:28:41.068536Z","shell.execute_reply.started":"2022-08-12T15:28:41.058701Z","shell.execute_reply":"2022-08-12T15:28:41.067432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# print('Train accuracy score:',accuracy_score(rounded_labels,y_pred1))\n# print('Test accuracy score:',accuracy_score(Y_test,bst.predict(xg_test)))","metadata":{"id":"TxWV5DtS-5VT","outputId":"fd980772-fc54-41d4-d13a-3c8e3b376b87","execution":{"iopub.status.busy":"2022-08-12T15:28:41.070934Z","iopub.execute_input":"2022-08-12T15:28:41.071388Z","iopub.status.idle":"2022-08-12T15:28:41.081923Z","shell.execute_reply.started":"2022-08-12T15:28:41.071351Z","shell.execute_reply":"2022-08-12T15:28:41.080659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from joblib import dump, load\ndump(model, 'model.joblib') ","metadata":{"id":"8OJxcbvpPw4q","outputId":"87d2ea7d-5f46-470d-9e31-4cb319f62187","execution":{"iopub.status.busy":"2022-08-12T15:28:41.083707Z","iopub.execute_input":"2022-08-12T15:28:41.084029Z","iopub.status.idle":"2022-08-12T15:28:41.497490Z","shell.execute_reply.started":"2022-08-12T15:28:41.083998Z","shell.execute_reply":"2022-08-12T15:28:41.495961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#**Clearly, Random Decision Forest is a winner here. Now, we use it on our test data**","metadata":{"id":"80DD2u11pt15"}},{"cell_type":"code","source":"# X_test = embedder(x_test)\nmodel = rfc_b\nfinal_predictions = model.predict(X_test)\nfinal_mse = mean_squared_error(y_test, final_predictions)\nfinal_rmse = np.sqrt(final_mse)\nprint(final_predictions, list(y_test[:10]))","metadata":{"id":"rg591y3lP8ls","outputId":"0cd17a43-42ea-4195-9be7-58c3dc14b77e","execution":{"iopub.status.busy":"2022-08-12T15:28:41.500609Z","iopub.execute_input":"2022-08-12T15:28:41.500988Z","iopub.status.idle":"2022-08-12T15:28:42.891496Z","shell.execute_reply.started":"2022-08-12T15:28:41.500955Z","shell.execute_reply":"2022-08-12T15:28:42.890220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_rmse","metadata":{"id":"rRoIy6dXQbNF","outputId":"f88e775f-b889-445c-8bef-30fc16913fb1","execution":{"iopub.status.busy":"2022-08-12T15:28:42.894780Z","iopub.execute_input":"2022-08-12T15:28:42.895151Z","iopub.status.idle":"2022-08-12T15:28:42.904003Z","shell.execute_reply.started":"2022-08-12T15:28:42.895117Z","shell.execute_reply":"2022-08-12T15:28:42.902422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_predictions","metadata":{"id":"_K6oYhLWQr4M","outputId":"d9243b33-6f2b-4368-acb6-fdfa77459a42","execution":{"iopub.status.busy":"2022-08-12T15:28:42.905747Z","iopub.execute_input":"2022-08-12T15:28:42.906158Z","iopub.status.idle":"2022-08-12T15:28:42.917518Z","shell.execute_reply.started":"2022-08-12T15:28:42.906125Z","shell.execute_reply":"2022-08-12T15:28:42.916172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Submission**","metadata":{"id":"D-pZVfiAp9ig"}},{"cell_type":"code","source":"submission = pd.read_csv(\"../input/feedback-prize-effectiveness/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-12T15:28:42.918535Z","iopub.execute_input":"2022-08-12T15:28:42.918840Z","iopub.status.idle":"2022-08-12T15:28:42.949030Z","shell.execute_reply.started":"2022-08-12T15:28:42.918808Z","shell.execute_reply":"2022-08-12T15:28:42.947831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"id":"woUAr1Y3SBBL","outputId":"be983f67-74c5-4b0a-a33d-9b2667bf27c9","execution":{"iopub.status.busy":"2022-08-12T15:28:42.950920Z","iopub.execute_input":"2022-08-12T15:28:42.951279Z","iopub.status.idle":"2022-08-12T15:28:42.971711Z","shell.execute_reply.started":"2022-08-12T15:28:42.951247Z","shell.execute_reply":"2022-08-12T15:28:42.970080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i=0\nwhile i<10:\n  submission['Ineffective'][i]=final_predictions[i][0]\n  submission['Adequate'][i]=final_predictions[i][1]\n  submission['Effective'][i]=final_predictions[i][2]\n  i=i+1","metadata":{"id":"pl0zHMV6S-Mf","outputId":"0a897e50-67cf-49db-b6d1-f1fdf8defb67","execution":{"iopub.status.busy":"2022-08-12T15:28:42.974306Z","iopub.execute_input":"2022-08-12T15:28:42.974946Z","iopub.status.idle":"2022-08-12T15:28:42.998425Z","shell.execute_reply.started":"2022-08-12T15:28:42.974897Z","shell.execute_reply":"2022-08-12T15:28:42.996992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"id":"DP9dKV_pTjjy","outputId":"02b7fc89-2529-4666-8f89-eee1cd6c5d8e","execution":{"iopub.status.busy":"2022-08-12T15:28:43.000460Z","iopub.execute_input":"2022-08-12T15:28:43.000996Z","iopub.status.idle":"2022-08-12T15:28:43.017731Z","shell.execute_reply.started":"2022-08-12T15:28:43.000946Z","shell.execute_reply":"2022-08-12T15:28:43.016574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","metadata":{"id":"6BOTPOboZPfB","execution":{"iopub.status.busy":"2022-08-12T15:28:43.019374Z","iopub.execute_input":"2022-08-12T15:28:43.019739Z","iopub.status.idle":"2022-08-12T15:28:43.037304Z","shell.execute_reply.started":"2022-08-12T15:28:43.019706Z","shell.execute_reply":"2022-08-12T15:28:43.035811Z"},"trusted":true},"execution_count":null,"outputs":[]}]}