扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

spaCy鎬庝箞缁樺埗PR鏇茬嚎

扬州沐宇科技
2024-05-11 17:50:54
spaCy

鍦╯paCy涓粯鍒禤R鏇茬嚎鍙互浣跨敤浠ヤ笅姝ラ锛?/p>

  1. 棣栧厛锛岀‘淇濅綘宸茬粡瀹夎浜嗗繀瑕佺殑搴擄紝鍖呮嫭spaCy銆乻cikit-learn鍜宮atplotlib銆傚鏋滆繕娌℃湁瀹夎锛屽彲浠ヤ娇鐢ㄤ互涓嬪懡浠よ繘琛屽畨瑁咃細
pip install spacy scikit-learn matplotlib
  1. 瀵煎叆蹇呰鐨勫簱锛?/li>
import spacy
from sklearn.metrics import precision_recall_curve
import matplotlib.pyplot as plt
  1. 鍔犺浇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]
  1. 浣跨敤scikit-learn鐨?code>precision_recall_curve鍑芥暟璁$畻PR鏇茬嚎鐨勭簿纭害鍜屽彫鍥炵巼锛?/li>
precision, recall, _ = precision_recall_curve(true_labels, predictions)
  1. 鏈€鍚庯紝浣跨敤matplotlib缁樺埗PR鏇茬嚎锛?/li>
plt.plot(recall, precision, marker='.')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.title('Precision-Recall curve')
plt.show()

杩欐牱灏卞彲浠ュ湪spaCy涓粯鍒禤R鏇茬嚎浜嗐€傝寰楁牴鎹綘鐨勫疄闄呮儏鍐佃皟鏁翠唬鐮佷腑鐨勬暟鎹拰鍙傛暟銆?/p>

扫码添加客服微信