mirror of
https://github.com/microsoft/FLAML.git
synced 2026-02-09 02:09:16 +08:00
Fix isinstance usage issues (#1488)
* Fix isinstance usage issues * Pin python version to 3.12 for pre-commit * Update mdformat to 0.7.22
This commit is contained in:
@@ -36,7 +36,7 @@ repos:
|
|||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
- repo: https://github.com/executablebooks/mdformat
|
- repo: https://github.com/executablebooks/mdformat
|
||||||
rev: 0.7.17
|
rev: 0.7.22
|
||||||
hooks:
|
hooks:
|
||||||
- id: mdformat
|
- id: mdformat
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ This repository incorporates material as listed below or described in the code.
|
|||||||
|
|
||||||
## Component. Ray.
|
## Component. Ray.
|
||||||
|
|
||||||
Code in tune/\[analysis.py, sample.py, trial.py, result.py\],
|
Code in tune/[analysis.py, sample.py, trial.py, result.py],
|
||||||
searcher/\[suggestion.py, variant_generator.py\], and scheduler/trial_scheduler.py is adapted from
|
searcher/[suggestion.py, variant_generator.py], and scheduler/trial_scheduler.py is adapted from
|
||||||
https://github.com/ray-project/ray/blob/master/python/ray/tune/
|
https://github.com/ray-project/ray/blob/master/python/ray/tune/
|
||||||
|
|
||||||
## Open Source License/Copyright Notice.
|
## Open Source License/Copyright Notice.
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ FLAML has a .NET implementation in [ML.NET](http://dot.net/ml), an open-source,
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
The latest version of FLAML requires **Python >= 3.10 and \< 3.13**. While other Python versions may work for core components, full model support is not guaranteed. FLAML can be installed via `pip`:
|
The latest version of FLAML requires **Python >= 3.10 and < 3.13**. While other Python versions may work for core components, full model support is not guaranteed. FLAML can be installed via `pip`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install flaml
|
pip install flaml
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ If you believe you have found a security vulnerability in any Microsoft-owned re
|
|||||||
|
|
||||||
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
|
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
|
||||||
|
|
||||||
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
|
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
|
||||||
|
|
||||||
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
|
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
|
||||||
|
|
||||||
|
|||||||
@@ -311,14 +311,14 @@ def get_y_pred(estimator, X, eval_metric, task: Task):
|
|||||||
else:
|
else:
|
||||||
y_pred = estimator.predict(X)
|
y_pred = estimator.predict(X)
|
||||||
|
|
||||||
if isinstance(y_pred, Series) or isinstance(y_pred, DataFrame):
|
if isinstance(y_pred, (Series, DataFrame)):
|
||||||
y_pred = y_pred.values
|
y_pred = y_pred.values
|
||||||
|
|
||||||
return y_pred
|
return y_pred
|
||||||
|
|
||||||
|
|
||||||
def to_numpy(x):
|
def to_numpy(x):
|
||||||
if isinstance(x, Series or isinstance(x, DataFrame)):
|
if isinstance(x, (Series, DataFrame)):
|
||||||
x = x.values
|
x = x.values
|
||||||
else:
|
else:
|
||||||
x = np.ndarray(x)
|
x = np.ndarray(x)
|
||||||
@@ -586,7 +586,7 @@ def _eval_estimator(
|
|||||||
|
|
||||||
# TODO: why are integer labels being cast to str in the first place?
|
# TODO: why are integer labels being cast to str in the first place?
|
||||||
|
|
||||||
if isinstance(val_pred_y, Series) or isinstance(val_pred_y, DataFrame) or isinstance(val_pred_y, np.ndarray):
|
if isinstance(val_pred_y, (Series, DataFrame, np.ndarray)):
|
||||||
test = val_pred_y if isinstance(val_pred_y, np.ndarray) else val_pred_y.values
|
test = val_pred_y if isinstance(val_pred_y, np.ndarray) else val_pred_y.values
|
||||||
if not np.issubdtype(test.dtype, np.number):
|
if not np.issubdtype(test.dtype, np.number):
|
||||||
# some NLP models return a list
|
# some NLP models return a list
|
||||||
|
|||||||
@@ -25,9 +25,7 @@ def load_default_huggingface_metric_for_task(task):
|
|||||||
|
|
||||||
|
|
||||||
def is_a_list_of_str(this_obj):
|
def is_a_list_of_str(this_obj):
|
||||||
return (isinstance(this_obj, list) or isinstance(this_obj, np.ndarray)) and all(
|
return isinstance(this_obj, (list, np.ndarray)) and all(isinstance(x, str) for x in this_obj)
|
||||||
isinstance(x, str) for x in this_obj
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _clean_value(value: Any) -> str:
|
def _clean_value(value: Any) -> str:
|
||||||
|
|||||||
@@ -37,10 +37,9 @@ class SearchState:
|
|||||||
if isinstance(domain_one_dim, sample.Domain):
|
if isinstance(domain_one_dim, sample.Domain):
|
||||||
renamed_type = list(inspect.signature(domain_one_dim.is_valid).parameters.values())[0].annotation
|
renamed_type = list(inspect.signature(domain_one_dim.is_valid).parameters.values())[0].annotation
|
||||||
type_match = (
|
type_match = (
|
||||||
renamed_type == Any
|
renamed_type is Any
|
||||||
or isinstance(value_one_dim, renamed_type)
|
or isinstance(value_one_dim, renamed_type)
|
||||||
or isinstance(value_one_dim, int)
|
or (renamed_type is float and isinstance(value_one_dim, int))
|
||||||
and renamed_type is float
|
|
||||||
)
|
)
|
||||||
if not (type_match and domain_one_dim.is_valid(value_one_dim)):
|
if not (type_match and domain_one_dim.is_valid(value_one_dim)):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -386,9 +386,8 @@ class TimeSeriesTask(Task):
|
|||||||
return X
|
return X
|
||||||
|
|
||||||
def preprocess(self, X, transformer=None):
|
def preprocess(self, X, transformer=None):
|
||||||
if isinstance(X, pd.DataFrame) or isinstance(X, np.ndarray) or isinstance(X, pd.Series):
|
if isinstance(X, (pd.DataFrame, np.ndarray, pd.Series)):
|
||||||
X = X.copy()
|
X = normalize_ts_data(X.copy(), self.target_names, self.time_col)
|
||||||
X = normalize_ts_data(X, self.target_names, self.time_col)
|
|
||||||
return self._preprocess(X, transformer)
|
return self._preprocess(X, transformer)
|
||||||
elif isinstance(X, int):
|
elif isinstance(X, int):
|
||||||
return X
|
return X
|
||||||
|
|||||||
@@ -546,14 +546,12 @@ def normalize_ts_data(X_train_all, target_names, time_col, y_train_all=None):
|
|||||||
|
|
||||||
|
|
||||||
def validate_data_basic(X_train_all, y_train_all):
|
def validate_data_basic(X_train_all, y_train_all):
|
||||||
assert isinstance(X_train_all, np.ndarray) or issparse(X_train_all) or isinstance(X_train_all, pd.DataFrame), (
|
assert isinstance(X_train_all, (np.ndarray, DataFrame)) or issparse(
|
||||||
"X_train_all must be a numpy array, a pandas dataframe, " "or Scipy sparse matrix."
|
X_train_all
|
||||||
)
|
), "X_train_all must be a numpy array, a pandas dataframe, or Scipy sparse matrix."
|
||||||
|
|
||||||
assert (
|
assert isinstance(
|
||||||
isinstance(y_train_all, np.ndarray)
|
y_train_all, (np.ndarray, pd.Series, pd.DataFrame)
|
||||||
or isinstance(y_train_all, pd.Series)
|
|
||||||
or isinstance(y_train_all, pd.DataFrame)
|
|
||||||
), "y_train_all must be a numpy array or a pandas series or DataFrame."
|
), "y_train_all must be a numpy array or a pandas series or DataFrame."
|
||||||
|
|
||||||
assert X_train_all.size != 0 and y_train_all.size != 0, "Input data must not be empty, use None if no data"
|
assert X_train_all.size != 0 and y_train_all.size != 0, "Input data must not be empty, use None if no data"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# ChaCha for Online AutoML
|
# ChaCha for Online AutoML
|
||||||
|
|
||||||
FLAML includes *ChaCha* which is an automatic hyperparameter tuning solution for online machine learning. Online machine learning has the following properties: (1) data comes in sequential order; and (2) the performance of the machine learning model is evaluated online, i.e., at every iteration. *ChaCha* performs online AutoML respecting the aforementioned properties of online learning, and at the same time respecting the following constraints: (1) only a small constant number of 'live' models are allowed to perform online learning at the same time; and (2) no model persistence or offline training is allowed, which means that once we decide to replace a 'live' model with a new one, the replaced model can no longer be retrieved.
|
FLAML includes *ChaCha* which is an automatic hyperparameter tuning solution for online machine learning. Online machine learning has the following properties: (1) data comes in sequential order; and (2) the performance of the machine learning model is evaluated online, i.e., at every iteration. *ChaCha* performs online AutoML respecting the aforementioned properties of online learning, and at the same time respecting the following constraints: (1) only a small constant number of 'live' models are allowed to perform online learning at the same time; and (2) no model persistence or offline training is allowed, which means that once we decide to replace a 'live' model with a new one, the replaced model can no longer be retrieved.
|
||||||
|
|
||||||
For more technical details about *ChaCha*, please check our paper.
|
For more technical details about *ChaCha*, please check our paper.
|
||||||
|
|
||||||
|
|||||||
@@ -641,8 +641,10 @@ class FLOW2(Searcher):
|
|||||||
else:
|
else:
|
||||||
# key must be in space
|
# key must be in space
|
||||||
domain = space[key]
|
domain = space[key]
|
||||||
if self.hierarchical and not (
|
if (
|
||||||
domain is None or type(domain) in (str, int, float) or isinstance(domain, sample.Domain)
|
self.hierarchical
|
||||||
|
and domain is not None
|
||||||
|
and not isinstance(domain, (str, int, float, sample.Domain))
|
||||||
):
|
):
|
||||||
# not domain or hashable
|
# not domain or hashable
|
||||||
# get rid of list type for hierarchical search space.
|
# get rid of list type for hierarchical search space.
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ class ChampionFrontierSearcher(BaseSearcher):
|
|||||||
hyperparameter_config_groups.append(partial_new_configs)
|
hyperparameter_config_groups.append(partial_new_configs)
|
||||||
# does not have searcher_trial_ids
|
# does not have searcher_trial_ids
|
||||||
searcher_trial_ids_groups.append([])
|
searcher_trial_ids_groups.append([])
|
||||||
elif isinstance(config_domain, Float) or isinstance(config_domain, Categorical):
|
elif isinstance(config_domain, (Float, Categorical)):
|
||||||
# otherwise we need to deal with them in group
|
# otherwise we need to deal with them in group
|
||||||
nonpoly_config[k] = v
|
nonpoly_config[k] = v
|
||||||
if k not in self._space_of_nonpoly_hp:
|
if k not in self._space_of_nonpoly_hp:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
**Date and Time**: 09.09.2024, 15:30-17:00
|
**Date and Time**: 09.09.2024, 15:30-17:00
|
||||||
|
|
||||||
Location: Sorbonne University, 4 place Jussieu, 75005 Paris
|
Location: Sorbonne University, 4 place Jussieu, 75005 Paris
|
||||||
|
|
||||||
Duration: 1.5 hours
|
Duration: 1.5 hours
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
**Date and Time**: 04-26, 09:00–10:30 PT.
|
**Date and Time**: 04-26, 09:00–10:30 PT.
|
||||||
|
|
||||||
Location: Microsoft Conference Center, Seattle, WA.
|
Location: Microsoft Conference Center, Seattle, WA.
|
||||||
|
|
||||||
Duration: 1.5 hours
|
Duration: 1.5 hours
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ from sklearn.datasets import load_iris
|
|||||||
from sklearn.model_selection import train_test_split
|
from sklearn.model_selection import train_test_split
|
||||||
from flaml import AutoML
|
from flaml import AutoML
|
||||||
|
|
||||||
|
|
||||||
X, y = load_iris(return_X_y=True, as_frame=True)
|
X, y = load_iris(return_X_y=True, as_frame=True)
|
||||||
X_train, X_test, y_train, y_test = train_test_split(
|
X_train, X_test, y_train, y_test = train_test_split(
|
||||||
X, y, test_size=0.2, random_state=42
|
X, y, test_size=0.2, random_state=42
|
||||||
@@ -110,7 +109,6 @@ from sklearn.datasets import load_iris
|
|||||||
from sklearn.model_selection import train_test_split
|
from sklearn.model_selection import train_test_split
|
||||||
from flaml import AutoML
|
from flaml import AutoML
|
||||||
|
|
||||||
|
|
||||||
X, y = load_iris(return_X_y=True, as_frame=True)
|
X, y = load_iris(return_X_y=True, as_frame=True)
|
||||||
X_train, X_test, y_train, y_test = train_test_split(
|
X_train, X_test, y_train, y_test = train_test_split(
|
||||||
X, y, test_size=0.2, random_state=42
|
X, y, test_size=0.2, random_state=42
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ print(flaml.__version__)
|
|||||||
```
|
```
|
||||||
|
|
||||||
- Please ensure all **code snippets and error messages are formatted in
|
- Please ensure all **code snippets and error messages are formatted in
|
||||||
appropriate code blocks**. See [Creating and highlighting code blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks)
|
appropriate code blocks**. See [Creating and highlighting code blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks)
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
## Becoming a Reviewer
|
## Becoming a Reviewer
|
||||||
@@ -88,7 +88,7 @@ Run `pre-commit install` to install pre-commit into your git hooks. Before you c
|
|||||||
|
|
||||||
### Coverage
|
### Coverage
|
||||||
|
|
||||||
Any code you commit should not decrease coverage. To run all unit tests, install the \[test\] option under FLAML/:
|
Any code you commit should not decrease coverage. To run all unit tests, install the [test] option under FLAML/:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install -e."[test]"
|
pip install -e."[test]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
Install the \[automl\] option.
|
Install the [automl] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl]"
|
pip install "flaml[automl]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
This example requires GPU. Install the \[automl,hf\] option:
|
This example requires GPU. Install the [automl,hf] option:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
pip install "flaml[automl,hf]"
|
pip install "flaml[automl,hf]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
Install the \[automl\] option.
|
Install the [automl] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl]"
|
pip install "flaml[automl]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
Install the \[automl\] option.
|
Install the [automl] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl]"
|
pip install "flaml[automl]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
Install the \[automl,ts_forecast\] option.
|
Install the [automl,ts_forecast] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl,ts_forecast]"
|
pip install "flaml[automl,ts_forecast]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Prerequisites for this example
|
### Prerequisites for this example
|
||||||
|
|
||||||
Install the \[automl\] option.
|
Install the [automl] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl] matplotlib openml"
|
pip install "flaml[automl] matplotlib openml"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Prerequisites for this example
|
### Prerequisites for this example
|
||||||
|
|
||||||
Install the \[automl\] option.
|
Install the [automl] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl] matplotlib openml"
|
pip install "flaml[automl] matplotlib openml"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Flamlized estimators automatically use data-dependent default hyperparameter con
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
This example requires the \[autozero\] option.
|
This example requires the [autozero] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install flaml[autozero] lightgbm openml
|
pip install flaml[autozero] lightgbm openml
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ FLAML can be used together with AzureML. On top of that, using mlflow and ray is
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
Install the \[automl,azureml\] option.
|
Install the [automl,azureml] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl,azureml]"
|
pip install "flaml[automl,azureml]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ As FLAML's AutoML module can be used a transformer in the Sklearn's pipeline we
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
Install the \[automl\] option.
|
Install the [automl] option.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[automl] openml"
|
pip install "flaml[automl] openml"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
### About `low_cost_partial_config` in `tune`.
|
### About `low_cost_partial_config` in `tune`.
|
||||||
|
|
||||||
- Definition and purpose: The `low_cost_partial_config` is a dictionary of subset of the hyperparameter coordinates whose value corresponds to a configuration with known low-cost (i.e., low computation cost for training the corresponding model). The concept of low/high-cost is meaningful in the case where a subset of the hyperparameters to tune directly affects the computation cost for training the model. For example, `n_estimators` and `max_leaves` are known to affect the training cost of tree-based learners. We call this subset of hyperparameters, *cost-related hyperparameters*. In such scenarios, if you are aware of low-cost configurations for the cost-related hyperparameters, you are recommended to set them as the `low_cost_partial_config`. Using the tree-based method example again, since we know that small `n_estimators` and `max_leaves` generally correspond to simpler models and thus lower cost, we set `{'n_estimators': 4, 'max_leaves': 4}` as the `low_cost_partial_config` by default (note that `4` is the lower bound of search space for these two hyperparameters), e.g., in [LGBM](https://github.com/microsoft/FLAML/blob/main/flaml/model.py#L215). Configuring `low_cost_partial_config` helps the search algorithms make more cost-efficient choices.
|
- Definition and purpose: The `low_cost_partial_config` is a dictionary of subset of the hyperparameter coordinates whose value corresponds to a configuration with known low-cost (i.e., low computation cost for training the corresponding model). The concept of low/high-cost is meaningful in the case where a subset of the hyperparameters to tune directly affects the computation cost for training the model. For example, `n_estimators` and `max_leaves` are known to affect the training cost of tree-based learners. We call this subset of hyperparameters, *cost-related hyperparameters*. In such scenarios, if you are aware of low-cost configurations for the cost-related hyperparameters, you are recommended to set them as the `low_cost_partial_config`. Using the tree-based method example again, since we know that small `n_estimators` and `max_leaves` generally correspond to simpler models and thus lower cost, we set `{'n_estimators': 4, 'max_leaves': 4}` as the `low_cost_partial_config` by default (note that `4` is the lower bound of search space for these two hyperparameters), e.g., in [LGBM](https://github.com/microsoft/FLAML/blob/main/flaml/model.py#L215). Configuring `low_cost_partial_config` helps the search algorithms make more cost-efficient choices.
|
||||||
In AutoML, the `low_cost_init_value` in `search_space()` function for each estimator serves the same role.
|
In AutoML, the `low_cost_init_value` in `search_space()` function for each estimator serves the same role.
|
||||||
|
|
||||||
- Usage in practice: It is recommended to configure it if there are cost-related hyperparameters in your tuning task and you happen to know the low-cost values for them, but it is not required (It is fine to leave it the default value, i.e., `None`).
|
- Usage in practice: It is recommended to configure it if there are cost-related hyperparameters in your tuning task and you happen to know the low-cost values for them, but it is not required (It is fine to leave it the default value, i.e., `None`).
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ pip install "flaml[hf]"
|
|||||||
#### Notebook
|
#### Notebook
|
||||||
|
|
||||||
To run the [notebook examples](https://github.com/microsoft/FLAML/tree/main/notebook),
|
To run the [notebook examples](https://github.com/microsoft/FLAML/tree/main/notebook),
|
||||||
install flaml with the \[notebook\] option:
|
install flaml with the [notebook] option:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "flaml[notebook]"
|
pip install "flaml[notebook]"
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ The estimator list can contain one or more estimator names, each corresponding t
|
|||||||
- Built-in estimator.
|
- Built-in estimator.
|
||||||
- 'lgbm': LGBMEstimator for task "classification", "regression", "rank", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, num_leaves, min_child_samples, learning_rate, log_max_bin (logarithm of (max_bin + 1) with base 2), colsample_bytree, reg_alpha, reg_lambda.
|
- 'lgbm': LGBMEstimator for task "classification", "regression", "rank", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, num_leaves, min_child_samples, learning_rate, log_max_bin (logarithm of (max_bin + 1) with base 2), colsample_bytree, reg_alpha, reg_lambda.
|
||||||
- 'xgboost': XGBoostSkLearnEstimator for task "classification", "regression", "rank", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_leaves, min_child_weight, learning_rate, subsample, colsample_bylevel, colsample_bytree, reg_alpha, reg_lambda.
|
- 'xgboost': XGBoostSkLearnEstimator for task "classification", "regression", "rank", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_leaves, min_child_weight, learning_rate, subsample, colsample_bylevel, colsample_bytree, reg_alpha, reg_lambda.
|
||||||
- 'xgb_limitdepth': XGBoostLimitDepthEstimator for task "classification", "regression", "rank", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_depth, min_child_weight, learning_rate, subsample, colsample_bylevel, colsample_bytree, reg_alpha, reg_lambda.
|
- 'xgb_limitdepth': XGBoostLimitDepthEstimator for task "classification", "regression", "rank", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_depth, min_child_weight, learning_rate, subsample, colsample_bylevel, colsample_bytree, reg_alpha, reg_lambda.
|
||||||
- 'rf': RandomForestEstimator for task "classification", "regression", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_features, max_leaves, criterion (for classification only). Starting from v1.1.0,
|
- 'rf': RandomForestEstimator for task "classification", "regression", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_features, max_leaves, criterion (for classification only). Starting from v1.1.0,
|
||||||
it uses a fixed random_state by default.
|
it uses a fixed random_state by default.
|
||||||
- 'extra_tree': ExtraTreesEstimator for task "classification", "regression", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_features, max_leaves, criterion (for classification only). Starting from v1.1.0,
|
- 'extra_tree': ExtraTreesEstimator for task "classification", "regression", "ts_forecast" and "ts_forecast_classification". Hyperparameters: n_estimators, max_features, max_leaves, criterion (for classification only). Starting from v1.1.0,
|
||||||
@@ -462,7 +462,7 @@ For both classification and regression tasks more advanced split configurations
|
|||||||
|
|
||||||
More in general, `split_type` can also be set as a custom splitter object, when `eval_method="cv"`. It needs to be an instance of a derived class of scikit-learn
|
More in general, `split_type` can also be set as a custom splitter object, when `eval_method="cv"`. It needs to be an instance of a derived class of scikit-learn
|
||||||
[KFold](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html#sklearn.model_selection.KFold)
|
[KFold](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html#sklearn.model_selection.KFold)
|
||||||
and have `split` and `get_n_splits` methods with the same signatures. To disable shuffling, the splitter instance must contain the attribute `shuffle=False`.
|
and have `split` and `get_n_splits` methods with the same signatures. To disable shuffling, the splitter instance must contain the attribute `shuffle=False`.
|
||||||
|
|
||||||
### Parallel tuning
|
### Parallel tuning
|
||||||
|
|
||||||
@@ -740,7 +740,7 @@ If you want to get a sense of how much time is needed to find the best model, yo
|
|||||||
|
|
||||||
> INFO - Estimated sufficient time budget=145194s. Estimated necessary time budget=2118s.
|
> INFO - Estimated sufficient time budget=145194s. Estimated necessary time budget=2118s.
|
||||||
|
|
||||||
> INFO - at 2.6s, estimator lgbm's best error=0.4459, best estimator lgbm's best error=0.4459
|
> INFO - at 2.6s, estimator lgbm's best error=0.4459, best estimator lgbm's best error=0.4459
|
||||||
|
|
||||||
You will see that the time to finish the first and cheapest trial is 2.6 seconds. The estimated necessary time budget is 2118 seconds, and the estimated sufficient time budget is 145194 seconds. Note that this is only an estimated range to help you decide your budget.
|
You will see that the time to finish the first and cheapest trial is 2.6 seconds. The estimated necessary time budget is 2118 seconds, and the estimated sufficient time budget is 145194 seconds. Note that this is only an estimated range to help you decide your budget.
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ Related arguments:
|
|||||||
|
|
||||||
- `evaluation_function`: A user-defined evaluation function.
|
- `evaluation_function`: A user-defined evaluation function.
|
||||||
- `metric`: A string of the metric name to optimize for.
|
- `metric`: A string of the metric name to optimize for.
|
||||||
- `mode`: A string in \['min', 'max'\] to specify the objective as minimization or maximization.
|
- `mode`: A string in ['min', 'max'] to specify the objective as minimization or maximization.
|
||||||
|
|
||||||
The first step is to specify your tuning objective.
|
The first step is to specify your tuning objective.
|
||||||
To do it, you should first specify your evaluation procedure (e.g., perform a machine learning model training and validation) with respect to the hyperparameters in a user-defined function `evaluation_function`.
|
To do it, you should first specify your evaluation procedure (e.g., perform a machine learning model training and validation) with respect to the hyperparameters in a user-defined function `evaluation_function`.
|
||||||
The function requires a hyperparameter configuration as input, and can simply return a metric value in a scalar or return a dictionary of metric name and metric value pairs.
|
The function requires a hyperparameter configuration as input, and can simply return a metric value in a scalar or return a dictionary of metric name and metric value pairs.
|
||||||
|
|
||||||
In the following code, we define an evaluation function with respect to two hyperparameters named `x` and `y` according to $obj := (x-85000)^2 - x/y$. Note that we use this toy example here for more accessible demonstration purposes. In real use cases, the evaluation function usually cannot be written in this closed form, but instead involves a black-box and expensive evaluation procedure. Please check out [Tune HuggingFace](/docs/Examples/Tune-HuggingFace), [Tune PyTorch](/docs/Examples/Tune-PyTorch) and [Tune LightGBM](/docs/Getting-Started#tune-user-defined-function) for real examples of tuning tasks.
|
In the following code, we define an evaluation function with respect to two hyperparameters named `x` and `y` according to $obj := (x-85000)^2 - x/y$. Note that we use this toy example here for more accessible demonstration purposes. In real use cases, the evaluation function usually cannot be written in this closed form, but instead involves a black-box and expensive evaluation procedure. Please check out [Tune HuggingFace](/docs/Examples/Tune-HuggingFace), [Tune PyTorch](/docs/Examples/Tune-PyTorch) and [Tune LightGBM](/docs/Getting-Started#tune-user-defined-function) for real examples of tuning tasks.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import time
|
import time
|
||||||
@@ -72,7 +72,7 @@ Related arguments:
|
|||||||
|
|
||||||
The second step is to specify a search space of the hyperparameters through the argument `config`. In the search space, you need to specify valid values for your hyperparameters and can specify how these values are sampled (e.g., from a uniform distribution or a log-uniform distribution).
|
The second step is to specify a search space of the hyperparameters through the argument `config`. In the search space, you need to specify valid values for your hyperparameters and can specify how these values are sampled (e.g., from a uniform distribution or a log-uniform distribution).
|
||||||
|
|
||||||
In the following code example, we include a search space for the two hyperparameters `x` and `y` as introduced above. The valid values for both are integers in the range of \[1, 100000\]. The values for `x` are sampled uniformly in the specified range (using `tune.randint(lower=1, upper=100000)`), and the values for `y` are sampled uniformly in logarithmic space of the specified range (using `tune.lograndit(lower=1, upper=100000)`).
|
In the following code example, we include a search space for the two hyperparameters `x` and `y` as introduced above. The valid values for both are integers in the range of [1, 100000]. The values for `x` are sampled uniformly in the specified range (using `tune.randint(lower=1, upper=100000)`), and the values for `y` are sampled uniformly in logarithmic space of the specified range (using `tune.lograndit(lower=1, upper=100000)`).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from flaml import tune
|
from flaml import tune
|
||||||
@@ -186,10 +186,10 @@ config = {
|
|||||||
Cost-related hyperparameters are a subset of the hyperparameters which directly affect the computation cost incurred in the evaluation of any hyperparameter configuration. For example, the number of estimators (`n_estimators`) and the maximum number of leaves (`max_leaves`) are known to affect the training cost of tree-based learners. So they are cost-related hyperparameters for tree-based learners.
|
Cost-related hyperparameters are a subset of the hyperparameters which directly affect the computation cost incurred in the evaluation of any hyperparameter configuration. For example, the number of estimators (`n_estimators`) and the maximum number of leaves (`max_leaves`) are known to affect the training cost of tree-based learners. So they are cost-related hyperparameters for tree-based learners.
|
||||||
|
|
||||||
When cost-related hyperparameters exist, the evaluation cost in the search space is heterogeneous.
|
When cost-related hyperparameters exist, the evaluation cost in the search space is heterogeneous.
|
||||||
In this case, designing a search space with proper ranges of the hyperparameter values is highly non-trivial. Classical tuning algorithms such as Bayesian optimization and random search are typically sensitive to such ranges. It may take them a very high cost to find a good choice if the ranges are too large. And if the ranges are too small, the optimal choice(s) may not be included and thus not possible to be found. With our method, you can use a search space with larger ranges in the case of heterogeneous cost.
|
In this case, designing a search space with proper ranges of the hyperparameter values is highly non-trivial. Classical tuning algorithms such as Bayesian optimization and random search are typically sensitive to such ranges. It may take them a very high cost to find a good choice if the ranges are too large. And if the ranges are too small, the optimal choice(s) may not be included and thus not possible to be found. With our method, you can use a search space with larger ranges in the case of heterogeneous cost.
|
||||||
|
|
||||||
Our search algorithms are designed to finish the tuning process at a low total cost when the evaluation cost in the search space is heterogeneous.
|
Our search algorithms are designed to finish the tuning process at a low total cost when the evaluation cost in the search space is heterogeneous.
|
||||||
So in such scenarios, if you are aware of low-cost configurations for the cost-related hyperparameters, you are encouraged to set them as the `low_cost_partial_config`, which is a dictionary of a subset of the hyperparameter coordinates whose value corresponds to a configuration with known low cost. Using the example of the tree-based methods again, since we know that small `n_estimators` and `max_leaves` generally correspond to simpler models and thus lower cost, we set `{'n_estimators': 4, 'max_leaves': 4}` as the `low_cost_partial_config` by default (note that 4 is the lower bound of search space for these two hyperparameters), e.g., in LGBM. Please find more details on how the algorithm works [here](#cfo-frugal-optimization-for-cost-related-hyperparameters).
|
So in such scenarios, if you are aware of low-cost configurations for the cost-related hyperparameters, you are encouraged to set them as the `low_cost_partial_config`, which is a dictionary of a subset of the hyperparameter coordinates whose value corresponds to a configuration with known low cost. Using the example of the tree-based methods again, since we know that small `n_estimators` and `max_leaves` generally correspond to simpler models and thus lower cost, we set `{'n_estimators': 4, 'max_leaves': 4}` as the `low_cost_partial_config` by default (note that 4 is the lower bound of search space for these two hyperparameters), e.g., in LGBM. Please find more details on how the algorithm works [here](#cfo-frugal-optimization-for-cost-related-hyperparameters).
|
||||||
|
|
||||||
In addition, if you are aware of the cost relationship between different categorical hyperparameter choices, you are encouraged to provide this information through `cat_hp_cost`. It also helps the search algorithm to reduce the total cost.
|
In addition, if you are aware of the cost relationship between different categorical hyperparameter choices, you are encouraged to provide this information through `cat_hp_cost`. It also helps the search algorithm to reduce the total cost.
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ Related arguments:
|
|||||||
- `config_constraints` (optional): A list of config constraints to be satisfied.
|
- `config_constraints` (optional): A list of config constraints to be satisfied.
|
||||||
- `metric_constraints` (optional): A list of metric constraints to be satisfied. e.g., `['precision', '>=', 0.9]`.
|
- `metric_constraints` (optional): A list of metric constraints to be satisfied. e.g., `['precision', '>=', 0.9]`.
|
||||||
|
|
||||||
The third step is to specify constraints of the tuning task. One notable property of `flaml.tune` is that it is able to finish the tuning process (obtaining good results) within a required resource constraint. A user can either provide the resource constraint in terms of wall-clock time (in seconds) through the argument `time_budget_s`, or in terms of the number of trials through the argument `num_samples`. The following example shows three use cases:
|
The third step is to specify constraints of the tuning task. One notable property of `flaml.tune` is that it is able to finish the tuning process (obtaining good results) within a required resource constraint. A user can either provide the resource constraint in terms of wall-clock time (in seconds) through the argument `time_budget_s`, or in terms of the number of trials through the argument `num_samples`. The following example shows three use cases:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Set a resource constraint of 60 seconds wall-clock time for the tuning.
|
# Set a resource constraint of 60 seconds wall-clock time for the tuning.
|
||||||
@@ -295,8 +295,8 @@ Related arguments:
|
|||||||
|
|
||||||
Details about parallel tuning with Spark could be found [here](/docs/Examples/Integrate%20-%20Spark#parallel-spark-jobs).
|
Details about parallel tuning with Spark could be found [here](/docs/Examples/Integrate%20-%20Spark#parallel-spark-jobs).
|
||||||
|
|
||||||
You can perform parallel tuning by specifying `use_ray=True` (requiring flaml\[ray\] option installed) or `use_spark=True`
|
You can perform parallel tuning by specifying `use_ray=True` (requiring flaml[ray] option installed) or `use_spark=True`
|
||||||
(requiring flaml\[spark\] option installed). You can also limit the amount of resources allocated per trial by specifying `resources_per_trial`,
|
(requiring flaml[spark] option installed). You can also limit the amount of resources allocated per trial by specifying `resources_per_trial`,
|
||||||
e.g., `resources_per_trial={'cpu': 2}` when `use_ray=True`.
|
e.g., `resources_per_trial={'cpu': 2}` when `use_ray=True`.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@@ -409,11 +409,11 @@ analysis = tune.run(
|
|||||||
|
|
||||||
You can find more details about this scheduler in [this paper](https://arxiv.org/pdf/1911.04706.pdf).
|
You can find more details about this scheduler in [this paper](https://arxiv.org/pdf/1911.04706.pdf).
|
||||||
|
|
||||||
#### 2. A scheduler of the [`TrialScheduler`](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#tune-schedulers) class from `ray.tune`.
|
#### 2. A scheduler of the [`TrialScheduler`](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#tune-schedulers) class from `ray.tune`.
|
||||||
|
|
||||||
There is a handful of schedulers of this type implemented in `ray.tune`, for example, [ASHA](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#asha-tune-schedulers-ashascheduler), [HyperBand](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#tune-original-hyperband), [BOHB](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#tune-scheduler-bohb), etc.
|
There is a handful of schedulers of this type implemented in `ray.tune`, for example, [ASHA](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#asha-tune-schedulers-ashascheduler), [HyperBand](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#tune-original-hyperband), [BOHB](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#tune-scheduler-bohb), etc.
|
||||||
|
|
||||||
To use this type of scheduler you can either (1) set `scheduler='asha'`, which will automatically create an [ASHAScheduler](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#asha-tune-schedulers-ashascheduler) instance using the provided inputs (`resource_attr`, `min_resource`, `max_resource`, and `reduction_factor`); or (2) create an instance by yourself and provided it via `scheduler`, as shown in the following code example,
|
To use this type of scheduler you can either (1) set `scheduler='asha'`, which will automatically create an [ASHAScheduler](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#asha-tune-schedulers-ashascheduler) instance using the provided inputs (`resource_attr`, `min_resource`, `max_resource`, and `reduction_factor`); or (2) create an instance by yourself and provided it via `scheduler`, as shown in the following code example,
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# require: pip install flaml[ray]
|
# require: pip install flaml[ray]
|
||||||
@@ -589,7 +589,7 @@ NOTE:
|
|||||||
|
|
||||||
## Hyperparameter Optimization Algorithm
|
## Hyperparameter Optimization Algorithm
|
||||||
|
|
||||||
To tune the hyperparameters toward your objective, you will want to use a hyperparameter optimization algorithm which can help suggest hyperparameters with better performance (regarding your objective). `flaml` offers two HPO methods: CFO and BlendSearch. `flaml.tune` uses BlendSearch by default when the option \[blendsearch\] is installed.
|
To tune the hyperparameters toward your objective, you will want to use a hyperparameter optimization algorithm which can help suggest hyperparameters with better performance (regarding your objective). `flaml` offers two HPO methods: CFO and BlendSearch. `flaml.tune` uses BlendSearch by default when the option [blendsearch] is installed.
|
||||||
|
|
||||||
<!--  | 
|
<!--  | 
|
||||||
:---:|:---: -->
|
:---:|:---: -->
|
||||||
|
|||||||
Reference in New Issue
Block a user