{ "cells": [ { "cell_type": "code", "execution_count": 3, "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 TfidfVectorizer\n", "\n", "from sklearn.naive_bayes import GaussianNB" ] }, { "cell_type": "code", "execution_count": 4, "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": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(559999, 3)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dbpedia_df.shape" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dbpedia_df['Label'].unique()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "dbpedia_df = dbpedia_df.sample(10000, replace=False)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Label | \n", "Name | \n", "Text | \n", "
|---|---|---|---|
| 252405 | \n", "7 | \n", "Prowers Bridge | \n", "The Prowers Bridge over the Arkansas River ne... | \n", "
| 504457 | \n", "13 | \n", "Que sera sera (film) | \n", "Que sera sera (Portuguese: Seja o que Deus Qu... | \n", "
| 270494 | \n", "7 | \n", "The Esplanade (Kenner Louisiana) | \n", "The Esplanade also known as the Esplanade Mal... | \n", "
| 546058 | \n", "14 | \n", "The 1974 Annual World's Best SF | \n", "The 1974 Annual World's Best SF is an antholo... | \n", "
| 461279 | \n", "12 | \n", "Just Go (album) | \n", "Just Go is the ninth studio album by American... | \n", "
| 277143 | \n", "7 | \n", "Steyning Methodist Church | \n", "Steyning Methodist Church is a Methodist plac... | \n", "
| 266867 | \n", "7 | \n", "Smith Estate (Ridge New York) | \n", "Smith Estate also known as Longwood Estate - ... | \n", "
| 283712 | \n", "8 | \n", "Yr Eifl | \n", "Yr Eifl is a mountain on the north coast of t... | \n", "
| 33861 | \n", "1 | \n", "IBM India | \n", "IBM India Private Limited is the Indian subsi... | \n", "
| 70953 | \n", "2 | \n", "Loreto College of Rose-Hill | \n", "Loreto College Rose Hill is a private seconda... | \n", "