spaCy鎬庝箞缁樺埗PR鏇茬嚎
鍦╯paCy涓粯鍒禤R鏇茬嚎鍙互浣跨敤浠ヤ笅姝ラ锛?/p>
- 棣栧厛锛岀‘淇濅綘宸茬粡瀹夎浜嗗繀瑕佺殑搴擄紝鍖呮嫭spaCy銆乻cikit-learn鍜宮atplotlib銆傚鏋滆繕娌℃湁瀹夎锛屽彲浠ヤ娇鐢ㄤ互涓嬪懡浠よ繘琛屽畨瑁咃細
pip install spacy scikit-learn matplotlib
- 瀵煎叆蹇呰鐨勫簱锛?/li>
import spacy
from sklearn.metrics import precision_recall_curve
import matplotlib.pyplot as plt
- 鍔犺浇spaCy妯″瀷骞惰幏鍙栭娴嬬粨鏋滃拰鐪熷疄鏍囩锛?/li>
nlp = spacy.load("en_core_web_sm")
texts = ["Some text", "Another text"]
true_labels = [True, False]
predictions = [nlp(text).cats["LABEL"] > 0.5 for text in texts]
- 浣跨敤scikit-learn鐨?code>precision_recall_curve鍑芥暟璁$畻PR鏇茬嚎鐨勭簿纭害鍜屽彫鍥炵巼锛?/li>
precision, recall, _ = precision_recall_curve(true_labels, predictions)
- 鏈€鍚庯紝浣跨敤matplotlib缁樺埗PR鏇茬嚎锛?/li>
plt.plot(recall, precision, marker='.')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.title('Precision-Recall curve')
plt.show()
杩欐牱灏卞彲浠ュ湪spaCy涓粯鍒禤R鏇茬嚎浜嗐€傝寰楁牴鎹綘鐨勫疄闄呮儏鍐佃皟鏁翠唬鐮佷腑鐨勬暟鎹拰鍙傛暟銆?/p>