{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"758B-Lab-1-answer.ipynb","provenance":[],"collapsed_sections":[],"toc_visible":true,"authorship_tag":"ABX9TyNqcL4TjZ7KOpGzvyYJEy9Q"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"JOIWgMXLI-Og"},"source":["# Load data"]},{"cell_type":"code","metadata":{"id":"DHMQ89Hkvowj","executionInfo":{"status":"ok","timestamp":1601323106806,"user_tz":240,"elapsed":475,"user":{"displayName":"Kunpeng Zhang","photoUrl":"","userId":"09274433828486852799"}},"outputId":"8003abb8-a5af-41ae-8cd2-426930af28eb","colab":{"base_uri":"https://localhost:8080/","height":204}},"source":["# load text data and convert the label/sentiment into corresponding numeric values: 'positive':2,'neutral':1,'negative':0\n","# possible packages you might need are: pandas, numpy\n","\n","import pandas as pd\n","import numpy as np\n","\n","# read the training data\n","fname = 'facebook_comments.csv'\n","df_train = pd.read_csv(fname,header=None,names=['text','sentiment'],encoding='iso-8859-1',lineterminator='\\n')\n","sent = {'positive':2,'neutral':1,'negative':0}\n","df_train['labels'] = df_train['sentiment'].str.strip().map(sent)\n","\n","# get texts and labels\n","training_texts = df_train.text.values\n","labels = df_train.labels.values\n","\n","# show the first 5 records\n","df_train.head()"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/html":["
\n"," | text | \n","sentiment | \n","labels | \n","
---|---|---|---|
0 | \n","Heres a single to add to Kindle. Just read t... | \n","neutral | \n","1 | \n","
1 | \n","If you tire of Non-Fiction.. Check out http://... | \n","neutral | \n","1 | \n","
2 | \n","Ghost of Round Island is supposedly nonfiction. | \n","neutral | \n","1 | \n","
3 | \n","Why is Barnes and Nobles version of the Kindle... | \n","negative | \n","0 | \n","
4 | \n","@Maria: Do you mean the Nook? Be careful bo... | \n","positive | \n","2 | \n","