2017-05-16 9 views
0

私は3つの別々の分類器を持っており、10倍のクロスバリデーションを行っています。 I出力(各実行/折り畳みのために)混同行列のような各時間:パンダ:とにかく、違う混乱行列を平均化するには?

cm = pd.crosstab(pd.Series(y_pred), pd.Series(y_test), rownames=['Predicted'], colnames=['Actual'], margins=True) 

私の質問があり、私は平均的な混同行列を作成することができます任意の方法はありますか?私はパンダをsklearnのcmよりむしろ使用しなければならない。

答えて

0

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() 

関連する問題