{ "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 import text \n", "\n", "from sklearn.naive_bayes import GaussianNB\n", "\n", "from nltk.tokenize import word_tokenize\n", "from nltk.probability import FreqDist" ] }, { "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", "
|---|---|---|---|
| 427520 | \n", "11 | \n", "Guzmania remyi | \n", "Guzmania remyi is a species of plant in the B... | \n", "
| 522145 | \n", "14 | \n", "Villa Aurore | \n", "Villa Aurore is a novel written in French by ... | \n", "
| 462552 | \n", "12 | \n", "Monk's Casino | \n", "Monk's Casino is a live album by German free ... | \n", "
| 2460 | \n", "1 | \n", "Kiss Technology | \n", "Kiss Technology is an entertainment technolog... | \n", "
| 83743 | \n", "3 | \n", "S.M. Zakir | \n", "S.M. Zakir (born 4 February 1969 in Kota Bhar... | \n", "
| 554887 | \n", "14 | \n", "New York Law Journal | \n", "The New York Law Journal founded in 1888 is a... | \n", "
| 270857 | \n", "7 | \n", "Latham United Methodist Church | \n", "Latham United Methodist Church is a historic ... | \n", "
| 323989 | \n", "9 | \n", "Nalavadi | \n", "Nalavadi is a village in Dharwad district in ... | \n", "
| 193352 | \n", "5 | \n", "Richard Ottley (judge) | \n", "Sir Richard Ottley was the 5th Chief Justice ... | \n", "
| 78104 | \n", "2 | \n", "Umatilla High School (Oregon) | \n", "Umatilla High School is a public high school ... | \n", "