本文整理汇总了Python中Analyzer.Analyzer.getStats方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.getStats方法的具体用法?Python Analyzer.getStats怎么用?Python Analyzer.getStats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.getStats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Processor
# 需要导入模块: from Analyzer import Analyzer [as 别名]
# 或者: from Analyzer.Analyzer import getStats [as 别名]
class Processor(object):
def __init__(self, datafile='data.txt', statsNum=3):
self.analyzer = Analyzer()
self.classificator = Classificator()
self.datafile = datafile
self.statsNum = statsNum
def writeStats(self, files):
datafile = open(self.datafile, 'w')
for file in files:
ffts = self.analyzer.getFFTs(file)
stats = self.analyzer.getStats(ffts)
datafile.write(' '.join(str(x) for x in stats) + '\n')
datafile.close()
def normalize(self, data):
transposed = data.transpose()
meanVal = 1
for i in range(len(transposed)):
if i % self.statsNum == 0:
meanVal = np.mean(transposed[i])
transposed[i] /= meanVal
data = transposed.transpose()
return data
def cluster(self, files, clustersNum):
self.writeStats(files)
datafile = open(self.datafile)
data = datafile.split('\n')
data = np.array([[float(x) for x in row.split(' ')] for row in data[:-1]])
data = self.normalize(data)
net = self.classificator.newnet(clustersNum)
net.train(data, epochs=500)
result = net.sim(data)
self.classificator.savenet(net)
return self.classificator.getGroupedResult(result)
def classify(self, file):
ffts = self.analyzer.getFFTs(file)
stats = self.analyzer.getStats(ffts)
net = self.classificator.loadnet()
return net.sim(stats)