def test_LeavePSubGroupOut(self):

        cv = cross_validation.LeavePSubGroupOut(verbose=2)
        for tr, vl in cv.split(X, y, g):
            assert (not np.unique(np.in1d([1, 2], [3, 4]))[0])

        self.assertRaises(ValueError,
                          cross_validation.LeavePSubGroupOut,
                          valid_size='ko')
        self.assertRaises(ValueError,
                          cross_validation.LeavePSubGroupOut,
                          valid_size=5.1)
예제 #2
0
field = 'Class'
group = 'uniquefid'
X, y, g = extract_ROI(raster, vector, field, group)
##############################################################################
# Initialize Random-Forest
# ---------------------------

classifier = RandomForestClassifier(random_state=12, n_jobs=1)

##############################################################################
# Create list of different CV
# ---------------------------

CVs = [
    cross_validation.RandomStratifiedKFold(n_splits=2),
    cross_validation.LeavePSubGroupOut(valid_size=0.5),
    cross_validation.LeaveOneSubGroupOut(),
    StratifiedKFold(n_splits=2, shuffle=True)  #from sklearn
]

kappas = []

for cv in CVs:
    SL = SuperLearner(classifier=classifier,
                      param_grid=dict(n_estimators=[50, 100]),
                      n_jobs=1)
    SL.fit(X, y, group=g, cv=cv)
    print('Kappa for ' + str(type(cv).__name__))
    cvKappa = []

    for stats in SL.get_stats_from_cv(confusion_matrix=False, kappa=True):