我正在做一些物流回歸作業。
我只是想知道在任何情況下,測驗集的評估指標是否比訓練集好一點(如下面的結果)?如果是,允許的差距是多少?
下面是我對測驗集和訓練集的評估結果,假設這兩個集都是從同一個資料集中提取的。
EVALUATION METRICS FOR Test Dataset:
Confusion Matrix:
Predicted Negative Predicted Positive
Actual Negative 82 20
Actual Positive 10 93
Accuracy = 0.8536585365853658
Precision = 0.8230088495575221
Recall = 0.9029126213592233
F1 score = 0.8380535530381049
EVALUATION METRICS FOR Training Dataset:
Confusion Matrix:
Predicted Negative Predicted Positive
Actual Negative 279 70
Actual Positive 44 324
Accuracy = 0.8410041841004184
Precision = 0.8223350253807107
Recall = 0.8804347826086957
F1 score = 0.8315648343229267
uj5u.com熱心網友回復:
通常情況并非如此,但這并非不可能。如果您將資料隨機拆分為測驗集和訓練集,在某些情況下,測驗資料比訓練資料更適合您的模型。想象一下下面的極端情況,您的資料由添加了不同級別噪聲的值組成。如果測驗資料點是噪聲較小的資料點,則它們將更好地擬合模型。但是,這種劃分為測驗和訓練資料的可能性很小。
如果測驗分數略高于訓練分數,這是絕對正常的。如果偶然地,模型未捕獲的噪聲在測驗資料中略低,則測驗樣本將更好地擬合模型。實際上這是一個好兆頭,因為這意味著你沒有過度擬合。您可以通過增加模型的自由度來提高整體性能。
如果測驗分數遠高于訓練分數,您應該檢查測驗資料和訓練之間的分割是否以合理的方式進行。

import numpy as np
import matplotlib.pyplot as plt
def f(x):
return 2*x 3
x_test = np.random.rand(30)
x_training = np.random.rand(70)
y_test = f(x_test) 1e-3 * np.random.randn(30)
y_training = f(x_training) 0.2 * np.random.randn(70)
k, d = np.polyfit(x_training, y_training, 1)
x = np.linspace(0, 1)
plt.plot(x_training, y_training, 'o', label='training data')
plt.plot(x_test, y_test, 'o', label='test data')
plt.plot(x, k*x d, 'k--', label='fitted model')
plt.plot(x, f(x), 'k:', label='real model')
plt.legend();
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/516936.html
上一篇:ValueError:形狀(None,3)和(None,2)不兼容
下一篇:dtreeviz框架的可視化問題
