{"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":"import matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline\n\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.svm import LinearSVC\nimport contractions","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f4cb6734e49c590fe0db6824cb82bdc2ee4d360d"},"cell_type":"code","source":"train = pd.read_csv('../input/train.csv')\ntest = pd.read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"35530bfe2a96060c60cb86772a2ce36acfe0c1e5"},"cell_type":"code","source":"train.question_text = train.question_text.apply(lambda x: contractions.fix(x))\ntest.question_text = test.question_text.apply(lambda x:contractions.fix(x))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d4d52875b8317ab524b5a2271a3ac91e1b6378fd"},"cell_type":"code","source":"tfidf = TfidfVectorizer(sublinear_tf=True, ngram_range=(1, 2), stop_words='english')\nX_train_dtm = tfidf.fit_transform(train.question_text)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"84982ba6dd9a00150bd4b851fc5d5064ed1399c8"},"cell_type":"code","source":"X_test_dtm = tfidf.transform(test.question_text)\nX_test_dtm","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2ecd7157d4325daf1fbc8ef74dff34d04ee17bf7"},"cell_type":"code","source":"#Linear SVC\nprint(\"\\nLinear SVC\")\nlogreg = LinearSVC()\n# train the model using X_train_dtm\n%time logreg.fit(X_train_dtm, train.target)\n# make class predictions for X_test_dtm\ny_pred = logreg.predict(X_test_dtm)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9b9f72b9f3c734d75eedf0a7954f43e6ca84f74a"},"cell_type":"code","source":"submission = test\nsubmission.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c67fea4540f5aff9949dfe2c2073cc12bdd82578"},"cell_type":"code","source":"\nsubmission['prediction'] = y_pred\nsubmission.prediction = submission.prediction.astype(int)\nsubmission.drop('question_text', axis = 1, inplace = True)\nsubmission.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"13e1452fdb4aace403bbb388126984d2c479dc06"},"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"74e2106a1962ec3f8a073cedc6d995c70c15b86c"},"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}