<jupyter_start><jupyter_text>Build a histogram with percentages correct for each category<jupyter_code>df_test = df[(df["is_test"] == True)]
df_test["prediction"] = predictions
#print df_test.head()
# Compare the percent correct to the results from earlier to make sure things are lined up right
print "Calculated accuracy:", sum(df_test["label"] == df_test["prediction"]) / float(len(df_test))
print "Model accuracy:", best_score
df_correct = df_test[(df_test["label"] == df_test["prediction"])]
df_incorrect = df_test[(df_test["label"] != df_test["prediction"])]
#df_correct.describe()
#df_test.describe()
#plt.hist(correct_labels)
#print df.describe()
print "Correct predictions:", df_correct.groupby(["label"])["prediction"].count()
print "Incorrect predictions:", df_incorrect.groupby(["label"])["prediction"].count()<jupyter_output>Correct predictions: label
catalogNumber     5934
country            635
county            4484
family              17
recordNumber      3155
recordedBy       31305
sciname           1989
stateProvince     5905
Name: prediction, dtype: int64
Incorrect predictions: label
catalogNumber      2303
country            1535
county             2958
family              567
genus                 2
recordNumber       3541
recordedBy         4956
sciname            2306
specificEpithet       3
stateProvince      4255
Name: prediction, dtype: int64<jupyter_text>Stats of text length for correct and incorrect<jupyter_code>print df_correct.describe()
print df_incorrect.describe()
#print model_results
d3_data = {}
for m in model_results:
    d3_data[m["feat_name"]] = {}
    d3_data[m["feat_name"]]["C"] = []
    d3_data[m["feat_name"]]["G"] = []
    d3_data[m["feat_name"]]["S"] = []
    #print m["feat_name"], m["model_params"], m["model_score"]
    for s in m["grid_scores"]:
        d3_data[m["feat_name"]]["C"].append(s[0]["C"])
        d3_data[m["feat_name"]]["G"].append(s[0]["gamma"])
        d3_data[m["feat_name"]]["S"].append(s[1])
        
#print d3_data
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from matplotlib import pylab
pylab.rcParams['figure.figsize'] = (10.0, 8.0)

def d3_plot(X, Y, Z):
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.set_xlabel("C", weight="bold", size="xx-large")
    ax.set_xticks([0, 5000, 10000, 15000])
    ax.set_xlim(0, max(X))
    ax.set_ylabel("gamma", weight="bold", size="xx-large")
    ax.set_yticks([0, 1.5, 3, 4.5])
    ax.set_ylim(0, max(Y))
    ax.set_zlabel("Accuracy", weight="bold", size="xx-large")
    #ax.set_zticks([0.5, 0.6, 0.70])
    ax.set_zlim(0.5, 0.75)
    ax.scatter(X, Y, Z, c='b', marker='o')
    ax.zaxis.set_major_locator(LinearLocator(10))
    ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
    plt.show()


d3_plot(np.array(d3_data["area"]["C"]), np.array(d3_data["area"]["G"]), np.array(d3_data["area"]["S"]))
d3_plot(np.array(d3_data["line"]["C"]), np.array(d3_data["line"]["G"]), np.array(d3_data["line"]["S"]))
d3_plot(np.array(d3_data["word"]["C"]), np.array(d3_data["word"]["G"]), np.array(d3_data["word"]["S"]))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17287066246056781, 'fraction_numerical': 0.043848580441640375, 'mean_word_length': 4.534031413612565, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '512263', 'license': 'MIT', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1175, 'n_words': 215, 'path': 'results/analize_results.ipynb', 'repo_name': 'mjcollin/ml_ocr', 'size': '3170'}