<jupyter_start><jupyter_text>Decision Tree<jupyter_code>train_X = balanced_fit[:,:-2]  #POS and errors
train_Y = balanced_fit[:,-1]
estimator = tree.DecisionTreeClassifier(max_depth=4)
tree_fit = estimator.fit(train_X, train_Y)
tree_fit.feature_importances_
graphviz_representation = tree.export_graphviz(tree_fit, out_file=None,
                                               max_depth=3,
                                               feature_names=ordered_features,
                                               class_names = ['OK', 'error'],
                                               filled=True, rounded=True, special_characters=True)
graph = graphviz.Source(graphviz_representation)
graph
ordered_features2 = list(ordered_features)
del ordered_features2[-2]
train_X2 = balanced_fit[:,:-4]
train_X2 = np.concatenate((train_X2, balanced_fit[:,-3:-2]), 1)
ordered_features2
estimator = tree.DecisionTreeClassifier(max_depth=3)
tree_fit2 = estimator.fit(train_X2, train_Y)
tree_fit2.feature_importances_
graphviz_representation = tree.export_graphviz(tree_fit2, out_file=None,
                                               max_depth=3,
                                               feature_names=ordered_features2,
                                               class_names = ['OK', 'error'],
                                               filled=True, rounded=True, special_characters=True)
graph = graphviz.Source(graphviz_representation)
graph.render('1', format='png')
graph<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09288537549407115, 'fraction_numerical': 0.015151515151515152, 'mean_word_length': 2.225053078556263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '148958', 'license': 'MIT', 'n_tokens_mistral': 419, 'n_tokens_neox': 413, 'n_words': 61, 'path': 'Chapter11/Decision_Trees.ipynb', 'repo_name': 'nalomran/Bioinformatics-with-Python-Cookbook-Second-Edition', 'size': '1518'}