<jupyter_start><jupyter_text>Compare cross-validated models  IPython magics<jupyter_code>%matplotlib inline<jupyter_output><empty_output><jupyter_text>Imports<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import titanic.tools as tools

from pprint import pprint
from titanic.modelling import ExtendedClassifier

pd.options.display.max_columns = None
pd.options.display.max_rows = None
pd.options.display.max_colwidth = -1

plt.rcParams['figure.figsize'] = [15, 4.5]<jupyter_output><empty_output><jupyter_text>Deserialize models<jupyter_code>models = dict()
models['LogisticRegression'] = ExtendedClassifier.deserialize(r'../models/logreg.pickle')
models['RandomForestClassifier'] = ExtendedClassifier.deserialize(r'../models/forest.pickle')
models['SVC'] = ExtendedClassifier.deserialize(r'../models/svc.pickle')
models['VotingClassifier'] = ExtendedClassifier.deserialize(r'../models/voting.pickle')
models<jupyter_output><empty_output><jupyter_text>Compare models<jupyter_code>scores = {name: model.profile['cv_score'] for name, model in models.items()}
scores
list(scores.keys())
fig = plt.figure(figsize=[15, 5])
ax = fig.add_subplot(111)
sns.barplot(x=list(scores.keys()), y=list(scores.values()), orient='v', ax=ax)
ax.set_ylim(bottom=0.8)
ax.set_title('Cross-validated accuracy of candidate models', fontsize=15)
for p in ax.patches:
    ax.annotate("%.5f" % p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()),
                ha='center', va='center', fontsize=13, color='k', alpha=0.8,
                xytext=(0, 20), textcoords='offset points')
plt.show()<jupyter_output><empty_output><jupyter_text>Save as .py<jupyter_code>%%javascript
IPython.notebook.save_notebook()
# sdfgjlsdfglksdjg
!jupyter nbconvert --to script 02_compare_models.ipynb<jupyter_output>[NbConvertApp] Converting notebook 02_compare_models.ipynb to script
[NbConvertApp] Writing 1803 bytes to 02_compare_models.py
{'fraction_non_alphanumeric': 0.141254462009179, 'fraction_numerical': 0.017338092809790925, 'mean_word_length': 7.0081632653061225, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '107726', 'license': 'MIT', 'n_tokens_mistral': 735, 'n_tokens_neox': 700, 'n_words': 116, 'path': 'notebooks/02_compare_models.ipynb', 'repo_name': 'alvaromendoza/pytanic', 'size': '1961'}