{"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-08-16T13:28:27.11025Z","iopub.execute_input":"2022-08-16T13:28:27.111518Z","iopub.status.idle":"2022-08-16T13:28:27.147367Z","shell.execute_reply.started":"2022-08-16T13:28:27.111352Z","shell.execute_reply":"2022-08-16T13:28:27.1461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport collections\nfrom collections import Counter\nfrom wordcloud import WordCloud","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:29.102155Z","iopub.execute_input":"2022-08-16T14:10:29.102598Z","iopub.status.idle":"2022-08-16T14:10:29.275092Z","shell.execute_reply.started":"2022-08-16T14:10:29.102546Z","shell.execute_reply":"2022-08-16T14:10:29.273915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix, classification_report","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:24.689878Z","iopub.execute_input":"2022-08-16T14:10:24.690451Z","iopub.status.idle":"2022-08-16T14:10:25.488496Z","shell.execute_reply.started":"2022-08-16T14:10:24.69028Z","shell.execute_reply":"2022-08-16T14:10:25.487304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***EDA***","metadata":{}},{"cell_type":"code","source":"steam_data = pd.read_csv('../input/fds-block5-nlp/train.csv')\nsteam_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:32.252267Z","iopub.execute_input":"2022-08-16T14:10:32.252744Z","iopub.status.idle":"2022-08-16T14:10:35.575579Z","shell.execute_reply.started":"2022-08-16T14:10:32.252702Z","shell.execute_reply":"2022-08-16T14:10:35.573774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"steam_data.describe(include ='all')","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:38.829296Z","iopub.execute_input":"2022-08-16T14:10:38.829788Z","iopub.status.idle":"2022-08-16T14:10:39.438732Z","shell.execute_reply.started":"2022-08-16T14:10:38.829747Z","shell.execute_reply":"2022-08-16T14:10:39.437423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"steam_data['label']= steam_data['label'].apply(lambda x: -1 if x=='Not Recommend' else 1)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:39.440678Z","iopub.execute_input":"2022-08-16T14:10:39.441035Z","iopub.status.idle":"2022-08-16T14:10:39.643451Z","shell.execute_reply.started":"2022-08-16T14:10:39.441004Z","shell.execute_reply":"2022-08-16T14:10:39.641876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Game có nhiều review nhất**","metadata":{}},{"cell_type":"code","source":"steam_data.groupby(\"app_name\", as_index=False)[\"label\"].count().rename(columns={'label':'Review Count'}).sort_values(by=[\"Review Count\"], ascending=False).head(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:39.645396Z","iopub.execute_input":"2022-08-16T14:10:39.645841Z","iopub.status.idle":"2022-08-16T14:10:39.729075Z","shell.execute_reply.started":"2022-08-16T14:10:39.645803Z","shell.execute_reply":"2022-08-16T14:10:39.727769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Số lượng review trên từng game**","metadata":{}},{"cell_type":"code","source":"steam_data.groupby(\"app_name\", as_index=False)[\"label\"].count().rename(columns={'label':'Review Count'}).plot(figsize=(14,6))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:39.731824Z","iopub.execute_input":"2022-08-16T14:10:39.732202Z","iopub.status.idle":"2022-08-16T14:10:40.019422Z","shell.execute_reply.started":"2022-08-16T14:10:39.732165Z","shell.execute_reply":"2022-08-16T14:10:40.018176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Các từ phổ biến nhất trong các bài review sử dụng wordcloud**","metadata":{}},{"cell_type":"code","source":"steam_data[\"review_text\"] = steam_data[\"review_text\"].astype(str)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:40.021144Z","iopub.execute_input":"2022-08-16T14:10:40.022303Z","iopub.status.idle":"2022-08-16T14:10:40.076613Z","shell.execute_reply.started":"2022-08-16T14:10:40.022242Z","shell.execute_reply":"2022-08-16T14:10:40.075187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def WordCloud_generator(data, title=None):\n    most_freq = Counter(data).most_common(1000) \n    text = ' '.join([x[0] for x in most_freq])\n    \n    wordcloud = WordCloud(width = 800, height = 800,\n                          background_color ='white',\n                          min_font_size = 10,\n                          collocations=False\n                         ).generate(text)     \n    plt.figure(figsize = (6, 6), facecolor = None) \n    plt.imshow(wordcloud, interpolation='bilinear') \n    plt.axis(\"off\") \n    plt.tight_layout(pad = 0) \n    plt.title(title,fontsize=25)\n    plt.show() ","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:40.078864Z","iopub.execute_input":"2022-08-16T14:10:40.079659Z","iopub.status.idle":"2022-08-16T14:10:40.089918Z","shell.execute_reply.started":"2022-08-16T14:10:40.079605Z","shell.execute_reply":"2022-08-16T14:10:40.088267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"WordCloud_generator(steam_data[\"review_text\"], title=\"Most used words in reviews\")\n","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:40.094829Z","iopub.execute_input":"2022-08-16T14:10:40.095279Z","iopub.status.idle":"2022-08-16T14:10:42.01251Z","shell.execute_reply.started":"2022-08-16T14:10:40.095238Z","shell.execute_reply":"2022-08-16T14:10:42.011387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Trên đây là 1 EDA cơ bản do mình soạn ra, mọi người hãy tìm thêm các insight khác của tập dữ liệu này.... Càng nhiều và càng phong phú thì điểm càng cao**","metadata":{}},{"cell_type":"markdown","source":"***Code Baseline***\n","metadata":{}},{"cell_type":"markdown","source":"ý tưởng cơ bản là dùng random forest để classify ","metadata":{}},{"cell_type":"code","source":"test_data= pd.read_csv('../input/fds-block5-nlp/test.csv')\ntest_data[\"review_text\"] = test_data[\"review_text\"].astype(str)\nTest_reviews = test_data[\"review_text\"].values.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:42.013965Z","iopub.execute_input":"2022-08-16T14:10:42.014393Z","iopub.status.idle":"2022-08-16T14:10:42.785043Z","shell.execute_reply.started":"2022-08-16T14:10:42.014358Z","shell.execute_reply":"2022-08-16T14:10:42.783516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# chuyển text thành string\nsteam_data[\"review_text\"] = steam_data[\"review_text\"].astype(str)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:42.786476Z","iopub.execute_input":"2022-08-16T14:10:42.786871Z","iopub.status.idle":"2022-08-16T14:10:42.838904Z","shell.execute_reply.started":"2022-08-16T14:10:42.786828Z","shell.execute_reply":"2022-08-16T14:10:42.837586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"reviews = steam_data[\"review_text\"].values.tolist()\nlabels = steam_data[\"label\"].tolist()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:42.842131Z","iopub.execute_input":"2022-08-16T14:10:42.842514Z","iopub.status.idle":"2022-08-16T14:10:42.867243Z","shell.execute_reply.started":"2022-08-16T14:10:42.842478Z","shell.execute_reply":"2022-08-16T14:10:42.865627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import nltk\nfrom sklearn.datasets import load_files\nfrom sklearn.feature_extraction.text import CountVectorizer\nvectorizer = CountVectorizer()\nX = vectorizer.fit_transform(reviews).toarray()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:10:42.868807Z","iopub.execute_input":"2022-08-16T14:10:42.869269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.2, random_state=0)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import RandomForestClassifier\nclassifier = RandomForestClassifier(n_estimators=1000,random_state=0)\nclassifier.fit(X_train, y_train) ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = classifier.predict(X_test)\ny_pred","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred2 =  classifier.predict(Test_reviews)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}