数字中的模式识别?

问题描述 投票:0回答:1

考虑输入文件是

25 27 29 25 27 29 25 27 29 25 27 29 25 27 28 

我想提取模式 25 27 29。我可以使用哪些算法来挖掘这样的序列中的模式?我愿意使用无监督学习技术来实现它。

pattern-matching text-mining
1个回答
0
投票

这个问题很难回答,因为模式和提取可能意味着不同的事情:

您的

pattern
包括数字之间的空格,还是仅包括数字本身的列表?图案到底是
25 27 29
还是
n n+2 n+4

extract
是指找到位置吗?将其从列表中删除?

因此,没有算法或技术,因为很难理解你愿意做什么。

以 Python 风格和非常通用的方式(您可以用整数替换

a
b
c
并使列表更长),您可以选择 :

list = [25, 27, 29, 25, 27, 29, 25, 27, 29, 25, 27, 29, 25, 27, 28]
ptn = [a, b, c]
position = []

for i, nb in enumerate(list):
    if i != len(list) - len(pattern);
         if nb == ptn[i] and list[i+1] == ptn[i+1] and list[i+2] == ptn[i+2]:
               position.append(i)
© www.soinside.com 2019 - 2024. All rights reserved.