concatenateクロス集計フレームgroupbyインデックス値はmeansです。
import numpy as np
import pandas as pd
# some random data frames
y_pred = np.random.randint(0, 2, 10)
y_test = np.random.randint(0, 2, 10)
cm1 = pd.crosstab(pd.Series(y_pred), pd.Series(y_test), rownames=['Predicted'], colnames=['Actual'], margins=True)
...
print(cm1)
Actual 0 1 All
Predicted
0 2 4 6
1 1 3 4
All 3 7 10
print(cm2)
Actual 0 1 All
Predicted
0 6 2 8
1 1 1 2
All 7 3 10
pandas.concat()最初の引数(パンダオブジェクトが連結される)としてシーケンスを取り、これは、リストやタプルを与えることによって、あなたは好きなだけを連結することができます。
Actual 0 1 All
Predicted
0 4 3 7
1 1 2 3
All 5 5 10
:に結果の
cm_concat = pd.concat((cm1, cm2))
cm_group = cm_concat.groupby(cm_concat.index)
cm_group.mean()