{ "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", "\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.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": "markdown", "metadata": {}, "source": [ "### DBPedia classes\n", "\n", "- Company\n", "- EducationalInstitution\n", "- Artist\n", "- Athlete\n", "- OfficeHolder\n", "- MeanOfTransportation\n", "- Building\n", "- NaturalPlace\n", "- Village\n", "- Animal\n", "- Plant\n", "- Album\n", "- Film\n", "- WrittenWork" ] }, { "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", "
|---|---|---|---|
| 524463 | \n", "14 | \n", "Open Sesame (manga) | \n", "Open Sesame is a Japanese manga series writte... | \n", "
| 214954 | \n", "6 | \n", "USS Porter (DDG-78) | \n", "USS Porter (DDG-78) is an Arleigh Burke-class... | \n", "
| 369188 | \n", "10 | \n", "Chionodes luctuella | \n", "Chionodes luctuella is a moth of the Gelechii... | \n", "
| 15537 | \n", "1 | \n", "Rashtriya Chemicals & Fertilizers | \n", "Rashtriya Chemicals & Fertilizers Ltd. (RCF) ... | \n", "
| 434426 | \n", "11 | \n", "Salix gilgiana | \n", "Salix gilgiana is a species of willow native ... | \n", "
| 315086 | \n", "8 | \n", "Devlins Creek | \n", "Devlins Creek an urban watercourse that is pa... | \n", "
| 133194 | \n", "4 | \n", "Warren Donald | \n", "Warren Donald (born 7 October 1964) is an Eng... | \n", "
| 138090 | \n", "4 | \n", "Chris Hatcher (outfielder) | \n", "Christopher Kenneth Hatcher (born January 7 1... | \n", "
| 358873 | \n", "9 | \n", "Królewskie Ostrzeszów County | \n", "Królewskie [kruˈlɛfskʲɛ] is a village in the ... | \n", "
| 108048 | \n", "3 | \n", "Hamuera Tamahau Mahupuku | \n", "Hamuera Tamahau Mahupuku (c.1842 – 14 January... | \n", "