OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
BaggingColumnTransformer.py
Go to the documentation of this file.
1 from ._CustomTransformer import _CustomTransformer
2 
3 import numpy as np
4 
5 
7  '''
8  Randomly select a percentage of columns to drop, always keeping the
9  band features (first n_bands columns). Optionally, the last n_extra
10  columns will also be always kept as additional features.
11  '''
12 
13  def __init__(self, n_bands, *args, n_extra=0, percent=0.75, seed=None, **kwargs):
14  self.n_bands = n_bands
15  self.n_extra = n_extra
16  self.percent = percent
17  self.random = np.random.RandomState(seed)
18 
19  def _fit(self, X, *args, **kwargs):
20  shp = X.shape[1] - self.n_bands
21  ncol = int(shp*self.percent)
22  cols = np.arange(shp-self.n_extra) + self.n_bands
23  self.random.shuffle(cols)
24  new_cols = list(cols[:ncol])
25  if self.n_extra: new_cols += list(X.shape[1]-(np.arange(self.n_extra)+1))
26  self.cols = np.append(np.arange(self.n_bands), new_cols, 0)
27  # print(f'Reducing bands from {shp} ({X.shape[1]} total) to {ncol} ({len(self.cols)} total) ({self.cols})')
28 
29  def _transform(self, X, *args, **kwargs):
30  return X[:, self.cols.astype(int)]
def __init__(self, n_bands, *args, n_extra=0, percent=0.75, seed=None, **kwargs)
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7