{ "cells": [ { "cell_type": "code", "execution_count": 1, "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": 2, "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": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(559999, 3)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dbpedia_df.shape" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dbpedia_df['Label'].unique()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "dbpedia_df = dbpedia_df.sample(10000, replace=False)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Label | \n", "Name | \n", "Text | \n", "
|---|---|---|---|
| 521705 | \n", "14 | \n", "Woodstock (novel) | \n", "Woodstock or The Cavalier. A Tale of the Year... | \n", "
| 373693 | \n", "10 | \n", "Cryptophagidae | \n", "Cryptophagidae is a family of beetles with re... | \n", "
| 333934 | \n", "9 | \n", "Dehliz-e Yek | \n", "Dehliz-e Yek (Persian: دهليزيك also Romanize... | \n", "
| 125305 | \n", "4 | \n", "Roland Osabutey | \n", "Roland Osabutey (born 11 March 1980) is a Gha... | \n", "
| 100866 | \n", "3 | \n", "Ann Voskamp | \n", "Ann Voskamp (born August 10 1973 in Listowel ... | \n", "
| 58320 | \n", "2 | \n", "Robert Bateman High School | \n", "Robert Bateman High School (also known as Rob... | \n", "
| 419470 | \n", "11 | \n", "Vriesea languida | \n", "Vriesea languida is a species of the genus Vr... | \n", "
| 164430 | \n", "5 | \n", "Gilbert Wellington Ostrom | \n", "Gilbert Wellington Ostrom (June 1837 – Decemb... | \n", "
| 426098 | \n", "11 | \n", "Banara regia | \n", "Banara regia is a species of plant in the Sal... | \n", "
| 281236 | \n", "8 | \n", "Calder River (Western Australia) | \n", "For other Rivers Calder see River Calder (dis... | \n", "