{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"data=pd.read_csv('../input/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ab811e159c105b1f61f52904b8e64ba4740bb93f"},"cell_type":"code","source":"from sklearn.feature_extraction.text import TfidfVectorizer","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"413ba1e8322509b0e6190d20d1f5c4ea1d713b28"},"cell_type":"code","source":"from nltk.corpus import stopwords","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1ae55ecd331e18351f332080fd380a1f8cabfa4e"},"cell_type":"code","source":"stopset=set(stopwords.words('english'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"26c3c83ec1ff85bddbdf8be07165541fa3ab7a85"},"cell_type":"code","source":"vector=TfidfVectorizer(use_idf=True , lowercase=True , strip_accents='ascii',stop_words=stopset)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0a80e71446635132664add7972bf1f9494856c79"},"cell_type":"code","source":"vector.fit(data['question_text'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"42b9b16792dc5414a0cc5aca28b4da77e9fd7584"},"cell_type":"code","source":"X=vector.transform(data['question_text'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4d52deaaf6c48164b3a535f215fc6c0ff0d2576e"},"cell_type":"code","source":"X.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"66daf94e70de80c14dd2b8686d77f4cd37e0adb5"},"cell_type":"code","source":"Y=data['target']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9bdbb120f85a6dea0f00df514658f68b4f76a912"},"cell_type":"code","source":"#from sklearn import naive_bayes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"35825653a08fb5fc1ddcab00cadc4e2f4826519b"},"cell_type":"code","source":"#ml=naive_bayes.MultinomialNB()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"01521332cd600dbcabcccc849263394156afd97f"},"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nlr=LogisticRegression(solver='sag',multi_class='ovr')\nlr.fit(X,Y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"db6ee613b503621b1d6c2c7e9f156c988b3415da"},"cell_type":"code","source":"#ml.fit(X,Y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1db1b4253c204f1cb4171cc22c17253f83197222"},"cell_type":"code","source":"test=pd.read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"47db89c7a706eb0d2ae750e0e88d37225f7f1094"},"cell_type":"code","source":"test.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"43ca0af0214b3a3d45d8e81915e4e27990d9a0c7"},"cell_type":"code","source":"voc=vector.transform(test['question_text'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b353ca1634b2ed5f687d5043748fdaffd7ba67f2"},"cell_type":"code","source":"predict=lr.predict(voc)\nprint(np.count_nonzero(predict == 1))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4b858d2598125178d9be7b6867c9e33e40d46419"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4884c9bac7f238a97069e3c3c5334e3ab13c7ba5"},"cell_type":"code","source":"df1=pd.DataFrame(test['qid'])\npre={'prediction':predict}\ndf2=pd.DataFrame(pre)\ndf1.reset_index(drop=True, inplace=True)\ndf2.reset_index(drop=True, inplace=True)\n\nresult = pd.concat( [df1, df2], axis=1)\nresult.to_csv('submission.csv',index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"01a011ca0694aafb664e89971f0634b409f1583e"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"35b901fed9b33b01bf1ac865dab36f08a9c4f5ae"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"608b2298314e44fac59b5ddd70fd4c4686d69d1c"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"42a5ea1fc90ede3f97be5dfce4066609d15f6fef"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"735629a956a72302ee6b7e65325b0d67099cefab"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cde3b235c981bf132c4df1b233a90b6bc2a1a8d2"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7d1fb64ba1a06a5b8562b4fcd043f26615d9143b"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b5034bd741b864fc55de621367d6b96a828b7b47"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"32b7eca7443971a79ad6f0c002be188827a2da1b"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}