本文整理汇总了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()
示例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")
示例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()
示例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)
'''
示例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
示例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)