示例#1
0
                            random_state=12,
                            verbose=False)
for tr, vl in SKF.split(X=None, y=y):
    print(tr, vl)

###############################################################################
# .. note::
#    Split is made to generate each fold

# Show label

for tr, vl in SKF.split(X=None, y=y):
    print(y[tr], y[vl])

##############################################################################
# .. note::
#    The first one is made with polygon only.
#    When learning/predicting, all pixels will be taken in account
#    TO generate a full X and y labels, extract samples from ROI

X, y = processing.extract_ROI(raster, vector, field)

for tr, vl in SKF.split(X, y):
    print(tr, vl)
    print(tr.shape, vl.shape)

##########################
# Plot example
from __drawCVmethods import plotMethod
plotMethod('SKF-pixel')
# Load HistoricalMap dataset
# -------------------------------------------

raster, vector = datasets.historicalMap(low_res=True)
field = 'Class'
X, y = raster_tools.getSamplesFromROI(raster, vector, field)
distanceMatrix = vector_tools.getDistanceMatrix(raster, vector)

##############################################################################
# Create CV
# -------------------------------------------
# n_splits will be the number  of the least populated class

SLOPO = SpatialLeaveOneOut(distanceThresold=100,
                           distanceMatrix=distanceMatrix,
                           random_state=12)

print(SLOPO.get_n_splits(X, y))

###############################################################################
# .. note::
#    Split is made to generate each fold

for tr, vl in SLOPO.split(X, y):
    print(tr.shape, vl.shape)

#############################################
# Draw image
from __drawCVmethods import plotMethod
plotMethod('SLOO-pixel')
示例#3
0
# Create CV
# -------------------------------------------
# if n_splits is False (default), the number of splits will be the smallest
# number of subgroup of all labels.

valid_size = 0.5  # Means 50%
LOSGO = LeaveOneSubGroupOut(verbose=False, random_state=12)  #

###############################################################################
# .. note::
#    Split is made to generate each fold

LOSGO.get_n_splits(X, y, s)
for tr, vl in LOSGO.split(X, y, s):
    print(tr.shape, vl.shape)

###############################################################################
# Differences with sklearn
# -------------------------------------------
# Sklearn do not use subgroups (only groups), so no hierarchical dependances.

from sklearn.model_selection import LeaveOneGroupOut
LOGO = LeaveOneGroupOut()
for tr, vl in LOGO.split(X=X, y=y, groups=s):
    print(tr.shape, vl.shape)

###############################################################################
# Plot example
from __drawCVmethods import plotMethod
plotMethod('LOO-group')
示例#4
0
    print(tr.shape, vl.shape)

print('y label with number of samples')
print(np.unique(y[tr], return_counts=True))
##############################################################################
# Differences with scikit-learn
# -------------------------------------------
from sklearn.model_selection import LeavePGroupsOut
# You need to specify the number of groups

LPGO = LeavePGroupsOut(n_groups=2)
for tr, vl in LPGO.split(X, y, g):
    print(tr.shape, vl.shape)

##############################################################################
# With GroupShuffleSplit, won't keep the percentage per subgroup
# This generate unbalanced classes

from sklearn.model_selection import GroupShuffleSplit
GSS = GroupShuffleSplit(test_size=0.5, n_splits=2)
for tr, vl in GSS.split(X, y, g):
    print(tr.shape, vl.shape)

print('y label with number of samples')
print(np.unique(y[tr], return_counts=True))

###############################################################################
# Plot example in image
from __drawCVmethods import plotMethod
plotMethod('SKF-group')