Exemplo n.º 1
0
    def get_feature_frames_or_fetch(self, df, symbol, features_and_labels):
        fkey = f'{symbol}__features'

        # note! features can be a MultiFrameDecorator !!
        if isinstance(features_and_labels.features, tuple):
            fkeys = [
                f'{symbol}__features__{i}'
                for i in range(len(features_and_labels.features))
            ]
            features = [
                self.file_cache[fkey] for fk in self.file_cache if fk in fkeys
            ]

            if len(features) == len(fkeys):
                features = MultiFrameDecorator(features)
            else:
                features, _, _ = extract_features(df, features_and_labels)
                for fk, f in zip(fkeys, features.frames()):
                    self.file_cache[fk] = f
        else:
            if fkey in self.file_cache:
                features = self.file_cache[fkey]
            else:
                print(f"fetch data for: {symbol}")
                features, _, _ = extract_features(df, features_and_labels)
                self.file_cache[fkey] = features

        return features._.values, features.index
Exemplo n.º 2
0
    def get_feature_frames_or_fetch(
            self, df, symbol,
            features_and_labels) -> Tuple[np.ndarray, pd.Index]:
        if symbol not in self.features:
            features, _, _ = extract_features(df, features_and_labels)
            self.features[symbol] = (features._.values, features.index)

        return self.features[symbol]
Exemplo n.º 3
0
    def get_feature_frames_or_fetch(
            self, df, symbol,
            features_and_labels) -> Tuple[np.ndarray, pd.Index]:
        _, features, self._targets = extract_features(df, features_and_labels)
        features_index = features.index
        features = features._.values

        return features, features_index