def _apply_impl(self, data): # TODO: generalize this to resample all fields (xyzuvwpq...) or # create a parameter to define which fields to process sklearn_model = self.algorithm_factory() X, y = sklearn_model.fit_resample(*data.Xy) applied = data.updated(self.transformations('a'), X=X, y=y) return Model(self, data, applied)
def _apply_impl(self, data): splitter_model = self.transformer.apply(data) applied = splitter_model.data.last_transformations_replaced( drop=self.transformer.size, transformation=self.transformations('a')[0]) return Model(self, data, applied, splitter_model=splitter_model)
def _apply_impl(self, data): from pjdata.specialdata import NoData if data is not NoData: raise Exception( 'Source component needs to be applied with NoData. ' 'Use Sink before it if needed.') return Model(self, NoData, self.data)
def _apply_impl(self, data): zeros = numpy.zeros(data.field(self.fields[0], self).shape[0]) partitions = list(self.algorithm.split(X=zeros, y=zeros)) applied = self._use_impl(data, partitions[self.partition][0], step='a') return Model(self, data, applied, indices=partitions[self.partition][1])
def apply(self, data: Union[type, Data] = NoData, exit_on_error=True): if data.isfrozen: return Model(self, data, data) if data.allfrozen: return Model(self, data, data.frozen) self._check_nodata(data, self) # Disable warnings, measure time and make the party happen. self._handle_warnings() # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv start = self._cpu() try: # Aqui, passa-se _exit_on_error para self de forma que # implementadores de conteineres possam acessar o valor # dentro de # _apply_impl e repassar aos contidos. TODO: Mesmo p/ max_time? self._exit_on_error = exit_on_error model = self._limit_by_time(function=self._apply_impl, data=data, max_time=self.max_time) # Check result type. if not isinstance(model, Model): raise Exception(f'{self.name} does not handle {type(model)}!') except Exception as e: self._handle_exception(e, exit_on_error) applied = data.updated(self.transformations('a'), failure=str(e), frozen=True) model = Model(self, data, applied) # TODO: é possível que um container não complete o try acima? # Caso sim, devemos gerar um ContainerModel aqui? # TODO: put time_spent inside data (as a "volatile" matrix)? time_spent = self._cpu() - start self._dishandle_warnings() # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ self._check_history(data, model.data, self.transformations('a')) return model
def _apply_impl(self, data): if data is not None: print('[apply] ', self._interpolate(self.text, data)) return Model(self, data, data)
def _apply_impl(self, data): applied = self._use_impl(data, step='a') return Model(self, data, applied)
def _apply_impl(self, data): sklearn_model = self.algorithm_factory() sklearn_model.fit(*data.Xy) return Model(self, data, data.frozen, sklearn_model=sklearn_model)
def _apply_impl(self, data): sklearn_model = self.algorithm_factory() sklearn_model.fit(*data.Xy) applied = self._use_impl(data, sklearn_model, step='a') return Model(self, data, applied, sklearn_model=sklearn_model)
def _apply_impl(self, data): return Model(self, data, data)
def _apply_impl(self, data): self._enforce_nodata(data, 'a') return Model(self, data, self.data)
def _apply_impl(self, data): sklearn_model = self.algorithm_factory(data.X.shape[1]) X_new = sklearn_model.fit_transform(*data.Xy) applied = data.updated(self.transformations('a'), X=X_new) return Model(self, data, applied, sklearn_model=sklearn_model)
def _apply_impl(self, data): from pjdata.specialdata import NoData return Model(self, data, NoData)
def _apply_impl(self, collection): applied = self._use_impl(collection) return Model(self, collection, applied)