我有兩個包含 Groundtruth 和 Predicted 標簽的資料框。假設我有 6 個班級標簽。假設這些資料框如下所示:
真相:
|0|0|0|0|1|1|1|2|2|3|3|3|4|4|4|5|5|5|5|5|5|5|
預料到的 :
|0|0|0|1|1|1|1|1|2|3|3|4|4|4|5|5|5|5|5|5|5|5|
如果動作開始的幀與分類器最終做出決策的幀之間的時間間隔為h,并且動作的總長度為H,則該動作的延遲定義為h/H。
這是一個解釋延遲的圖:

我想根據這兩個資料幀計算類的平均延遲。
這是我迄今為止嘗試過的:
groundtruth = pd.read_csv('groundtruth .csv', sep=",", header=None).transpose()
prediction = pd.read_csv('prediction .csv', sep=",", header=None).transpose()
average_latency=0
current_latency=0
changes_groundtruth = {}
changes_prediction = {}
for col in groundtruth.columns:
changes_groundtruth[col] = [0] [idx for idx, (i, j) in enumerate(zip(groundtruth[col], groundtruth[col][1:]), 1) if i != j]
for col in prediction.columns:
changes_prediction[col] = [0] [idx for idx, (i, j) in enumerate(zip(prediction[col], prediction[col][1:]), 1) if i != j]
for i in range(len(changes_groundtruth[0])):
for j in range(len(changes_prediction[0])):
if (changes_groundtruth[0][i] == changes_prediction[0][j]):
if (groundtruth[0].loc[i] == prediction[0].loc[j]):
current_latency = (changes_prediction[0][j] - changes_groundtruth[0][i])
elif (changes_groundtruth[0][i] < changes_prediction[0][j]):
if (groundtruth[0].loc[i] == prediction[0].loc[j]):
current_latency = (changes_prediction[0][j] - changes_groundtruth[0][i])
我不知道這是否正確。如何以最佳/正確的方式計算延遲?
uj5u.com熱心網友回復:
IIUC,并假設gt和pred該系列的資料:
gt = groundtruth[0]
pred = prediction[0]
您可以groupby在系列本身上使用并idxmin獲取第一個元素和sizeH的索引,其余的是簡單的算術:
g = gt.groupby(gt)
(pred.groupby(pred).idxmin()-g.idxmin())/g.size()
輸出:
0 0.000000
1 -0.333333
2 0.500000
3 0.000000
4 -0.333333
5 -0.142857
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/365299.html
