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


Python IOtools.todisc_matrix方法代码示例

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


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

示例1: report_results

# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import todisc_matrix [as 别名]
 def report_results(self):
     self.compute_precision()
     self.compute_recall()
     self.compute_fmeasure()
     self.compute_accuracy()
     
     IOtools.todisc_matrix(self.confusionmatrix, self.folder+os.sep+self.experimentname+".confmat")
     
     
     
     f = codecs.open(self.folder+os.sep+self.experimentname+".results", "a", encoding='utf8')
     # write report as list not to keep the whole string in memory
     header = "\t" + "\t".join(self.catmetrics.keys()) +"\n"
     f.write(header)
     
     labelencoding, _ = classfhelpers.classlabelindicing(self.classes)    # labeldecoding contains indices
     for c in self.classes:
         i = labelencoding[c]
         line = []
         line.append(c)
         for metricname in self.catmetrics.keys():
             line.append(self.catmetrics[metricname][i])
         line = map(lambda x : str(x), line)
         outstr = "\t".join(line) + "\n"
         f.write(outstr)
     f.write("\nAccuracy: "+str(self.accuracy))
     f.close()
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:29,代码来源:clsshell.py

示例2: buildcorpus

# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import todisc_matrix [as 别名]
def buildcorpus(nfile, ncat, resourcename, path):
    resourcepath = path + os.sep + resourcename
    catnames = IOtools.getfoldernames_of_dir(resourcepath)[:ncat]
    
    featurematrix = []
    doctermmatrix = []
    cfdTermDoc = nltk.ConditionalFreqDist()
    
    for catname in catnames:
        fileids = []
        p = resourcepath + os.sep + catname + os.sep
        fileids.extend(IOtools.getfilenames_of_dir(p, removeextension=False)[:nfile])
        corpus = CorpusFeatures(fileids, resourcename+os.sep+catname, p)
        corpus.getfeatures()
        datapoints = corpus.build_featurematrix()
        for k,v in datapoints.iteritems():
            featurematrix.append([k]+v+[resourcename])
            
        corpus.plot_features()
        
        #doc term matrix
        cfd = corpus.build_termmatrix()
        for fileid in cfd.conditions():
            for term in list(cfd[fileid]):
                cfdTermDoc[fileid].inc(term)
    
    IOtools.todisc_matrix(featurematrix, IOtools.results_rootpath+os.sep+"MATRIX"+str(nfile*ncat)+"texts.txt", mode="a")
开发者ID:dicleoztur,项目名称:tez0.1v,代码行数:29,代码来源:dataspace.py

示例3: classification_results

# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import todisc_matrix [as 别名]
def classification_results(experimentname, resultfile, classlabeldecoding):
    results = IOtools.readtextlines(IOtools.results_rootpath+os.sep+resultfile)
    
    numofpoints = int(results[1].split(":")[1])
    print results[2]," ",results[3],"  ",numofpoints
    predictions = results[3 : (numofpoints+3)]
    print len(predictions)
    confusionmatrix = np.zeros((len(classlabeldecoding), len(classlabeldecoding)))
    
    for i,prediction in enumerate(predictions):
        #items = prediction.split("\t")
        items = re.split(r"\s+", prediction)
        items = [str(item).strip() for item in items]
        predicted = items[0]
        actual = items[1]
        
        print i,"  ",prediction," ~~ ",items
        
        confusionmatrix[classlabeldecoding[predicted], classlabeldecoding[actual]] += 1
    
    IOtools.todisc_matrix(confusionmatrix.tolist(), IOtools.matrixpath+os.sep+experimentname+"ConfMat.m")
    
    
    # plot confusion matrix
    xitems = [0 for i in range(len(classlabeldecoding))]
    for k,v in classlabeldecoding.iteritems():
        xitems[v] = k
        
    
    classlabeldecoding.keys()
    colors = plotter._get_colors(confusionmatrix.shape[0])
    for k,v in classlabeldecoding.iteritems():
        plotter.plot_line(xitems, confusionmatrix[v, :], linelabel=k, clr=colors[v])
        print xitems," ",k,"  : ",v
    
    
    plotter.plot_line(xitems, confusionmatrix.diagonal().tolist(), linelabel="target", clr="k")
    plt.xlabel("actual")
    plt.ylabel("predicted")
    plt.legend()
    plt.savefig(IOtools.img_output+os.sep+experimentname+"ConfMat.png")
    plt.show()
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:44,代码来源:classification.py

示例4: add_resource_label

# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import todisc_matrix [as 别名]
if __name__ == "__main__":
    
    '''
    matrixpath = IOtools.matrixpath
    
    m1 = "featureMATRIX-3cat-testn-450texts.m"
    m2 = "featureMATRIX-3cat-trainn-4500texts.m"
    '''
    
    matrixpath = "/home/dicle/Dicle/Tez/output/CLASSTEST/"
    m1 = "t600.m"
    m2 = "t60.m"
    
    
    newmatrix1 = add_resource_label(matrixpath+os.sep+m1, "train", replacelabel=True)
    print newmatrix1
    
    IOtools.todisc_matrix(newmatrix1, matrixpath+os.sep+"labelresource"+m1)
    
    '''
    newmatrix2 = add_resource_label(matrixpath+os.sep+m2, "test", replacelabel=True)
    IOtools.todisc_matrix(newmatrix2, matrixpath+os.sep+"labelresource"+m2)
    '''
    
    
    
    
    
    
    
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:25,代码来源:matrixhandler.py

示例5: get_doc_NOUN_matrix

# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import todisc_matrix [as 别名]
 print docTermmatrix.shape
 
 
 '''
 for term in terms:        
     w, postag = SAKsParser.find_word_POStag(term)
     print w," ",postag
 '''
 #print matrix[rows-1,cols-10 : cols]
 
 
 nounmatrix, nouns = get_doc_NOUN_matrix(docTermmatrix, terms)
 print nounmatrix.shape
 
 outpath = "/home/dicle/Dicle/Tez/output/topicdetect/"
 IOtools.todisc_matrix(nounmatrix, outpath+os.sep+"nounmatrix60docs.m")
 
 nountfidfmatrix = find_tfidf(nounmatrix)
 IOtools.todisc_matrix(nountfidfmatrix, outpath+os.sep+"nounTFIDFmatrix60docs.m")
 
 lsa_tfidfmatrix = lsa_transform(nountfidfmatrix)
 lsa_occrmatrix = lsa_transform(nounmatrix)
 
 IOtools.todisc_matrix(lsa_tfidfmatrix, outpath+os.sep+"lsa_nounTFIDFmatrix60docs.m")
 IOtools.todisc_matrix(lsa_occrmatrix, outpath+os.sep+"lsa_doctermmatrix60docs.m")
 
 
 # get topic terms
 
 N = 10
 
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:32,代码来源:termanalysis.py

示例6: record_matrix

# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import todisc_matrix [as 别名]
 def record_matrix(self, matrix, mname):
     fname = IOtools.matrixpath+os.sep+mname+"-"+self.spacename+"MATRIX.m"
     IOtools.todisc_matrix(matrix, fname)
开发者ID:dicleoztur,项目名称:tez0.1v,代码行数:5,代码来源:dataspace.py


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