예제 #1
0
 def __init__(self, sklearn_cv_obj, **kwargs):
     
     splitrule = []
     for _, test in sklearn_cv_obj:
         splitrule+=[(None, test)]
         
     CustomPartitioner.__init__(self, splitrule, **kwargs)
예제 #2
0
 def test_gnbsearghlight_exclude_partition(self):
     # just a smoke test with a custom partitioner
     ds1 = datasets['3dsmall'].copy(deep=True)
     gnb_sl = GNBSearchlight(GNB(),
                             generator=CustomPartitioner([([0], [1])]),
                             qe=IndexQueryEngine(myspace=Sphere(2)),
                             errorfx=None)
     res = gnb_sl(ds1)
예제 #3
0
    def test_splitter_gnbsearghlight(self):
        ds1 = datasets['3dsmall'].copy(deep=True)

        gnb_sl = GNBSearchlight(GNB(),
                                generator=CustomPartitioner([([0], [1])]),
                                qe=IndexQueryEngine(myspace=Sphere(2)),
                                splitter=Splitter(attr='partitions',
                                                  attr_values=[1, 2]),
                                errorfx=None)
        res = gnb_sl(ds1)
        assert_equal(res.nsamples, (ds1.chunks == 1).sum())
예제 #4
0
    def test_gnbsearchlight_3partitions_and_splitter(self):
        ds = self.dataset[:, :20]
        # custom partitioner which provides 3 partitions
        part = CustomPartitioner([([2], [3], [1])])
        gnb_sl = sphere_gnbsearchlight(GNB(), part)
        res_gnb_sl = gnb_sl(ds)

        # compare results to full blown searchlight
        sl = sphere_searchlight(CrossValidation(GNB(), part))
        res_sl = sl(ds)

        assert_datasets_equal(res_gnb_sl, res_sl)

        # and theoretically for this simple single cross-validation we could
        # just use Splitter
        splitter = Splitter('chunks', [2, 3])
        # we have to put explicit None since can't become a kwarg in 1 day any
        # longer here
        gnb_sl_ = sphere_gnbsearchlight(GNB(), None, splitter=splitter)
        res_gnb_sl_ = gnb_sl_(ds)
        assert_datasets_equal(res_gnb_sl, res_gnb_sl_)
예제 #5
0
def get_partitioner(split_attr='group_split'):

    splitter = Splitter(attr='partitions', attr_values=(2, 3))

    if split_attr == 'group_split':

        splitrule = [
            # (leave, training, testing)
            (['3', '4'], ['1'], ['2']),
            (['3', '4'], ['2'], ['1']),
            (['1'], ['2'], ['3', '4']),
            (['2'], ['1'], ['3', '4']),
            (['1', '2'], ['3'], ['4']),
            (['1', '2'], ['4'], ['3']),
            (['3'], ['4'], ['1', '2']),
            (['4'], ['3'], ['1', '2']),
        ]
        partitioner = CustomPartitioner(splitrule=splitrule, attr=split_attr)

    elif split_attr == 'subject':

        partitioner = MemoryGroupSubjectPartitioner(group_attr='group_split',
                                                    subject_attr=split_attr,
                                                    attr=split_attr)

    elif split_attr == "group_mdm":
        partitioner = LeaveOneSubjectPerGroupPartitioner(
            group_attr='group', subject_attr="subject", attr="subject")

    elif split_attr == "subject_ofp":

        partitioner = partitioner = NFoldPartitioner(attr="subject")
        splitter = Splitter(attr="partitions")

    elif split_attr == 'group':

        partitioner = NFoldPartitioner(attr=split_attr)
        splitter = Splitter(attr='partitions')

    return partitioner, splitter