当前位置: 首页>>代码示例>>Python>>正文


Python Classifier.learn方法代码示例

本文整理汇总了Python中Classifier.Classifier.learn方法的典型用法代码示例。如果您正苦于以下问题:Python Classifier.learn方法的具体用法?Python Classifier.learn怎么用?Python Classifier.learn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Classifier.Classifier的用法示例。


在下文中一共展示了Classifier.learn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import learn [as 别名]
class Processor:

    def __init__(self,files,chanNum):
        self.signal = []
        self.stimulusCode = []
        self.phaseInSequence = []
        self.targetLetters = []
        self.firsttrain = 1
        self.cl = Classifier()
        self.sf = SpatialFilter(chanNum)
        self.rate = 0
        self.files = files
        self.chanNum = chanNum

    # Z cisla trenovacieho znaku urci jeho poziciu v speller matici
    def getCharIndexes (self,num):
        output = []
        #row index
        output.append((num/6)+6)
        #col index
        output.append(num % 6)
        return output


    # Pomocou opisneho pola phaseInSequence zisti na akych indexoch su prechody medzi cielovymi znakmi
    def findCharEnds (self):
        # najdi prechody medzi pismenami na ktore pouzivatel mysli (len pre dataset)
        charEnds = []
        for i in range (len(self.phaseInSequence)):
            if self.phaseInSequence[i] == 3 and self.phaseInSequence[i-1] == 2:
                tmp = (int)(i/12)
                #tmp = i
                charEnds.append(tmp)
        return charEnds

    # Transformuje list dat na numpy array
    def prepairSignalArray (self,finalData):
        converted = []
        for i in range(len(finalData)):
            converted.append(np.array(finalData[i]))

        return np.array(converted)

    # Vytvorenie znackovacieho pola pre IsiBinList - hovori ci dane vysvietenia zodpovedali cielovemu znaku
    def prepairTargetArray (self,targIndexes, isiCount = 12):
        output = []
        for i in range(isiCount):
            if i in targIndexes:
                output.append(1)
            else:
                output.append(0)

        return np.array(output)

    # Metoda trenuje klasifikator a updatuje pouzivatelske rozhranie
    def trainClassifier(self, trainLetter, progress, progLab, maxSets):

        # nacitanie a predspracovanie signalu
        signalLoader = SignalLoader(self.chanNum,self.files)
        prpr = Preprocessor(self.chanNum,[])
        signal,stimCode,phaseInSequence = signalLoader.loadSignal()
        self.signal = prpr.preprocess(240,1E-1,30E0,self.sf,signal,stimCode,phaseInSequence,0)
        self.stimulusCode = prpr.stimulusCode
        self.phaseInSequence = prpr.phaseInSequence
        self.targetLetters = sum(trainLetter,[])

        # najdenie prechodov medzi znakmi
        charEnds = self.findCharEnds()

        # rozdelenie dat do epoch
        em = EpochManager(self.signal,self.stimulusCode,self.phaseInSequence)
        isiList = em.createEpochs()

        # trening jednotlivych znakov
        for i in range(len(charEnds)):
            progress["value"] = i
            progLab["text"] = ("Trénujem znak: {}/{}").format(i+1, len(charEnds))
            print "Averaging character:",i,"\n"
            hi = charEnds[i]
            if i == 0:
                lo = 0
            else:
                lo = charEnds[i-1]

            rowColBinList = em.getAveragedEpochs(hi,lo,isiList,maxSets)
            finalDataArray = rowColBinList
            classMarks = self.prepairTargetArray(self.getCharIndexes(self.targetLetters[i]))

            if self.firsttrain == 1:
                self.cl.learn(finalDataArray,classMarks,0)
                self.firsttrain = 0
            else:
                self.cl.learn(finalDataArray,classMarks)

    # Metoda hada cielove znaky a updatuje pouzivatelske rozhranie
    def guessChars(self,subset,files,targetLetter,testProgress,progTestLabel,guessView,guessLab,maxSets):
        aktCharNum = 0
        totalChars = len(sum(targetLetter,[]))

        if self.chanNum != 64:
#.........这里部分代码省略.........
开发者ID:BergiSK,项目名称:Bakalarka,代码行数:103,代码来源:Processor.py


注:本文中的Classifier.Classifier.learn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。