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)
def plot_series(s, l, idx=None):
global directory
if directory is None:
directory = prepare_directory()
import matplotlib.pyplot as plt
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
fig1, ax1 = plt.subplots(nrows=len(s), ncols=1)
fig2, ax2 = plt.subplots(nrows=1, ncols=1)
for i, si in enumerate(s):
if i == idx:
color = colors[0]
else:
color = colors[int(1 + l[i])]
ax1[i].plot(si, color=color)
ax2.plot(si, color=color)
fig1.savefig(str(directory / "series1.png"))
fig2.savefig(str(directory / "series2.png"))
def test_distance1():
directory = prepare_directory()
s1 = np.array([0., 0, 1, 2, 1, 0, 1, 0, 0, 2, 1, 0, 0])
s2 = np.array([0., 1, 2, 3, 1, 10, 1, 0, 2, 1, 0, 0, 0])
d, paths = dtw.warping_paths(s1, s2)
# print(d, "\n", paths)
dtwvis.plot_warpingpaths(s1, s2, paths, filename=directory / "temp1.png")
weights = np.full((len(s1), 8), np.inf)
weights[:, 2:4] = 0.0
weights[4:7, 2:4] = 10.0
weights[:, 4:6] = 0.0
weights[4:7, 4:6] = 10.0
d, paths = dtww.warping_paths(s1, s2, weights)
# print(d, "\n", paths)
dtwvis.plot_warpingpaths(s1, s2, paths, filename=directory / "temp2.png")