在spaCy中,可以使用evaluate()方法来评估文本分类器的性能。该方法需要传入一个可迭代的样本集,其中每个样本是一个元组,包含文本和标签。然后,该方法会返回一个包含性能指标的字典,包括准确率(accuracy)、精确率(precision)、召回率(recall)、F1值等。
下面是一个示例代码,演示如何使用evaluate()方法评估文本分类器的性能:
import spacy# 加载spaCy模型nlp = spacy.load("en_core_web_sm")# 准备样本集test_samples = [ ("This is a great movie", "POSITIVE"), ("I did not like this book", "NEGATIVE"), ("The weather is nice today", "NEUTRAL")]# 加载分类器textcat = nlp.get_pipe("textcat")# 评估性能evaluation_results = textcat.evaluate(test_samples)print(evaluation_results)运行该代码后,将会输出包含性能指标的字典,可以根据这些指标来评估文本分类器的性能。


