![](/img/trans.png)
[英]How to determine accuracy, precision and recall from two DataFrames that has different row numbers in python?
[英]different results in calculating recall and precision from two different methods
按照下面的代碼,我正在計算特定分類器的召回率和精度得分
clf = GradientBoostingClassifier(n_estimators=20)
clf.fit(X_train,y_train)
pred=clf.predict(X_test)
precision_recall_fscore_support(y_test, pred, average='micro' or, 'weighted', or, 'macro', or 'none')
那么結果將是
(0.8861803737814977, 0.8714028776978417, 0.8736586610015085, None)
(0.8714028776978417, 0.8714028776978417, 0.8714028776978417, None)
(0.8576684989847967, 0.883843537414966, 0.8649539913120651, None)
(array([0.95433071, 0.76100629]),
array([0.84166667, 0.92602041]),
array([0.89446494, 0.83544304]),
array([720, 392]))
但是如果我用
clf = GradientBoostingClassifier()
skf = StratifiedKFold(n_splits=10)
param_grid = {'n_estimators':range(20,23)}
grid_search = GridSearchCV(clf, param_grid, scoring=scorers, refit=recall_score,
cv=skf, return_train_score=True, n_jobs=-1)
results = pd.DataFrame(grid_search_clf.cv_results_)
然后我會得到下表
您可以看到,平均召回率和精確度得分與上一步中計算出的得分和准確性得分有很大不同,而相同參數的相同數據已應用於這兩者。 我想知道是否有人可以幫助我做錯了什么
好吧,指標是根據不同的事物計算的。
precision_recall_fscore_support(y_test, pred)
在測試數據上顯示指標的值。
但是,當您使用GridSearchCV時,訓練數據將按照定義的cv分為訓練和測試,並根據該測試數據(這是訓練數據的子集)計算指標。 然后對指標進行平均。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.