{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "source": [ "import pandas as pd\n", "import numpy as np\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "from sklearn.model_selection import train_test_split\n", "import warnings\n", "from sklearn.metrics import accuracy_score, confusion_matrix\n", "from ast import literal_eval\n", "from sklearn.linear_model import LogisticRegressionCV\n", "from sklearn.metrics import classification_report\n", "from sklearn.naive_bayes import MultinomialNB\n", "from sklearn.svm import LinearSVC\n", "from imblearn.over_sampling import SMOTE\n", "from sklearn.model_selection import GridSearchCV\n", "from sklearn.svm import SVC\n", "warnings.filterwarnings('ignore')" ], "metadata": { "id": "Qf8de7f3KqrS" }, "execution_count": 1, "outputs": [] }, { "cell_type": "code", "source": [ "%cd /content/tweets-2019-cleaned-final.csv" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "DMVVU_M4dRko", "outputId": "eb2c503d-e200-4fca-da28-889dc9eb0222" }, "execution_count": 3, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "[Errno 20] Not a directory: '/content/tweets-2019-cleaned-final.csv'\n", "/content\n" ] } ] }, { "cell_type": "code", "source": [ "# Load the dataset\n", "df = pd.read_csv('tweets-2019-cleaned-final.csv', converters={\"message\": literal_eval})\n", "df = df.astype({'Content': 'str'})\n", "df.head(1000)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 930 }, "id": "cgObBSEKKz0s", "outputId": "7825c16e-4ab7-42c6-be9d-9a909422e91b" }, "execution_count": 13, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Tweet ID Username Content Created At User Location\n", "0 1082720989799239680 pkcLV Exactly!\\n\\nAs Greta Thunberg,a 15-yr-old from... 2019-01-08 19:29:34+00:00 peterkc1 on Post\n", "1 1082694057854414848 AOC The American people did not organize the bigge... 2019-01-08 17:42:33+00:00 Bronx + Queens, NYC\n", "2 1082680822447124480 squiffcreative Have you heard ‘Change is coming featuring Gre... 2019-01-08 16:49:57+00:00 forest of dean\n", "3 1082676373116702720 Veeresh22972960 @DrShekharPatel grateful 2 u 2 follow me great... 2019-01-08 16:32:17+00:00 forest\n", "4 1082663069824749568 peter_sorenson1 We need RADICALS 2 make change happen. Abraham... 2019-01-08 15:39:25+00:00 North Texas USA\n", ".. ... ... ... ... ...\n", "995 1103194772309716993 forumdc Greta #Thunberg has inspired other students by... 2019-03-06 07:25:04+00:00 Frankfurt, Germany\n", "996 1103193268744060928 RollingStone Watch climate activist Greta Thunberg talk abo... 2019-03-06 07:19:06+00:00 New York, New York\n", "997 1103160310830063616 crowfreak How Greta Thunberg’s Lone Strike Against Clima... 2019-03-06 05:08:08+00:00 Pacific Northwest native\n", "998 1103158550774382592 AlbertaChampion The anti-climate change movement started by Sw... 2019-03-06 05:01:08+00:00 Calgary, Alberta\n", "999 1103123170775560192 mightyreds 15 มีนานี้ เด็กๆ 51 ประเทศทั่วโลก นัดโดดเรียน ... 2019-03-06 02:40:33+00:00 Bangkok\n", "\n", "[1000 rows x 5 columns]" ], "text/html": [ "\n", "
\n", " | Tweet ID | \n", "Username | \n", "Content | \n", "Created At | \n", "User Location | \n", "
---|---|---|---|---|---|
0 | \n", "1082720989799239680 | \n", "pkcLV | \n", "Exactly!\\n\\nAs Greta Thunberg,a 15-yr-old from... | \n", "2019-01-08 19:29:34+00:00 | \n", "peterkc1 on Post | \n", "
1 | \n", "1082694057854414848 | \n", "AOC | \n", "The American people did not organize the bigge... | \n", "2019-01-08 17:42:33+00:00 | \n", "Bronx + Queens, NYC | \n", "
2 | \n", "1082680822447124480 | \n", "squiffcreative | \n", "Have you heard ‘Change is coming featuring Gre... | \n", "2019-01-08 16:49:57+00:00 | \n", "forest of dean | \n", "
3 | \n", "1082676373116702720 | \n", "Veeresh22972960 | \n", "@DrShekharPatel grateful 2 u 2 follow me great... | \n", "2019-01-08 16:32:17+00:00 | \n", "forest | \n", "
4 | \n", "1082663069824749568 | \n", "peter_sorenson1 | \n", "We need RADICALS 2 make change happen. Abraham... | \n", "2019-01-08 15:39:25+00:00 | \n", "North Texas USA | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
995 | \n", "1103194772309716993 | \n", "forumdc | \n", "Greta #Thunberg has inspired other students by... | \n", "2019-03-06 07:25:04+00:00 | \n", "Frankfurt, Germany | \n", "
996 | \n", "1103193268744060928 | \n", "RollingStone | \n", "Watch climate activist Greta Thunberg talk abo... | \n", "2019-03-06 07:19:06+00:00 | \n", "New York, New York | \n", "
997 | \n", "1103160310830063616 | \n", "crowfreak | \n", "How Greta Thunberg’s Lone Strike Against Clima... | \n", "2019-03-06 05:08:08+00:00 | \n", "Pacific Northwest native | \n", "
998 | \n", "1103158550774382592 | \n", "AlbertaChampion | \n", "The anti-climate change movement started by Sw... | \n", "2019-03-06 05:01:08+00:00 | \n", "Calgary, Alberta | \n", "
999 | \n", "1103123170775560192 | \n", "mightyreds | \n", "15 มีนานี้ เด็กๆ 51 ประเทศทั่วโลก นัดโดดเรียน ... | \n", "2019-03-06 02:40:33+00:00 | \n", "Bangkok | \n", "
1000 rows × 5 columns
\n", "