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

refactor: Add Modeler classes for Oracles #137

Merged
merged 3 commits into from
Mar 10, 2022

Conversation

nhanitvn
Copy link
Contributor

@nhanitvn nhanitvn commented Mar 4, 2022

  • Add Modeler classes
  • Refactor code to build/train Oracles
  • Use H1st Predictive Model for ensembling Students and Teacher's output instead of the general H1st StackEnsemble
  • Test cases passed

@nhanitvn nhanitvn requested a review from TgithubJ March 4, 2022 18:58
h1st/model/oracle/oracle_modeler.py Outdated Show resolved Hide resolved
h1st/model/oracle/oracle_modeler.py Outdated Show resolved Hide resolved
self.stats = {}

def generate_features(self, data: Dict):
@classmethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nhanitvn Did you use @classmethod here because you need to use this method in OracleModeler without instantiating Oracle class ? I am not sure if this is the best option. Have you thought about using @staticmethod ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know any benefit of using @classmethod if it is not factory method.

Copy link
Contributor Author

@nhanitvn nhanitvn Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benefit is that you can override generate_features() in Oracle's subclasses and have the overridden one called instead :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it.

@@ -127,25 +119,22 @@ def predict(self, input_data: Dict) -> Dict:
raise RuntimeError('No student built')

# Generate features to get students' predictions
predict_data = self.generate_data(input_data)
predict_data = self.__class__.generate_data(input_data, self.teacher, self.stats)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make generate_data a staticmethod, then this will look more beautiful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ugly here. However, the classmethod benefit the build_model(). Check TimeseriesOracleModeler and you see that we don't need to re-implement build_model(). With static method, you cannot do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it

@TgithubJ TgithubJ merged commit 504c2ee into h1st-ai:main Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants