2021-12-03 12:45:16 -05:00
|
|
|
import sys
|
2021-11-18 09:39:45 -08:00
|
|
|
import pytest
|
2022-04-28 14:06:29 -04:00
|
|
|
from utils import get_toy_data_seqregression, get_automl_settings
|
2022-10-12 20:04:42 -04:00
|
|
|
import os
|
|
|
|
import shutil
|
2021-11-18 09:39:45 -08:00
|
|
|
|
|
|
|
|
2021-12-03 12:45:16 -05:00
|
|
|
@pytest.mark.skipif(sys.platform == "darwin", reason="do not run on mac os")
|
2021-11-16 14:06:20 -05:00
|
|
|
def test_regression():
|
2021-11-23 14:26:39 -05:00
|
|
|
try:
|
|
|
|
import ray
|
2022-03-20 22:03:02 -04:00
|
|
|
|
|
|
|
if not ray.is_initialized():
|
|
|
|
ray.init()
|
2021-11-23 14:26:39 -05:00
|
|
|
except ImportError:
|
|
|
|
return
|
2021-11-16 14:06:20 -05:00
|
|
|
from flaml import AutoML
|
|
|
|
|
2022-04-28 14:06:29 -04:00
|
|
|
X_train, y_train, X_val, y_val = get_toy_data_seqregression()
|
2021-11-16 14:06:20 -05:00
|
|
|
|
|
|
|
automl = AutoML()
|
2022-04-28 14:06:29 -04:00
|
|
|
automl_settings = get_automl_settings()
|
2021-11-16 14:06:20 -05:00
|
|
|
|
2022-04-28 14:06:29 -04:00
|
|
|
automl_settings["task"] = "seq-regression"
|
|
|
|
automl_settings["metric"] = "pearsonr"
|
|
|
|
automl_settings["starting_points"] = {"transformer": {"num_train_epochs": 1}}
|
|
|
|
automl_settings["use_ray"] = {"local_dir": "data/outut/"}
|
2021-11-16 14:06:20 -05:00
|
|
|
|
2022-01-14 13:39:09 -08:00
|
|
|
ray.shutdown()
|
2022-02-09 15:04:29 -08:00
|
|
|
ray.init()
|
2022-03-20 22:03:02 -04:00
|
|
|
|
2021-11-16 14:06:20 -05:00
|
|
|
automl.fit(
|
|
|
|
X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings
|
|
|
|
)
|
2022-01-14 13:39:09 -08:00
|
|
|
automl.predict(X_val)
|
2021-12-03 12:45:16 -05:00
|
|
|
|
2022-10-12 20:04:42 -04:00
|
|
|
if os.path.exists("test/data/output/"):
|
2022-11-27 11:22:54 -08:00
|
|
|
try:
|
|
|
|
shutil.rmtree("test/data/output/")
|
|
|
|
except PermissionError:
|
|
|
|
print("PermissionError when deleting test/data/output/")
|
2022-10-12 20:04:42 -04:00
|
|
|
|
2021-12-03 12:45:16 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_regression()
|