statistics - Contingency table in Python -
given 2 lists of equal length, how can construct contingency table in pythonic way? know confusion_matrix skit-learn, there 'manual' , effective ways that?
you can use pandas library create table shown in wikipedia example, so,
import pandas pd right_handed = [43, 44] left_handed = [9,4] df = pd.dataframe({'right': right_handed, 'left': left_handed}, index = ['males', 'females'])
this yields dataframe, so,
in [3]: print (df) left right males 9 43 females 4 44
you can use sum totals,
print (df.left.sum()) print (df.right.sum()) 13 87 in [7]: print (df.ix['males'].sum()) print (df.ix['females'].sum()) 52 48
Comments
Post a Comment