{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import zipfile\nimport pandas as pd\nimport numpy as np\nimport operator \nimport re\nimport gc\nfrom keras import layers\nimport os\nimport keras\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom tensorflow.keras.preprocessing.text import Tokenizer\nfrom tensorflow.keras.preprocessing.sequence import pad_sequences\nfrom sklearn.model_selection import train_test_split\nfrom keras.models import Model\nfrom tensorflow.keras.models import Sequential\nfrom keras.layers import Dense, Embedding, Bidirectional, concatenate, Input, Dropout\nfrom tensorflow.keras.layers import Input, Embedding, Bidirectional, LSTM, Dense,Flatten,Conv2D,Conv1D,GlobalMaxPooling1D,Concatenate, TimeDistributed\nfrom keras.optimizers import Adam\nfrom keras import optimizers, callbacks \nfrom sklearn.metrics import log_loss,f1_score\n\nfor dirname, _, filenames in os.walk('/kaggle'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/quora-insincere-questions-classification/train.csv\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"with zipfile.ZipFile(\"../input/quora-insincere-questions-classification/embeddings.zip\",\"r\") as z:\n    z.extractall(\".\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Function for extracting embeddings files"},{"metadata":{"trusted":true},"cell_type":"code","source":"def load_embed(file):\n    def get_coefs(word,*arr): \n        return word, np.asarray(arr, dtype='float32')\n    embeddings_index = dict(get_coefs(*o.split(\" \")) for o in open(file, encoding='latin'))\n    return embeddings_index","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"glove = './glove.840B.300d/glove.840B.300d.txt'\nembed_glove = load_embed(glove)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Building the vocabulary of our dataset**"},{"metadata":{"trusted":true},"cell_type":"code","source":"def build_vocab(texts):\n    sentences = texts.apply(lambda x: x.split()).values\n    vocab = {}\n    for sentence in sentences:\n        for word in sentence:\n            try:\n                vocab[word] += 1\n            except KeyError:\n                vocab[word] = 1\n    return vocab\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Checking the coverage of embeddings to our vocabulary**"},{"metadata":{"trusted":true},"cell_type":"code","source":"def check_coverage(vocab, embeddings_index):\n    known_words = {}\n    unknown_words = {}\n    nb_known_words = 0\n    nb_unknown_words = 0\n    for word in vocab.keys():\n        try:\n            known_words[word] = embeddings_index[word]\n            nb_known_words += vocab[word]\n        except:\n            unknown_words[word] = vocab[word]\n            nb_unknown_words += vocab[word]\n            pass\n\n    print('Found embeddings for {:.3%} of vocab'.format(len(known_words) / len(vocab)))\n    print('Found embeddings for  {:.3%} of all text'.format(nb_known_words / (nb_known_words + nb_unknown_words)))\n    unknown_words = sorted(unknown_words.items(), key=operator.itemgetter(1))[::-1]\n\n    return unknown_words\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1 - Checking the coverage without any modifcation to data"},{"metadata":{"trusted":true},"cell_type":"code","source":"vocabulary = build_vocab(train_df['question_text'])\nuncovered = check_coverage(vocabulary,embed_glove)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"uncovered[:10]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1-1 words with ponctuation"},{"metadata":{"trusted":true},"cell_type":"code","source":"puncts = [',', '.', '\"', ':', ')', '(', '-', '!', '?', '|', ';', \n          \"'\",  '&', '/', '[', ']', '>', '<', '%', '=', '#', '+', \n          '\\\\',  '§', '″', '′','¿','═']\n\n\ndef preprocessing1(text):\n    text = text.lower()\n    for punct in puncts:\n        text = text.replace(punct, f' {punct} ')\n    return text\n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.question_text = train_df.question_text.apply(preprocessing1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"vocabulary = build_vocab(train_df['question_text'])\nuncovered = check_coverage(vocabulary,embed_glove)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"uncovered[:10]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1-2 Contraction words"},{"metadata":{"trusted":true},"cell_type":"code","source":"contraction_map = {\"ain't\": \"is not\", \"aren't\": \"are not\",\"can't\": \"cannot\", \"'cause\": \"because\",\n                    \"could've\": \"could have\", \"couldn't\": \"could not\", \"didn't\": \"did not\", \n                   \"doesn't\": \"does not\", \"don't\": \"do not\", \"hadn't\": \"had not\", \n                   \"hasn't\": \"has not\", \"haven't\": \"have not\", \"he'd\": \"he would\",\"he'll\": \"he will\",\n                   \"he's\": \"he is\", \"how'd\": \"how did\", \"how'd'y\": \"how do you\", \"how'll\": \"how will\",\n                   \"how's\": \"how is\",  \"I'd\": \"I would\", \"I'd've\": \"I would have\", \"I'll\": \"I will\", \n                   \"I'll've\": \"I will have\",\"I'm\": \"I am\", \"I've\": \"I have\", \"i'd\": \"i would\", \n                    \"i'd've\": \"i would have\", \"i'll\": \"i will\",  \"i'll've\": \"i will have\",\"i'm\": \"i am\",\n                   \"i've\": \"i have\", \"isn't\": \"is not\", \"it'd\": \"it would\", \"it'd've\": \"it would have\",\n                   \"it'll\": \"it will\", \"it'll've\": \"it will have\",\"it's\": \"it is\", \"let's\": \"let us\", \n                   \"ma'am\": \"madam\", \"mayn't\": \"may not\", \"might've\": \"might have\",\n                   \"mightn't\": \"might not\",\"mightn't've\": \"might not have\", \"must've\": \"must have\",\n                   \"mustn't\": \"must not\", \"mustn't've\": \"must not have\", \"needn't\": \"need not\",\n                    \"needn't've\": \"need not have\",\"o'clock\": \"of the clock\", \"oughtn't\": \"ought not\",\n                   \"oughtn't've\": \"ought not have\", \"shan't\": \"shall not\", \"sha'n't\": \"shall not\",\n                   \"shan't've\": \"shall not have\", \"she'd\": \"she would\", \"she'd've\": \"she would have\",\n                   \"she'll\": \"she will\", \"she'll've\": \"she will have\", \"she's\": \"she is\", \"should've\":\n                   \"should have\", \"shouldn't\": \"should not\", \"shouldn't've\": \"should not have\", \n                   \"so've\": \"so have\",\"so's\": \"so as\", \"this's\": \"this is\",\"that'd\": \"that would\",                        \n                   \"that'd've\": \"that would have\", \"that's\": \"that is\", \"there'd\": \"there would\", \n                    \"there'd've\": \"there would have\", \"there's\": \"there is\", \"here's\": \"here is\",\n                   \"they'd\": \"they would\", \"they'd've\": \"they would have\", \"they'll\": \"they will\", \n                   \"they'll've\": \"they will have\", \"they're\": \"they are\", \"they've\": \"they have\",\n                   \"to've\": \"to have\", \"wasn't\": \"was not\", \"we'd\": \"we would\", \n                   \"we'd've\": \"we would have\", \"we'll\": \"we will\", \"we'll've\": \"we will have\", \n                   \"we're\": \"we are\", \"we've\": \"we have\", \"weren't\": \"were not\",                       \n                   \"what'll\": \"what will\", \"what'll've\": \"what will have\", \"what're\": \"what are\",\n                    \"what's\": \"what is\", \"what've\": \"what have\", \"when's\": \"when is\", \n                   \"when've\": \"when have\", \"where'd\": \"where did\", \"where's\": \"where is\", \n                   \"where've\": \"where have\", \"who'll\": \"who will\", \"who'll've\": \"who will have\", \n                   \"who's\": \"who is\", \"who've\": \"who have\", \"why's\": \"why is\", \"why've\": \"why have\",\n                   \"will've\": \"will have\", \"won't\": \"will not\", \"won't've\": \"will not have\",\n                   \"would've\": \"would have\", \"wouldn't\": \"would not\", \"wouldn't've\": \"would not have\",\n                    \"y'all\": \"you all\", \"y'all'd\": \"you all would\",\"y'all'd've\": \"you all would have\",\n                   \"y'all're\": \"you all are\",\"y'all've\": \"you all have\",\"you'd\": \"you would\",\n                   \"you'd've\": \"you would have\", \"you'll\": \"you will\", \"you'll've\": \"you will have\",\n                   \"you're\": \"you are\", \"you've\": \"you have\" }\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def preprocessing2(text, mapping):\n    specials = [\"’\", \"‘\", \"´\", \"`\"]\n    for s in specials:\n        text = text.replace(s, \"'\")\n    text = ' '.join([mapping[t] if t in mapping else t for t in text.split(\" \")])\n    return text","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.question_text = train_df.question_text.apply(lambda x: preprocessing2(x, contraction_map))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"vocabulary = build_vocab(train_df['question_text'])\nuncovered = check_coverage(vocabulary,embed_glove)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"uncovered[0:20]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1-3 special characters & espace around ponctuation"},{"metadata":{"trusted":true},"cell_type":"code","source":"special_map = {\"‘\": \"'\", \"₹\": \"e\", \"´\": \"'\", \"°\": \"\", \"€\": \"e\", \"™\": \"tm\", \"√\": \" sqrt \", \"×\": \"x\",\n               \"²\": \"2\", \"—\": \"-\", \"–\": \"-\", \"’\": \"'\", \"_\": \"-\", \"`\": \"'\", '“': '\"', '”': '\"', '“': '\"',\n               \"£\": \"e\", '∞': 'infinity', 'θ': 'theta', '÷': '/', 'α': 'alpha', '•': '.', 'à': 'a',\n               '−': '-', 'β': 'beta', '∅': '', '³': '3', 'π': 'pi','\\u200b': ' ', '…': ' ... ', '\\ufeff': '',\n               'करना': '', 'है': '' }\npunct = \"/-'?!.,#$%\\'()*+-/:;<=>@[\\\\]^_`{|}~\" + '\"\"“”’' + '∞θ÷α•à−β∅³π‘₹´°£€\\×™√²—–&'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def preprocessing3(text, punct, mapping):\n    for p in mapping:\n        text = text.replace(p, mapping[p])  \n    for p in punct:\n        text = text.replace(p, f' {p} ')   \n    return text","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.question_text = train_df.question_text.apply(lambda x: preprocessing3(x, punct, special_map))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"vocabulary = build_vocab(train_df['question_text'])\nuncovered = check_coverage(vocabulary,embed_glove)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"uncovered[:100]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1-3 miss spelling words"},{"metadata":{"trusted":true},"cell_type":"code","source":"mispell_dict = {'pubg':'video game','fortnite':'video game','redmi':'phone mark','brexit':'britain exit',\n                'cryptocurrencies':'crypto currencies','pokémon':'video game','laravel':'framework',\n                'colour': 'color', 'centre': 'center', 'favourite': 'favorite', 'travelling': 'traveling', \n                'counselling': 'counseling', 'theatre': 'theater', 'cancelled': 'canceled', 'labour': 'labor',\n                'organisation': 'organization', 'wwii': 'world war 2', 'citicise': 'criticize', 'youtu ': 'youtube ',\n                'Qoura': 'Quora', 'sallary': 'salary', 'Whta': 'What', 'narcisist': 'narcissist', 'howdo': 'how do',\n                'whatare': 'what are', 'howcan': 'how can', 'howmuch': 'how much', 'howmany': 'how many', \n                'whydo': 'why do', 'doI': 'do I', 'theBest': 'the best', 'howdoes': 'how does', \n                'mastrubation': 'masturbation', 'mastrubate': 'masturbate', \"mastrubating\": 'masturbating',\n                'pennis': 'penis', 'Etherium': 'Ethereum', 'narcissit': 'narcissist', 'bigdata': 'big data', \n                '2k17': '2017', '2k18': '2018', 'qouta': 'quota', 'exboyfriend': 'ex boyfriend', \n                'airhostess': 'air hostess', \"whst\": 'what', 'watsapp': 'whatsapp', 'demonitisation': 'demonetization',\n                'demonitization': 'demonetization', 'demonetisation': 'demonetization'}\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def preprocessing4(x, dic):\n    for word in dic.keys():\n        x = x.replace(word, dic[word])\n    return x\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.question_text = train_df.question_text.apply(lambda x: preprocessing4(x, mispell_dict))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"vocabulary = build_vocab(train_df['question_text'])\nuncovered = check_coverage(vocabulary,embed_glove)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"len_voc = 95000\nmax_len = 60","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"2 Tokenizing + padding"},{"metadata":{"trusted":true},"cell_type":"code","source":"def make_data(X):\n    t = Tokenizer(num_words=len_voc)\n    t.fit_on_texts(X)\n    X = t.texts_to_sequences(X)\n    X = pad_sequences(X, maxlen=max_len)\n    return X, t.word_index, t","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X, word_index, t = make_data(train_df['question_text'])\nY = train_df['target'].values\nlen_voc = len(word_index)\ndel train_df\nlen_voc","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"len_voc","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, Y, random_state = 420, test_size = 0.1)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"4 Embeddings"},{"metadata":{"trusted":true},"cell_type":"code","source":"def make_embed_matrix(embeddings_index, word_index, len_voc):\n    all_embs = np.stack(embeddings_index.values())\n    emb_mean,emb_std = all_embs.mean(), all_embs.std()\n    embed_size = all_embs.shape[1]\n    word_index = word_index\n    embedding_matrix = np.random.normal(emb_mean, emb_std, (len_voc, embed_size))\n    \n    for word, i in word_index.items():\n        if i >= len_voc: continue\n        embedding_vector = embeddings_index.get(word)\n        if embedding_vector is not None: \n            embedding_matrix[i] = embedding_vector\n    \n    return embedding_matrix","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"embedding = make_embed_matrix(embed_glove, word_index,len_voc)\ndel word_index\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"embedding[0].shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"embedding.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras import backend as K\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def f1(y_true, y_pred):\n    def recall(y_true, y_pred):\n        true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))\n        possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))\n        recall = true_positives / (possible_positives + K.epsilon())\n        return recall\n\n    def precision(y_true, y_pred):\n        true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))\n        predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))\n        precision = true_positives / (predicted_positives + K.epsilon())\n        return precision\n    \n    precision = precision(y_true, y_pred)\n    recall = recall(y_true, y_pred)\n    return 2*((precision*recall)/(precision+recall+K.epsilon()))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from tensorflow.compat.v1.keras.layers import CuDNNGRU\nfrom keras.layers import GlobalAveragePooling1D, GlobalMaxPool1D\nfrom keras.layers import Embedding,Bidirectional,LSTM,Dropout,Conv1D,MaxPooling1D,Dense\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def make_model(embedding_matrix, embed_size=300,loss='binary_crossentropy') :\n    model = Sequential()\n    model.add(Embedding(len_voc, embed_size , weights=[embedding_matrix], trainable=False))\n    model.add(LSTM(128)) \n    model.add(Dense(128,activation='relu'))\n    model.add(Dropout(0.2)) \n    model.add(Dense(1, activation=\"sigmoid\"))\n    model.compile(loss='binary_crossentropy', optimizer='adam' ,metrics=['accuracy',f1])\n    return model\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"modelTest= make_model(embedding)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"modelTest.summary()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Model creation"},{"metadata":{"trusted":true},"cell_type":"code","source":"WEIGHTS_PATH = './w0.h5'\nmc = callbacks.ModelCheckpoint( filepath=WEIGHTS_PATH, monitor='val_loss', mode='min', save_best_only=True )\nes = callbacks.EarlyStopping( patience=5 )\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"history = modelTest.fit(X_train, y_train, epochs = 10, validation_data = (X_test, y_test) , callbacks=[es , mc] , batch_size=2048 )\nplt.plot(history.history['val_loss'])\nplt.plot(history.history['loss'])\nplt.legend( ['test', 'train'] )","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_pred = modelTest.predict(X_test, batch_size=512, verbose=1)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"testing our model befor submitting"},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.metrics import f1_score\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def tweak_threshold(pred, truth):\n    thresholds = []\n    scores = []\n    for thresh in np.arange(0.1, 0.501, 0.01):\n        thresh = np.round(thresh, 2)\n        thresholds.append(thresh)\n        score = f1_score(truth, (pred>thresh).astype(int))\n        scores.append(score)\n    return np.max(scores), thresholds[np.argmax(scores)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"score_val, threshold_val = tweak_threshold(test_pred, y_test)\n\nprint(f\"Scored {round(score_val, 4)} for threshold {threshold_val} with untreated texts on validation data\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Submission"},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df  = pd.read_csv(\"/kaggle/input/quora-insincere-questions-classification/test.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"vocabulary = build_vocab(test_df['question_text'])\nuncovered = check_coverage(vocabulary,embed_glove)    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df.question_text = test_df.question_text.apply(preprocessing1)\ntest_df.question_text = test_df.question_text.apply(lambda x: preprocessing2(x, contraction_map))\ntest_df.question_text = test_df.question_text.apply(lambda x: preprocessing3(x, punct, special_map))\ntest_df.question_text = test_df.question_text.apply(lambda x: preprocessing4(x, mispell_dict))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"vocabulary = build_vocab(test_df['question_text'])\nuncovered = check_coverage(vocabulary,embed_glove)    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_X = test_df[\"question_text\"].fillna(\"_na_\").values\ntest_X = t.texts_to_sequences(test_X)\ntest_X = pad_sequences(test_X, maxlen=max_len)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_X","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_X.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pred_val = modelTest.predict(test_X, batch_size=512, verbose=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_y = (pred_val>0.34).astype(int)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_y.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_y","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"(unique, counts) = np.unique(test_y, return_counts=True)\nfrequencies = np.asarray((unique, counts)).T\nfrequencies","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission = pd.DataFrame({\"qid\":test_df[\"qid\"].values})\nsubmission['prediction'] = test_y\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}