How to use the dtaidistance.dtw_weighted function in dtaidistance

To help you get started, we’ve selected a few dtaidistance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wannesm / dtaidistance / tests / test_dtw_weighted_dt.py View on Github external
[0.14229249011857703, 0.4425000000000002],
        [0.19565217391304346, 0.5900000000000001]
    ])
    targets = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
    if directory:
        import matplotlib.pyplot as plt
        plt.figure(figsize=(3, 3))
        plt.scatter(features[:20, 0], features[:20, 1], marker="+")
        plt.scatter(features[20:, 0], features[20:, 1], marker=".")
        plt.xlim([-0.1, 1.1])
        plt.ylim([-0.1, 1.1])
        plt.savefig(str(directory / "features.png"))
        plt.close()

    clf = dtww.DecisionTreeClassifier()
    clf.fit(features, targets, use_feature_once=False)

    if directory:
        from sklearn.tree import export_graphviz
        export_graphviz(clf, out_file=str(directory / "hierarchy.dot"))
github wannesm / dtaidistance / tests / test_dtw_weighted.py View on Github external
[0.0, 0.1, 0.4, 0.3, 0.2, 0.3, 0.0, 0.0],
        [0.1, 0.0, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1]])
    l = np.array([1, 1, 0, 0, 0, 0, 0, 0])
    prototypeidx = 0

    if directory:
        plot_series(s, l, prototypeidx)
        savefig = str(directory / "dts.dot")
    else:
        savefig = None
    ml_values, cl_values, clf, imp = dtww.series_to_dt(s, l, prototypeidx, window=0, min_ig=0.01,
                                                       savefig=savefig,
                                                       warping_paths_fnc=dtww.warping_paths)
    # logger.debug(f"ml_values = {dict(ml_values)}")
    # logger.debug(f"cl_values = {dict(cl_values)}")
    weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values,
                                                   only_max=False, strict_cl=True)
    if directory:
        plot_margins(s[prototypeidx], weights, clf, imp)
github wannesm / dtaidistance / tests / test_dtw_weighted.py View on Github external
l = np.loadtxt(Path(__file__).parent / "rsrc" / "labels_0.csv", delimiter=',')

    if directory:
        plot_series(s, l)
        savefig = str(directory / "dts.dot")
    else:
        savefig = None

    prototypeidx = 3
    labels = np.zeros(l.shape)
    labels[l == l[prototypeidx]] = 1
    ml_values, cl_values, clf, importances = \
        dtww.series_to_dt(s, labels, prototypeidx, window=0, min_ig=0.1, savefig=savefig)
    logger.debug(f"ml_values = {dict(ml_values)}")
    logger.debug(f"cl_values = {dict(cl_values)}")
    weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values,
                                                   only_max=False, strict_cl=True)
    if directory:
        plot_margins(s[prototypeidx], weights, clf, prototypeidx)
github wannesm / dtaidistance / tests / test_dtw_weighted.py View on Github external
[0.0, 0.0, 1.1, 0.9, 1.0, 1.0, 0.0, 0.0],
        [0.0, 0.1, 1.1, 1.0, 0.9, 0.9, 0.0, 0.0],
        [0.0, 0.1, 1.0, 1.1, 0.9, 1.0, 0.0, 0.1],
        [0.0, 0.1, 0.4, 0.3, 0.2, 0.3, 0.0, 0.0],
        [0.1, 0.0, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1]])
    l = np.array([1, 1, 0, 0, 0, 0, 0, 0])
    prototypeidx = 0

    if directory:
        plot_series(s, l, prototypeidx)
        savefig = str(directory / "dts.dot")
    else:
        savefig = None
    ml_values, cl_values, clf, imp = dtww.series_to_dt(s, l, prototypeidx, window=0, min_ig=0.01,
                                                       savefig=savefig,
                                                       warping_paths_fnc=dtww.warping_paths)
    # logger.debug(f"ml_values = {dict(ml_values)}")
    # logger.debug(f"cl_values = {dict(cl_values)}")
    weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values,
                                                   only_max=False, strict_cl=True)
    if directory:
        plot_margins(s[prototypeidx], weights, clf, imp)
github wannesm / dtaidistance / tests / test_dtw_weighted.py View on Github external
[0.0, 0.2, 0.3, 0.7, 1.1, 0.0, 0.1, 0.0],
        [0.1, 0.0, 1.0, 1.0, 1.0, 0.9, 0.0, 0.0],
        [0.0, 0.0, 1.1, 0.9, 1.0, 1.0, 0.0, 0.0],
        [0.0, 0.1, 1.1, 1.0, 0.9, 0.9, 0.0, 0.0],
        [0.0, 0.1, 1.0, 1.1, 0.9, 1.0, 0.0, 0.1],
        [0.0, 0.1, 0.4, 0.3, 0.2, 0.3, 0.0, 0.0],
        [0.1, 0.0, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1]])
    l = np.array([1, 1, 0, 0, 0, 0, 0, 0])
    prototypeidx = 0

    if directory:
        plot_series(s, l, prototypeidx)
        savefig = str(directory / "dts.dot")
    else:
        savefig = None
    ml_values, cl_values, clf, imp = dtww.series_to_dt(s, l, prototypeidx, window=0, min_ig=0.01,
                                                       savefig=savefig,
                                                       warping_paths_fnc=dtww.warping_paths)
    # logger.debug(f"ml_values = {dict(ml_values)}")
    # logger.debug(f"cl_values = {dict(cl_values)}")
    weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values,
                                                   only_max=False, strict_cl=True)
    if directory:
        plot_margins(s[prototypeidx], weights, clf, imp)