def __init__(self, dataframe, base_cv=None, **cv_kwargs):
# We create a copy of the dataframe with a new last level
# index which is an enumeration of the rows (like proper indices)
self.all_segments = pd.DataFrame({'Preictal': dataframe['Preictal'], 'i': np.arange(len(dataframe))})
self.all_segments.set_index('i', append=True, inplace=True)
# Now create a series with only the segments as rows. This is what we will pass into the wrapped cross
# validation generator
self.segments = self.all_segments['Preictal'].groupby(level='segment').first()
self.segments.sort(inplace=True)
if base_cv is None:
self.cv = cross_validation.StratifiedKFold(self.segments, **cv_kwargs)
else:
self.cv = base_cv(self.segments, **cv_kwargs)
评论列表
文章目录