python-3.x - 导入错误: No module named 'mstamp_stomp'

标签 python-3.x machine-learning time-series cluster-analysis matrix-profile

我正在尝试从 git 存储库运行 demo.py https://github.com/mcyeh/mstamp/tree/master/Python 。 这是论文Matrix Profile VI: Meaningful Multidimensional Motif Discovery的源代码。我已附上下面的代码。

# -*- coding: utf-8 -*-
"""
@author: Michael Yeh
C.-C. M. Yeh, N. Kavantzas, and E. Keogh, "Matrix Profile VI: Meaningful
Multidimensional Motif Discovery," IEEE ICDM 2017.
https://sites.google.com/view/mstamp/
http://www.cs.ucr.edu/~eamonn/MatrixProfile.html
"""

import scipy.io as sio
import matplotlib.pyplot as plt
from mstamp_stomp import mstamp as mstamp_stomp
from mstamp_stamp import mstamp as mstamp_stamp


def plot_motifs(matrix_profile, dimensionality=1):
    motif_at = matrix_profile[dimensionality - 1, :].argsort()[:2]

    plt.figure(figsize=(14, 7))
    for i in range(3):
        plt.subplot(4, 1, i + 1)
        plt.plot(data.T[i, :])
        plt.title('$T_{}$'.format(i + 1))
        for m in motif_at:
            plt.plot(range(m, m + sub_len), data.T[i, :][m:m + sub_len], c='r')
        plt.xlim((0, matrix_profile.shape[1]))

    plt.subplot(414)
    plt.title('{}-dimensional Matrix Profile'.format(dimensionality))
    plt.plot(matrix_profile[dimensionality - 1, :])
    for m in motif_at:
        plt.axvline(m, c='r')
    plt.xlim((0, matrix_profile.shape[1]))
    plt.tight_layout()


if __name__ == '__main__':
    mat = sio.loadmat('toy_data.mat')
    data = mat['data']
    sub_len = mat['sub_len'][0][0]

    # using the stomp based method to compute the multidimensional matrix
    # profile
    mat_pro_1, pro_idx_1 = mstamp_stomp(data.T, sub_len,
                                        return_dimension=False)

    # plot the matrix profile as image
    plt.figure()
    plt.title('Matrix Profile (STOMP)')
    plt.imshow(mat_pro_1, extent=[0, 1, 0, 1])

    # using the stamp based method to compute the multidimensional matrix
    # profile
    mat_pro_2, pro_idx_2 = mstamp_stamp(data.T, sub_len,
                                        return_dimension=False)

    # plot the matrix profile as image
    plt.figure()
    plt.title('Matrix Profile (STAMP)')
    plt.imshow(mat_pro_2, extent=[0, 1, 0, 1])

    plot_motifs(mat_pro_2)

    # the function can also be used to compute the 1D matrix profile
    mat_pro_3, _ = mstamp_stomp(data[:, 1].T, sub_len,
                                return_dimension=False)
    plt.figure()
    plt.plot(mat_pro_3[0, :])

    mat_pro_4, _ = mstamp_stamp(data[:, 1].T, sub_len,
                                return_dimension=False)
    plt.figure()
    plt.plot(mat_pro_4[0, :])

    plt.show()

最佳答案

Import error: No module named 'mstamp_stomp'

这反射(reflect)了搜索路径问题。您需要 chdir 进入包含源代码的目录,并且在执行代码之前您还需要在路径中包含 . 点:

$ cd mstamp/Python
$ export PYTHONPATH=.
$ python demo.py

您可以使用此代码片段来调试此类问题:

import pprint
import sys
pprint.pprint(sys.path)

关于python-3.x - 导入错误: No module named 'mstamp_stomp' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54895017/

相关文章:

python - 回车不保持新的光标位置

python - Python 中的日期字符串格式化

python - Selenium 驱动程序: How to find the element added after the webpage is loaded?

R:使用 bigmemory 库通过 randomForest 进行分类

graph - Highcharts -指定堆积时间序列的顺序

Python 3 sys.exec_prefix 错误

machine-learning - 表示 H2O 输入 CSV 中的项目列表

python - 在 python 中查找嵌套字典中的值之和

python - 用于附加和创建 pandas 数据帧的快速 numpy 数组结构

r - R align.time/aggregate 中的错误?