{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.metrics import accuracy_score\n", "from sklearn.metrics import precision_score\n", "from sklearn.metrics import recall_score\n", "\n", "from sklearn.feature_extraction.text import CountVectorizer\n", "from sklearn.feature_extraction.text import TfidfTransformer\n", "\n", "from sklearn.naive_bayes import GaussianNB" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "dbpedia_df = pd.read_csv('./datasets/dbpedia_csv/train.csv', \n", " skiprows=1, names = ['Label', 'Name', 'Text'])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(559999, 3)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dbpedia_df.shape" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dbpedia_df['Label'].unique()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "dbpedia_df = dbpedia_df.sample(10000, replace=False)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Label | \n", "Name | \n", "Text | \n", "
|---|---|---|---|
| 445879 | \n", "12 | \n", "Lucas (album) | \n", "Lucas is the second album by Ghostly Internat... | \n", "
| 120854 | \n", "4 | \n", "Pat McGehee | \n", "Patrick Henry McGehee (July 2 1888 – December... | \n", "
| 449608 | \n", "12 | \n", "One Too Many Hearts | \n", "One Too Many Hearts is the third EP by Americ... | \n", "
| 171512 | \n", "5 | \n", "Arken Arystanov | \n", "Arkén Kenesbékovich Arystánov (Kazakh: Аркен ... | \n", "
| 26868 | \n", "1 | \n", "Cineplex Odeon Films | \n", "Cineplex Odeon Films (also known as Cineplex ... | \n", "
| 402498 | \n", "11 | \n", "Steirachne | \n", "Steirachne is a genus of grass in the Poaceae... | \n", "
| 102353 | \n", "3 | \n", "Harry Thumann | \n", "Harry Thumann (28 February 1952 – 2001) was a... | \n", "
| 337385 | \n", "9 | \n", "Chah Sheykh | \n", "Chah Sheykh (Persian: چاه شيخ also Romanized... | \n", "
| 485176 | \n", "13 | \n", "Emmtan-Magan | \n", "Em Magan is a 2006 Tamil drama film directed ... | \n", "
| 295129 | \n", "8 | \n", "Hot Springs Range | \n", "The Hot Springs Range is a mountain range in ... | \n", "