<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Example of how to use classification code for ship logbooks
Imports
Step1:  Initialize classifier
Classification algorithm can be set to "Naive Bayes" or "Decision Tree"
Step2:  Load Data, Clean data, and Perform Classification
This function loads, cleans, and classifies data
Options include
Step3:  How to access data from outside of the classifier
Step4:  Sample plots of data
<ASSISTANT_TASK:>
Python Code:
from exploringShipLogbooks.config import non_slave_ships
from exploringShipLogbooks.classification import LogbookClassifier
Explanation: Example of how to use classification code for ship logbooks
Imports
End of explanation
cl = LogbookClassifier(classification_algorithm="Naive Bayes")
Explanation: Initialize classifier
Classification algorithm can be set to "Naive Bayes" or "Decision Tree"
End of explanation
cl.load_clean_and_classify(fuzz=False, export_csv=True)
Explanation: Load Data, Clean data, and Perform Classification
This function loads, cleans, and classifies data
Options include:
fuzz - boolean value for whether to perform fuzzy string matching on values or not
export_csv - boolean value to determine whether classification output is saved. The csv contains information for every log used in the code, with the following key:
0 = unclassified data
1 = data used as negative training data
2 = data used as positive validation data from cliwoc database
3 = slave voyages database data
4 = data classified as a non-slave ship
5 = data classified a slave ship
End of explanation
# data that was classified (unknown class before classification)
cl.unclassified_logs.head()
# data used for validation: 20% of slave voyage logs
cl.validation_set_2.head()
# data used for validation: logs that mention slaves in cliwoc data set
cl.validation_set_1.head()
# data used for training classifier
cl.training_data.head()
Explanation: How to access data from outside of the classifier
End of explanation
import exploringShipLogbooks
import os.path as op
import matplotlib.pyplot as plt
import matplotlib
%matplotlib inline
import pandas as pd
# load un-cleaned slave_voyage_logs data
data_path = op.join(exploringShipLogbooks.__path__[0], 'data')
file_name = data_path + '/tastdb-exp-2010'
slave_voyage_logs = pd.read_pickle(file_name)
fig1, ax1 = plt.subplots()
ax1.hist(pd.concat([cl.validation_set_2, cl.training_data], ignore_index = True)['Year'])
ax1.set_xlabel('Year', fontsize = 30)
ax1.set_ylabel('Counts', fontsize = 30)
plt.xlim([1750, 1850])
for tick in ax1.xaxis.get_major_ticks():
    tick.label.set_fontsize(26) 
for tick in ax1.yaxis.get_major_ticks():
    tick.label.set_fontsize(26) 
fig1.set_size_inches(10, 8)
plt.savefig('slave_voyage_years.png')
fig2, ax2 = plt.subplots()
ax2.hist(pd.concat([cl.validation_set_1, cl.unclassified_logs], ignore_index = True)['Year'])
ax2.set_xlabel('Year', fontsize = 30)
ax2.set_ylabel('Counts', fontsize = 30)
plt.xlim([1750, 1850])
for tick in ax2.xaxis.get_major_ticks():
    tick.label.set_fontsize(26) 
for tick in ax2.yaxis.get_major_ticks():
    tick.label.set_fontsize(26) 
fig2.set_size_inches(11, 8)
plt.savefig('cliwoc_years.jpeg')
fractions = []
fract_dict = dict(slave_voyage_logs['national'].value_counts(normalize=True))
fractions = []
nats = []
for key in fract_dict:
    if fract_dict[key] > 0.01:
        nats.append(key)
        fractions.append(fract_dict[key])
explode=[0.05] * len(fractions)
fig2, ax2 = plt.subplots()
fig2.set_size_inches(10,10)
matplotlib.rcParams['font.size'] = 30
matplotlib.pylab.pie(fractions, labels = nats, explode = explode)
plt.savefig('slave_voyages_nats.png')
fractions = []
fract_dict = dict(cl.cliwoc_data_all['Nationality'].value_counts(normalize=True))
fractions = []
nats = []
for key in fract_dict:
    if fract_dict[key] > 0.01:
        nats.append(key)
        fractions.append(fract_dict[key])
explode=[0.05] * len(fractions)
fig2, ax2 = plt.subplots()
fig2.set_size_inches(10,10)
matplotlib.rcParams['font.size'] = 30
matplotlib.pylab.pie(fractions, labels = nats, explode = explode)
plt.savefig('cliwoc_nats.png')
Explanation: Sample plots of data
End of explanation
<END_TASK>