Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom TimeseriesGenerator for LSTM #1129

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions gordo/data_frame_mapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging
import sklearn_pandas

from copy import copy
from sklearn.base import BaseEstimator
from typing import List, Union, Optional

logger = logging.getLogger(__name__)


class DataFrameMapper(sklearn_pandas.DataFrameMapper):
_default_kwargs = {"df_out": True}

def __init__(
self,
columns: List[Union[str, List[str]]],
transformers: Optional[List[BaseEstimator]] = None,
**kwargs
):
self.columns = columns
self.transformers = transformers
features = self._build_features(columns, transformers)
base_kwargs = copy(self._default_kwargs)
base_kwargs.update(kwargs)
super().__init__(features=features, **base_kwargs)

@staticmethod
def _build_features(
columns: List[Union[str, List[str]]],
transformers: Optional[List[BaseEstimator]],
):
features = []
for column in columns:
features.append((column, transformers))
return features

def __getstate__(self):
state = super().__getstate__()
state["columns"] = self.columns
state["transformers"] = self.transformers
del state["features"]
return state

def __setstate__(self, state):
features = self._build_features(state.get("columns"), state.get("transformers"))
state["features"] = features
super().__setstate__(state)


__all__ = ["DataFrameMapper"]
Loading