本文整理汇总了Python中classifier.Classifier.classification方法的典型用法代码示例。如果您正苦于以下问题:Python Classifier.classification方法的具体用法?Python Classifier.classification怎么用?Python Classifier.classification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classifier.Classifier
的用法示例。
在下文中一共展示了Classifier.classification方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeResult
# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import classification [as 别名]
def writeResult(writeFile, trainMatrix, trainLables, testMatrix, testLables, type):
result = open(writeFile, "a+")
result.write("-------Method\tPrecision-Recall-F1(1100 original text and gbdt)-------\n")
if type == 0:
trainMatrix, testMatrix = featureSelection(trainMatrix, trainLables, testMatrix)
classifierInstance = Classifier(trainMatrix, trainLables, testMatrix, testLables)
methods = ["tree", "knn", "svm", "essemble", "gbdt"]
for i in range(len(methods)):
key = methods[i]
classifierInstance.classification(key)
print key + "classification() done!"
dict = classifierInstance.evaluate()
for metric in dict:
result.write(key + "\t" + metric + "\t" + dict[metric] + "\n")
result.close()
示例2: eval_classifier
# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import classification [as 别名]
def eval_classifier(classifierToUse, featuresToUse, testOrTrain="train"):
print("Chosen feature: {0}".format(featuresToUse) )
print("Chosen classifier: {0}".format(classifierToUse))
fe = FeatureExtractor(featuresToUse)
dataset = DataSet(fe)
classifier = Classifier()
evaluate = Evaluation()
print "test or Train %s" % testOrTrain
for feature_class, files in getTestData(testOrTrain).items():
print "%s" % testOrTrain
for f in files:
dataset.addFile(feature_class, f)
print "Dataset initialized"
print_class_stats(dataset.classes)
print "Test set created."
a_train, a_test, c_train, c_test = train_test_split(dataset.featureVector, dataset.classes, test_size=0.9)
c_pred = classifier.classification(a_train,a_test,c_train,c_test,classifierToUse)
evaluate.evaluate(c_pred,c_test,featuresToUse,classifierToUse)