-
Notifications
You must be signed in to change notification settings - Fork 28
[WIP][New Model] Dynamic Programming Decision Trees #176
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
Open
KohlerHECTOR
wants to merge
13
commits into
autogluon:main
Choose a base branch
from
KohlerHECTOR:dpdt-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8218de3
first commit to add dpdt
KohlerHECTOR 38d660f
Changed to AdaBoostDPDT to have compat with predict_proba
KohlerHECTOR 3738c81
Progress on BoostedDPDT; added memory estimate (estimators * dpdt tre…
KohlerHECTOR 250df43
added configs and registered model and tests
KohlerHECTOR 0534f8e
Fixed some typos
KohlerHECTOR c8f8df7
Fixed some cpus stuff
KohlerHECTOR 11324dc
updated with time limit
KohlerHECTOR 2ca10a3
Merge remote-tracking branch 'origin/main' into dpdt-model
LennartPurucker 2096a9b
maint: minor refactor and make test run
LennartPurucker 6dbe698
add: preprocessing for nan and cat handling
LennartPurucker 996e72d
add/fix: search space for HPO of dpdt
LennartPurucker ac10777
add: state after EBM rerun
LennartPurucker e070555
Merge remote-tracking branch 'origin/main' into dpdt-model
LennartPurucker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import numpy as np | ||
| from autogluon.core.models import AbstractModel | ||
|
|
||
| if TYPE_CHECKING: | ||
| import pandas as pd | ||
|
|
||
|
|
||
| class CustomRandomForestModel(AbstractModel): | ||
| ag_key = "DPDT" | ||
| ag_name = "dpdt" | ||
|
|
||
| def __init__(self, **kwargs): | ||
| super().__init__(**kwargs) | ||
| self._feature_generator = None | ||
|
|
||
| def _preprocess(self, X: pd.DataFrame, **kwargs) -> np.ndarray: | ||
| X = super()._preprocess(X, **kwargs) | ||
| return X.to_numpy() | ||
|
|
||
| def _fit( | ||
| self, | ||
| X: pd.DataFrame, # training data | ||
| y: pd.Series, # training labels | ||
| # X_val=None, # val data (unused in RF model) | ||
| # y_val=None, # val labels (unused in RF model) | ||
| # time_limit=None, # time limit in seconds (ignored in tutorial) | ||
| num_cpus: int = 1, # number of CPUs to use for training | ||
| # num_gpus: int = 0, # number of GPUs to use for training | ||
| **kwargs, # kwargs includes many other potential inputs, refer to AbstractModel documentation for details | ||
| ): | ||
| # Select model class | ||
| if self.problem_type in ["regression"]: | ||
| from dpdt import DPDTreeRegressor | ||
|
|
||
| model_cls = DPDTreeRegressor | ||
| else: | ||
| from dpdt import DPDTreeClassifier | ||
|
|
||
| # case for 'binary' and 'multiclass', | ||
| model_cls = DPDTreeClassifier | ||
|
|
||
| X = self.preprocess(X) | ||
| y = self.preprocess(y) | ||
| params = self._get_model_params() | ||
| self.model = model_cls(**params) | ||
| self.model.fit(X, y) | ||
|
|
||
| def _set_default_params(self): | ||
| """Default parameters for the model.""" | ||
| default_params = { | ||
| "max_depth": 10, | ||
| "n_jobs": -1, | ||
| "random_state": 0, | ||
| "cart_nodes_list": (8,3,) | ||
| } | ||
| for param, val in default_params.items(): | ||
| self._set_default_param_value(param, val) | ||
|
|
||
| def _get_default_auxiliary_params(self) -> dict: | ||
| """Specifics allowed input data and that all other dtypes should be handled | ||
| by the model-agnostic preprocessor. | ||
| """ | ||
| default_auxiliary_params = super()._get_default_auxiliary_params() | ||
| extra_auxiliary_params = { | ||
| "valid_raw_types": ["int", "float", "category"], | ||
| } | ||
| default_auxiliary_params.update(extra_auxiliary_params) | ||
| return default_auxiliary_params | ||
|
|
||
|
|
||
| # def get_configs_for_custom_rf( | ||
| # *, | ||
| # default_config: bool = True, | ||
| # num_random_configs: int = 1, | ||
| # sequential_fold_fitting: bool = False, | ||
| # ): | ||
| # """Generate the hyperparameter configurations to run for our custom random | ||
| # forest model. | ||
|
|
||
| # sequential_fold_fitting: bool = False | ||
| # If True, the model will be configured to use sequential | ||
| # fold fitting (better for debugging, but usually slower). This is also a good | ||
| # idea to use on SLURM or other shared compute clusters where you want to run | ||
| # multiple jobs on the same node. | ||
| # See `tabflow_slurm.run_tabarena_experiment.setup_slurm_job` for ways to | ||
| # optimally use sequential_fold_fitting=False on SLURM. | ||
| # """ | ||
| # from autogluon.common.space import Int | ||
| # from tabrepo.utils.config_utils import ConfigGenerator | ||
|
|
||
| # manual_configs = [ | ||
| # {}, | ||
| # ] | ||
| # search_space = { | ||
| # "n_estimators": Int(4, 50), | ||
| # } | ||
|
|
||
| # gen_custom_rf = ConfigGenerator( | ||
| # model_cls=CustomRandomForestModel, | ||
| # manual_configs=manual_configs if default_config else None, | ||
| # search_space=search_space, | ||
| # ) | ||
| # experiments_lst = gen_custom_rf.generate_all_bag_experiments( | ||
| # num_random_configs=num_random_configs | ||
| # ) | ||
|
|
||
| # if sequential_fold_fitting: | ||
| # for m_i in range(len(experiments_lst)): | ||
| # if ( | ||
| # "ag_args_ensemble" | ||
| # not in experiments_lst[m_i].method_kwargs["model_hyperparameters"] | ||
| # ): | ||
| # experiments_lst[m_i].method_kwargs["model_hyperparameters"][ | ||
| # "ag_args_ensemble" | ||
| # ] = {} | ||
| # experiments_lst[m_i].method_kwargs["model_hyperparameters"][ | ||
| # "ag_args_ensemble" | ||
| # ]["fold_fitting_strategy"] = "sequential_local" | ||
|
|
||
| # return experiments_lst | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.