{"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":"# 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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\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-01-19T15:07:50.410945Z","iopub.execute_input":"2022-01-19T15:07:50.411335Z","iopub.status.idle":"2022-01-19T15:07:50.445822Z","shell.execute_reply.started":"2022-01-19T15:07:50.411234Z","shell.execute_reply":"2022-01-19T15:07:50.445025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.linear_model import RidgeClassifier, LogisticRegression\nfrom lightgbm import LGBMClassifier\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2022-01-19T15:07:50.572434Z","iopub.execute_input":"2022-01-19T15:07:50.573202Z","iopub.status.idle":"2022-01-19T15:07:53.304245Z","shell.execute_reply.started":"2022-01-19T15:07:50.573162Z","shell.execute_reply":"2022-01-19T15:07:53.303532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#读取数据集\ntrain_df = pd.read_csv('/kaggle/input/DeepShare_nlpstarter/train.csv')\ntest_df = pd.read_csv('/kaggle/input/DeepShare_nlpstarter/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-19T15:07:53.305953Z","iopub.execute_input":"2022-01-19T15:07:53.306198Z","iopub.status.idle":"2022-01-19T15:08:00.141947Z","shell.execute_reply.started":"2022-01-19T15:07:53.306167Z","shell.execute_reply":"2022-01-19T15:08:00.141155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Tfidf编码\ntfidf = TfidfVectorizer(ngram_range=(1, 2), max_features=1000).fit(train_df['text'].iloc[:].values)\ntrain_tfidf = tfidf.transform(train_df['text'].iloc[:].values)\ntest_tfidf = tfidf.transform(test_df['text'].iloc[:].values)\nprint('Finish Tfidf')\n\n#Lgb\nclf = LGBMClassifier()\nclf.fit(train_tfidf, train_df['label'].iloc[:].values)\nprint('Finish Lgb')\n\n#提交结果\nres = pd.DataFrame()\nres['id'] = test_df['id']\nres['label'] = clf.predict(test_tfidf)\nres.to_csv('submission.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2022-01-19T15:08:00.143401Z","iopub.execute_input":"2022-01-19T15:08:00.143743Z","iopub.status.idle":"2022-01-19T15:18:26.170068Z","shell.execute_reply.started":"2022-01-19T15:08:00.143701Z","shell.execute_reply":"2022-01-19T15:18:26.168826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res","metadata":{"execution":{"iopub.status.busy":"2022-01-19T15:23:16.479035Z","iopub.execute_input":"2022-01-19T15:23:16.479404Z","iopub.status.idle":"2022-01-19T15:23:16.499721Z","shell.execute_reply.started":"2022-01-19T15:23:16.479368Z","shell.execute_reply":"2022-01-19T15:23:16.498732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}