1212# along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
1414# experiments.py
15- # Copyright (C) 2014-2016 Fracpete (pythonwekawrapper at gmail dot com)
15+ # Copyright (C) 2014-2022 Fracpete (pythonwekawrapper at gmail dot com)
1616
1717import logging
1818import javabridge
@@ -622,7 +622,7 @@ class Tester(OptionHandler):
622622 For generating statistical results from an experiment.
623623 """
624624
625- def __init__ (self , classname = "weka.experiment.PairedCorrectedTTester" , jobject = None , options = None ):
625+ def __init__ (self , classname = "weka.experiment.PairedCorrectedTTester" , jobject = None , options = None , swap_rows_and_cols = False ):
626626 """
627627 Initializes the specified tester using either the classname or the supplied JB_Object.
628628
@@ -632,17 +632,41 @@ def __init__(self, classname="weka.experiment.PairedCorrectedTTester", jobject=N
632632 :type jobject: JB_Object
633633 :param options: the list of commandline options to set
634634 :type options: list
635+ :param swap_rows_and_cols: whether to swap rows/columns, to compare datasets rather than classifiers
636+ :type swap_rows_and_cols: bool
635637 """
636638 if jobject is None :
637639 jobject = Tester .new_instance (classname )
638640 self .enforce_type (jobject , "weka.experiment.Tester" )
639641 self .columns_determined = False
640- self ._dataset_columns = ["Key_Dataset" ]
641642 self ._run_column = "Key_Run"
642643 self ._fold_column = "Key_Fold"
644+ self ._swap_rows_and_cols = swap_rows_and_cols
645+ self ._dataset_columns = ["Key_Dataset" ]
643646 self ._result_columns = ["Key_Scheme" , "Key_Scheme_options" , "Key_Scheme_version_ID" ]
644647 super (Tester , self ).__init__ (jobject = jobject , options = options )
645648
649+ @property
650+ def swap_rows_and_cols (self ):
651+ """
652+ Returns whether to swap rows/cols.
653+
654+ :return: whether to swap
655+ :rtype: bool
656+ """
657+ return self ._swap_rows_and_cols
658+
659+ @swap_rows_and_cols .setter
660+ def swap_rows_and_cols (self , swap ):
661+ """
662+ Sets whether to swap rows/cols.
663+
664+ :param swap: whether to swap
665+ :type swap: bool
666+ """
667+ self .columns_determined = False
668+ self ._swap_rows_and_cols = swap
669+
646670 @property
647671 def resultmatrix (self ):
648672 """
@@ -780,11 +804,18 @@ def init_columns(self):
780804 print ("No instances set, cannot determine columns!" )
781805 return
782806
807+ if self .swap_rows_and_cols :
808+ dataset_columns = self .result_columns
809+ result_columns = self .dataset_columns
810+ else :
811+ dataset_columns = self .dataset_columns
812+ result_columns = self .result_columns
813+
783814 # dataset
784- if self . dataset_columns is None :
815+ if dataset_columns is None :
785816 raise Exception ("No dataset columns set!" )
786817 cols = ""
787- for name in self . dataset_columns :
818+ for name in dataset_columns :
788819 att = data .attribute_by_name (name )
789820 if att is None :
790821 raise Exception ("Dataset column not found: " + name )
@@ -814,10 +845,10 @@ def init_columns(self):
814845 self .jobject , "setFoldColumn" , "(I)V" , index )
815846
816847 # result
817- if self . _result_columns is None :
818- raise Exception ("No reset columns set!" )
848+ if result_columns is None :
849+ raise Exception ("No result columns set!" )
819850 cols = ""
820- for name in self . _result_columns :
851+ for name in result_columns :
821852 att = data .attribute_by_name (name )
822853 if att is None :
823854 raise Exception ("Result column not found: " + name )
0 commit comments