Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def plot_margins(serie, weights, clfs, importances=None):
global directory
if directory is None:
directory = prepare_directory()
from sklearn import tree
feature_names = ["f{} ({}, {})".format(i // 2, i, '-' if (i % 2) == 0 else '+') for i in range(2 * len(serie))]
out_str = io.StringIO()
for clf in clfs:
tree.export_graphviz(clf, out_file=out_str, feature_names=feature_names)
print("\n\n", file=out_str)
with open(str(directory / "tree.dot"), "w") as ofile:
print(out_str.getvalue(), file=ofile)
dtww.plot_margins(serie, weights, filename=str(directory / "margins.png"), importances=importances)