mirror of
https://github.com/microsoft/autogen.git
synced 2025-08-02 13:52:39 +00:00

* subspace in flow2 * search space and trainable from AutoML * experimental features: multivariate TPE, grouping, add_evaluated_points * test experimental features * readme * define by run * set time_budget_s for bs Co-authored-by: liususan091219 <Xqq630517> * version * acl * test define_by_run_func * size * constraints Co-authored-by: Chi Wang <wang.chi@microsoft.com>
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
from flaml import AutoML
|
|
from sklearn.datasets import load_boston
|
|
import os
|
|
import unittest
|
|
import logging
|
|
import tempfile
|
|
import io
|
|
|
|
|
|
class TestLogging(unittest.TestCase):
|
|
|
|
def test_logging_level(self):
|
|
|
|
from flaml import logger, logger_formatter
|
|
|
|
with tempfile.TemporaryDirectory() as d:
|
|
|
|
training_log = os.path.join(d, "training.log")
|
|
|
|
# Configure logging for the FLAML logger
|
|
# and add a handler that outputs to a buffer.
|
|
logger.setLevel(logging.INFO)
|
|
buf = io.StringIO()
|
|
ch = logging.StreamHandler(buf)
|
|
ch.setFormatter(logger_formatter)
|
|
logger.addHandler(ch)
|
|
|
|
# Run a simple job.
|
|
automl = AutoML()
|
|
automl_settings = {
|
|
"time_budget": 1,
|
|
"metric": 'rmse',
|
|
"task": 'regression',
|
|
"log_file_name": training_log,
|
|
"log_training_metric": True,
|
|
"n_jobs": 1,
|
|
"model_history": True,
|
|
"learner_selector": "roundrobin",
|
|
}
|
|
X_train, y_train = load_boston(return_X_y=True)
|
|
n = len(y_train) >> 1
|
|
automl.fit(X_train=X_train[:n], y_train=y_train[:n],
|
|
X_val=X_train[n:], y_val=y_train[n:],
|
|
**automl_settings)
|
|
logger.info(automl.search_space)
|
|
logger.info(automl.low_cost_partial_config)
|
|
logger.info(automl.points_to_evalaute)
|
|
import optuna as ot
|
|
study = ot.create_study()
|
|
from flaml.tune.space import define_by_run_func
|
|
logger.info(define_by_run_func(study.ask(), automl.search_space))
|
|
config = automl.best_config.copy()
|
|
config['learner'] = automl.best_estimator
|
|
automl.trainable({"ml": config})
|
|
# Check if the log buffer is populated.
|
|
self.assertTrue(len(buf.getvalue()) > 0)
|
|
|
|
import pickle
|
|
with open('automl.pkl', 'wb') as f:
|
|
pickle.dump(automl, f, pickle.HIGHEST_PROTOCOL)
|
|
print(automl.__version__)
|