Last active
July 31, 2022 20:43
-
-
Save kylegallatin/35d62a0e7e0524a87ad5815dbe54c7e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterable, Callable, Dict | |
class SuperSimpleFeatureStore: | |
def __init__(self, dataframe: pd.DataFrame): | |
self.dataframe = dataframe | |
self.feature_dict = dataframe.set_index("user_id").T.to_dict() | |
def register_feature(self, name: str, feature_definition: Callable) -> None: | |
for key in self.feature_dict: | |
self.feature_dict[key][name] = feature_definition(self.feature_dict[key]) | |
def get_user_feature(self, user_id: str) -> Dict: | |
return self.feature_dict.get(user_id) | |
def get_all_data(self) -> pd.DataFrame: | |
return pd.DataFrame(self.feature_dict).T |
@anuran-roy thanks for bringing it up! The gists were copied directly from the notebook here that's meant to be runnable e2e - but you're right that as a standalone gist keeping those things as global variables isn't very useful. I'll update it!
Oh but that is actually just a straight up error, using the constructor argument on one line and a previously defined variable on another. Thanks for bringing it up! I've fixed it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @kylegallatin I came across your post on Medium today! Great tutorial, thanks a lot for clearing up how ML works for production!
That said, I think there might be an error in line 7. I actually don't see any
user_data
variable declared or initialized before this occurence. 😅