2021-02-22 22:10:41 -08:00
{
"cells": [
{
"cell_type": "markdown",
"source": [
"Copyright (c) 2020-2021 Microsoft Corporation. All rights reserved. \n",
"\n",
"Licensed under the MIT License.\n",
"\n",
"# Tune LightGBM with FLAML Library\n",
"\n",
"\n",
"## 1. Introduction\n",
"\n",
"FLAML is a Python library (https://github.com/microsoft/FLAML) designed to automatically produce accurate machine learning models \n",
"with low computational cost. It is fast and cheap. The simple and lightweight design makes it easy \n",
"to use and extend, such as adding new learners. FLAML can \n",
"- serve as an economical AutoML engine,\n",
"- be used as a fast hyperparameter tuning tool, or \n",
"- be embedded in self-tuning software that requires low latency & resource in repetitive\n",
" tuning tasks.\n",
"\n",
"In this notebook, we demonstrate how to use FLAML library to tune hyperparameters of LightGBM with a regression example.\n",
"\n",
"FLAML requires `Python>=3.6`. To run this notebook example, please install flaml with the `notebook` option:\n",
"```bash\n",
"pip install flaml[notebook]\n",
"```"
2021-08-23 19:36:51 -04:00
],
"metadata": {
"slideshow": {
"slide_type": "slide"
}
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 16:26:46 -04:00
"execution_count": 1,
2021-02-22 22:10:41 -08:00
"source": [
"!pip install flaml[notebook];"
2021-08-23 19:36:51 -04:00
],
"outputs": [],
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "markdown",
"source": [
"## 2. Regression Example\n",
"### Load data and preprocess\n",
"\n",
"Download [houses dataset](https://www.openml.org/d/537) from OpenML. The task is to predict median price of the house in the region based on demographic composition and a state of housing market in the region."
2021-08-23 19:36:51 -04:00
],
"metadata": {
"slideshow": {
"slide_type": "slide"
}
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 1,
"source": [
"from flaml.data import load_openml_dataset\n",
"X_train, X_test, y_train, y_test = load_openml_dataset(dataset_id=537, data_dir='./')"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
2021-07-24 20:10:43 -04:00
"load dataset from ./openml_ds537.pkl\n",
"Dataset name: houses\n",
"X_train.shape: (15480, 8), y_train.shape: (15480,);\n",
"X_test.shape: (5160, 8), y_test.shape: (5160,)\n"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"slideshow": {
"slide_type": "subslide"
},
"tags": []
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "markdown",
2021-08-23 19:36:51 -04:00
"source": [
"### Run FLAML\n",
"In the FLAML automl run configuration, users can specify the task type, time budget, error metric, learner list, whether to subsample, resampling strategy type, and so on. All these arguments have default values which will be used if users do not provide them. "
],
2021-02-22 22:10:41 -08:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
2021-08-23 19:36:51 -04:00
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 2,
"source": [
"''' import AutoML class from flaml package '''\n",
"from flaml import AutoML\n",
"automl = AutoML()"
],
"outputs": [],
2021-02-22 22:10:41 -08:00
"metadata": {
"slideshow": {
"slide_type": "slide"
2021-04-10 21:14:28 -04:00
},
"tags": []
2021-08-23 19:36:51 -04:00
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 3,
2021-02-22 22:10:41 -08:00
"source": [
"settings = {\n",
2021-08-23 16:26:46 -04:00
" \"time_budget\": 240, # total running time in seconds\n",
2021-04-08 09:29:55 -07:00
" \"metric\": 'r2', # primary metrics for regression can be chosen from: ['mae','mse','r2']\n",
" \"estimator_list\": ['lgbm'], # list of ML learners; we tune lightgbm in this example\n",
" \"task\": 'regression', # task type \n",
" \"log_file_name\": 'houses_experiment.log', # flaml log file\n",
2021-08-23 16:26:46 -04:00
" \"seed\": 7654321, # random seed\n",
2021-02-22 22:10:41 -08:00
"}"
2021-08-23 19:36:51 -04:00
],
"outputs": [],
2021-02-22 22:10:41 -08:00
"metadata": {
"slideshow": {
"slide_type": "slide"
2021-08-23 19:36:51 -04:00
}
}
},
{
"cell_type": "code",
"execution_count": 4,
"source": [
"'''The main flaml automl API'''\n",
"automl.fit(X_train=X_train, y_train=y_train, **settings)"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stderr",
2021-05-08 02:50:50 +00:00
"text": [
2021-08-23 19:36:51 -04:00
"[flaml.automl: 08-22 21:09:17] {1130} INFO - Evaluation method: cv\n",
"[flaml.automl: 08-22 21:09:17] {634} INFO - Using RepeatedKFold\n",
"[flaml.automl: 08-22 21:09:17] {1155} INFO - Minimizing error metric: 1-r2\n",
"[flaml.automl: 08-22 21:09:17] {1175} INFO - List of ML learners in AutoML Run: ['lgbm']\n",
"[flaml.automl: 08-22 21:09:17] {1358} INFO - iteration 0, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:18] {1515} INFO - at 0.5s,\tbest lgbm's error=0.7385,\tbest lgbm's error=0.7385\n",
"[flaml.automl: 08-22 21:09:18] {1358} INFO - iteration 1, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:18] {1515} INFO - at 0.7s,\tbest lgbm's error=0.7385,\tbest lgbm's error=0.7385\n",
"[flaml.automl: 08-22 21:09:18] {1358} INFO - iteration 2, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:18] {1515} INFO - at 0.8s,\tbest lgbm's error=0.5517,\tbest lgbm's error=0.5517\n",
"[flaml.automl: 08-22 21:09:18] {1358} INFO - iteration 3, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:18] {1515} INFO - at 1.0s,\tbest lgbm's error=0.3103,\tbest lgbm's error=0.3103\n",
"[flaml.automl: 08-22 21:09:18] {1358} INFO - iteration 4, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:19] {1515} INFO - at 1.1s,\tbest lgbm's error=0.3103,\tbest lgbm's error=0.3103\n",
"[flaml.automl: 08-22 21:09:19] {1358} INFO - iteration 5, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:19] {1515} INFO - at 1.4s,\tbest lgbm's error=0.2718,\tbest lgbm's error=0.2718\n",
"[flaml.automl: 08-22 21:09:19] {1358} INFO - iteration 6, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:19] {1515} INFO - at 1.6s,\tbest lgbm's error=0.2718,\tbest lgbm's error=0.2718\n",
"[flaml.automl: 08-22 21:09:19] {1358} INFO - iteration 7, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:19] {1515} INFO - at 1.8s,\tbest lgbm's error=0.2718,\tbest lgbm's error=0.2718\n",
"[flaml.automl: 08-22 21:09:19] {1358} INFO - iteration 8, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:19] {1515} INFO - at 2.0s,\tbest lgbm's error=0.2406,\tbest lgbm's error=0.2406\n",
"[flaml.automl: 08-22 21:09:19] {1358} INFO - iteration 9, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:20] {1515} INFO - at 2.2s,\tbest lgbm's error=0.2406,\tbest lgbm's error=0.2406\n",
"[flaml.automl: 08-22 21:09:20] {1358} INFO - iteration 10, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:20] {1515} INFO - at 2.8s,\tbest lgbm's error=0.1787,\tbest lgbm's error=0.1787\n",
"[flaml.automl: 08-22 21:09:20] {1358} INFO - iteration 11, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:21] {1515} INFO - at 3.7s,\tbest lgbm's error=0.1787,\tbest lgbm's error=0.1787\n",
"[flaml.automl: 08-22 21:09:21] {1358} INFO - iteration 12, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:22] {1515} INFO - at 4.3s,\tbest lgbm's error=0.1787,\tbest lgbm's error=0.1787\n",
"[flaml.automl: 08-22 21:09:22] {1358} INFO - iteration 13, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:22] {1515} INFO - at 4.9s,\tbest lgbm's error=0.1787,\tbest lgbm's error=0.1787\n",
"[flaml.automl: 08-22 21:09:22] {1358} INFO - iteration 14, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:23] {1515} INFO - at 5.8s,\tbest lgbm's error=0.1765,\tbest lgbm's error=0.1765\n",
"[flaml.automl: 08-22 21:09:23] {1358} INFO - iteration 15, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:25] {1515} INFO - at 7.6s,\tbest lgbm's error=0.1765,\tbest lgbm's error=0.1765\n",
"[flaml.automl: 08-22 21:09:25] {1358} INFO - iteration 16, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:26] {1515} INFO - at 8.3s,\tbest lgbm's error=0.1765,\tbest lgbm's error=0.1765\n",
"[flaml.automl: 08-22 21:09:26] {1358} INFO - iteration 17, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:28] {1515} INFO - at 10.3s,\tbest lgbm's error=0.1765,\tbest lgbm's error=0.1765\n",
"[flaml.automl: 08-22 21:09:28] {1358} INFO - iteration 18, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:28] {1515} INFO - at 11.0s,\tbest lgbm's error=0.1765,\tbest lgbm's error=0.1765\n",
"[flaml.automl: 08-22 21:09:28] {1358} INFO - iteration 19, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:29] {1515} INFO - at 11.4s,\tbest lgbm's error=0.1765,\tbest lgbm's error=0.1765\n",
"[flaml.automl: 08-22 21:09:29] {1358} INFO - iteration 20, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:31] {1515} INFO - at 13.9s,\tbest lgbm's error=0.1765,\tbest lgbm's error=0.1765\n",
"[flaml.automl: 08-22 21:09:31] {1358} INFO - iteration 21, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:32] {1515} INFO - at 14.9s,\tbest lgbm's error=0.1693,\tbest lgbm's error=0.1693\n",
"[flaml.automl: 08-22 21:09:32] {1358} INFO - iteration 22, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:33] {1515} INFO - at 15.8s,\tbest lgbm's error=0.1693,\tbest lgbm's error=0.1693\n",
"[flaml.automl: 08-22 21:09:33] {1358} INFO - iteration 23, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:34] {1515} INFO - at 16.9s,\tbest lgbm's error=0.1693,\tbest lgbm's error=0.1693\n",
"[flaml.automl: 08-22 21:09:34] {1358} INFO - iteration 24, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:35] {1515} INFO - at 18.1s,\tbest lgbm's error=0.1693,\tbest lgbm's error=0.1693\n",
"[flaml.automl: 08-22 21:09:35] {1358} INFO - iteration 25, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:38] {1515} INFO - at 20.9s,\tbest lgbm's error=0.1685,\tbest lgbm's error=0.1685\n",
"[flaml.automl: 08-22 21:09:38] {1358} INFO - iteration 26, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:39] {1515} INFO - at 22.0s,\tbest lgbm's error=0.1685,\tbest lgbm's error=0.1685\n",
"[flaml.automl: 08-22 21:09:39] {1358} INFO - iteration 27, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:47] {1515} INFO - at 30.0s,\tbest lgbm's error=0.1685,\tbest lgbm's error=0.1685\n",
"[flaml.automl: 08-22 21:09:47] {1358} INFO - iteration 28, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:50] {1515} INFO - at 32.7s,\tbest lgbm's error=0.1685,\tbest lgbm's error=0.1685\n",
"[flaml.automl: 08-22 21:09:50] {1358} INFO - iteration 29, current learner lgbm\n",
"[flaml.automl: 08-22 21:09:51] {1515} INFO - at 33.6s,\tbest lgbm's error=0.1685,\tbest lgbm's error=0.1685\n",
"[flaml.automl: 08-22 21:09:51] {1358} INFO - iteration 30, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:09] {1515} INFO - at 52.0s,\tbest lgbm's error=0.1685,\tbest lgbm's error=0.1685\n",
"[flaml.automl: 08-22 21:10:09] {1358} INFO - iteration 31, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:11] {1515} INFO - at 54.1s,\tbest lgbm's error=0.1685,\tbest lgbm's error=0.1685\n",
"[flaml.automl: 08-22 21:10:11] {1358} INFO - iteration 32, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:17] {1515} INFO - at 59.6s,\tbest lgbm's error=0.1609,\tbest lgbm's error=0.1609\n",
"[flaml.automl: 08-22 21:10:17] {1358} INFO - iteration 33, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:22] {1515} INFO - at 65.1s,\tbest lgbm's error=0.1609,\tbest lgbm's error=0.1609\n",
"[flaml.automl: 08-22 21:10:22] {1358} INFO - iteration 34, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:26] {1515} INFO - at 68.7s,\tbest lgbm's error=0.1609,\tbest lgbm's error=0.1609\n",
"[flaml.automl: 08-22 21:10:26] {1358} INFO - iteration 35, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:45] {1515} INFO - at 88.0s,\tbest lgbm's error=0.1609,\tbest lgbm's error=0.1609\n",
"[flaml.automl: 08-22 21:10:45] {1358} INFO - iteration 36, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:46] {1515} INFO - at 88.9s,\tbest lgbm's error=0.1609,\tbest lgbm's error=0.1609\n",
"[flaml.automl: 08-22 21:10:46] {1358} INFO - iteration 37, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:54] {1515} INFO - at 96.6s,\tbest lgbm's error=0.1573,\tbest lgbm's error=0.1573\n",
"[flaml.automl: 08-22 21:10:54] {1358} INFO - iteration 38, current learner lgbm\n",
"[flaml.automl: 08-22 21:10:57] {1515} INFO - at 99.6s,\tbest lgbm's error=0.1573,\tbest lgbm's error=0.1573\n",
"[flaml.automl: 08-22 21:10:57] {1358} INFO - iteration 39, current learner lgbm\n",
"[flaml.automl: 08-22 21:11:57] {1515} INFO - at 160.1s,\tbest lgbm's error=0.1573,\tbest lgbm's error=0.1573\n",
"[flaml.automl: 08-22 21:11:57] {1358} INFO - iteration 40, current learner lgbm\n",
"[flaml.automl: 08-22 21:11:59] {1515} INFO - at 161.4s,\tbest lgbm's error=0.1573,\tbest lgbm's error=0.1573\n",
"[flaml.automl: 08-22 21:11:59] {1358} INFO - iteration 41, current learner lgbm\n",
"[flaml.automl: 08-22 21:12:00] {1515} INFO - at 162.5s,\tbest lgbm's error=0.1573,\tbest lgbm's error=0.1573\n",
"[flaml.automl: 08-22 21:12:00] {1358} INFO - iteration 42, current learner lgbm\n",
"[flaml.automl: 08-22 21:12:35] {1515} INFO - at 197.7s,\tbest lgbm's error=0.1535,\tbest lgbm's error=0.1535\n",
"[flaml.automl: 08-22 21:12:35] {1358} INFO - iteration 43, current learner lgbm\n",
"[flaml.automl: 08-22 21:13:09] {1515} INFO - at 231.6s,\tbest lgbm's error=0.1535,\tbest lgbm's error=0.1535\n",
"[flaml.automl: 08-22 21:13:09] {1592} INFO - selected model: LGBMRegressor(colsample_bytree=0.6513228229604555,\n",
" learning_rate=0.011556686284183076, max_bin=512,\n",
" min_child_samples=9, n_estimators=2120, num_leaves=92,\n",
" objective='regression', reg_alpha=0.024999216167840198,\n",
" reg_lambda=0.01918323581702806, verbose=-1)\n",
"[flaml.automl: 08-22 21:13:16] {1633} INFO - retrain lgbm for 6.6s\n",
"[flaml.automl: 08-22 21:13:16] {1636} INFO - retrained model: LGBMRegressor(colsample_bytree=0.6513228229604555,\n",
" learning_rate=0.011556686284183076, max_bin=512,\n",
" min_child_samples=9, n_estimators=2120, num_leaves=92,\n",
" objective='regression', reg_alpha=0.024999216167840198,\n",
" reg_lambda=0.01918323581702806, verbose=-1)\n",
"[flaml.automl: 08-22 21:13:16] {1199} INFO - fit succeeded\n",
"[flaml.automl: 08-22 21:13:16] {1200} INFO - Time taken to find the best model: 197.68836307525635\n",
"[flaml.automl: 08-22 21:13:16] {1205} WARNING - Time taken to find the best model is 82% of the provided time budget and not all estimators' hyperparameter search converged. Consider increasing the time budget.\n"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"slideshow": {
"slide_type": "slide"
},
"tags": []
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "markdown",
2021-08-23 19:36:51 -04:00
"source": [
"### Best model and metric"
],
2021-02-22 22:10:41 -08:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
2021-08-23 19:36:51 -04:00
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 5,
"source": [
"''' retrieve best config'''\n",
"print('Best hyperparmeter config:', automl.best_config)\n",
"print('Best r2 on validation data: {0:.4g}'.format(1-automl.best_loss))\n",
"print('Training duration of best run: {0:.4g} s'.format(automl.best_config_train_time))"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
2021-08-23 19:36:51 -04:00
"Best hyperparmeter config: {'n_estimators': 2120, 'num_leaves': 92, 'min_child_samples': 9, 'learning_rate': 0.011556686284183076, 'log_max_bin': 10, 'colsample_bytree': 0.6513228229604555, 'reg_alpha': 0.024999216167840198, 'reg_lambda': 0.01918323581702806}\n",
"Best r2 on validation data: 0.8465\n",
"Training duration of best run: 35.16 s\n"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
}
],
"metadata": {
"slideshow": {
"slide_type": "slide"
2021-08-23 19:36:51 -04:00
},
"tags": []
}
},
{
"cell_type": "code",
"execution_count": 6,
"source": [
"automl.model.estimator\n"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-08-23 19:36:51 -04:00
"output_type": "execute_result",
2021-02-22 22:10:41 -08:00
"data": {
2021-05-08 02:50:50 +00:00
"text/plain": [
2021-08-23 19:36:51 -04:00
"LGBMRegressor(colsample_bytree=0.6513228229604555,\n",
" learning_rate=0.011556686284183076, max_bin=512,\n",
" min_child_samples=9, n_estimators=2120, num_leaves=92,\n",
" objective='regression', reg_alpha=0.024999216167840198,\n",
" reg_lambda=0.01918323581702806, verbose=-1)"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
},
"metadata": {},
2021-08-23 19:36:51 -04:00
"execution_count": 6
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 7,
"source": [
"import matplotlib.pyplot as plt\n",
"plt.barh(automl.model.estimator.feature_name_, automl.model.estimator.feature_importances_)"
],
2021-08-23 16:26:46 -04:00
"outputs": [
{
2021-08-23 19:36:51 -04:00
"output_type": "execute_result",
2021-08-23 16:26:46 -04:00
"data": {
"text/plain": [
"<BarContainer object of 8 artists>"
]
},
"metadata": {},
2021-08-23 19:36:51 -04:00
"execution_count": 7
2021-08-23 16:26:46 -04:00
},
{
2021-08-23 19:36:51 -04:00
"output_type": "display_data",
2021-08-23 16:26:46 -04:00
"data": {
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
2021-08-23 19:36:51 -04:00
],
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"248.518125pt\" version=\"1.1\" viewBox=\"0 0 461.782812 248.518125\" width=\"461.782812pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 248.518125 \nL 461.782812 248.518125 \nL 461.782812 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 119.782813 224.64 \nL 454.582813 224.64 \nL 454.582813 7.2 \nL 119.782813 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"patch_3\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 214.756364 \nL 372.279786 214.756364 \nL 372.279786 194.482238 \nL 119.782813 194.482238 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_4\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 189.413706 \nL 310.139474 189.413706 \nL 310.139474 169.13958 \nL 119.782813 169.13958 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_5\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 164.071049 \nL 365.502756 164.071049 \nL 365.502756 143.796923 \nL 119.782813 143.796923 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_6\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 138.728392 \nL 348.191865 138.728392 \nL 348.191865 118.454266 \nL 119.782813 118.454266 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_7\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 113.385734 \nL 379.667169 113.385734 \nL 379.667169 93.111608 \nL 119.782813 93.111608 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_8\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 88.043077 \nL 341.530592 88.043077 \nL 341.530592 67.768951 \nL 119.782813 67.768951 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_9\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 62.70042 \nL 432.473279 62.70042 \nL 432.473279 42.426294 \nL 119.782813 42.426294 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_10\">\n <path clip-path=\"url(#pb483a497c3)\" d=\"M 119.782813 37.357762 \nL 438.639955 37.357762 \nL 438.639955 17.083636 \nL 119.782813 17.083636 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m88f1ead640\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"119.782813\" xlink:href=\"#m88f1ead640\" y=\"224.64\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <defs>\n <path d=\"M 31.78125 66.40625 \nQ 24.171875 66.40625 20.328125 58.90625 \nQ 16.5 51.421875 16.5 36.375 \nQ 16.5 21.390625 20.328125 13.890625 \nQ 24.171875 6.390625 31.78125 6.390625 \nQ 39.453125 6.390625 43.28125 13.890625 \nQ 47.125 21.390625 47.125 36.375 \nQ 47.125 51.421875 43.28125 58.90625 \nQ 39.453125 66.40625 31.78125 66.40625 \nz\nM 31.78125 74.21875 \nQ 44.046875 74.21875 50.515625 64.515625 \nQ 56.984375 54.828125 56.984375 36.375 \nQ 56.984375 17.96875 50.515625 8.265625 \nQ 44.046875 -1.421875 31.78125 -1.421875 \nQ 19.53125 -1.421875 13.0625 8.265625 \nQ 6.59375 17.96875 6.59375 36.375 \nQ 6.59375 54.828125 13.0625 64.515625 \nQ 19.53125 74.21875 31.78125 74.21875 \nz\n\" id=\"DejaVuSans-48\"/>\n </defs>\n <g transform=\"translate(116.601562 239.238438)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-48\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_2\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"172.399503\" xlink:href=\"#m88f1ead640\" y=\"224.64\"/>\n
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAD4CAYA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VkmJ00zM7NMTppmZmaZnDQHgaRGSasz2pxQ8rxZ0iWDH52ZmfWVk2b1NAJ/SZoR0RIRn6leOGZm1ptRmTTTKu8xSddKelTS9ZJ2kPQ+SSsktUu6UtLY1H69pItS/XJJb0v1V0maVdLvS92MtVTSI+lxWNp0AXC4pJWSzpZ0hKRb0z67SvqJpDZJyyRNTfXzU1xLJD0lyUnWzGwIjcqkmewLfDci3g68AHweuAqYHRFTKD4t6fSS9h2p/jvAxRWM8yzwgYiYBswGOk/BzgOWRkRTRHyrbJ/zgBURMRX4EnB1ybb9gA8ChwBfkTSmfEBJcyW1SGrZsqmjglDNzKwnozlp/joiHkjla4D3Aesi4vFUtwiYWdL+upKfh1YwzhjgCkntwGJg/4x9ZgA/AIiIe4HdJO2ctt0WEZsj4g8UCXmP8p0jYmFENEdEc90O9RWEamZmPRnNnz0bZc83Artltu8sv0b6j4ekbYDtutjvbOAZ4KDU9uW+BFtic0l5C6P7GJqZDanRvNJ8i6TOFeMJQAvQ2Hm9EjgJuK+k/eySnw+m8npgeiofTbGqLFcPPB0RW1Ofdan+RWCnbmJbCpwIIOkI4A8R8ULWrMzMbNCM5lXKWuBMSVcCvwA+AywDFkvaFngYuKyk/S6S2ihWev+Q6q4Abpa0CrgD+FMX43wXuEHSyWVt2oAtad+rgBUl+8wHrkzjbQLm9G+qZmY2EBRRfpay9klqBG6NiAMz268HmtN1xBFlbMPkaJhTyX1LZlar/NVg+SS1RkRzef1oPj1rZmZWkVF5ejYi1gNZq8zUvnHQgjEzsxHDK00zM7NMTppmZma
2021-08-23 16:26:46 -04:00
},
"metadata": {
"needs_background": "light"
2021-08-23 19:36:51 -04:00
}
2021-08-23 16:26:46 -04:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {}
2021-08-23 16:26:46 -04:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 8,
2021-02-22 22:10:41 -08:00
"source": [
2021-03-16 22:13:35 -07:00
"''' pickle and save the automl object '''\n",
2021-02-22 22:10:41 -08:00
"import pickle\n",
2021-03-16 22:13:35 -07:00
"with open('automl.pkl', 'wb') as f:\n",
" pickle.dump(automl, f, pickle.HIGHEST_PROTOCOL)"
2021-08-23 19:36:51 -04:00
],
"outputs": [],
2021-02-22 22:10:41 -08:00
"metadata": {
"slideshow": {
"slide_type": "slide"
2021-08-23 19:36:51 -04:00
}
}
},
{
"cell_type": "code",
"execution_count": 9,
"source": [
"''' compute predictions of testing dataset ''' \n",
"y_pred = automl.predict(X_test)\n",
"print('Predicted labels', y_pred)\n",
"print('True labels', y_test)"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
2021-08-23 19:36:51 -04:00
"Predicted labels [144012.37488361 251501.98425004 147503.3849682 ... 219178.01297482\n",
" 213834.88677304 272956.11149784]\n",
2021-07-24 20:10:43 -04:00
"True labels 14740 136900.0\n",
"10101 241300.0\n",
"20566 200700.0\n",
"2670 72500.0\n",
"15709 460000.0\n",
" ... \n",
"13132 121200.0\n",
"8228 137500.0\n",
"3948 160900.0\n",
"8522 227300.0\n",
"16798 265600.0\n",
"Name: median_house_value, Length: 5160, dtype: float64\n"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
}
],
"metadata": {
"slideshow": {
"slide_type": "slide"
},
"tags": []
2021-08-23 19:36:51 -04:00
}
},
{
"cell_type": "code",
"execution_count": 10,
2021-02-22 22:10:41 -08:00
"source": [
"''' compute different metric values on testing dataset'''\n",
"from flaml.ml import sklearn_metric_loss_score\n",
"print('r2', '=', 1 - sklearn_metric_loss_score('r2', y_pred, y_test))\n",
"print('mse', '=', sklearn_metric_loss_score('mse', y_pred, y_test))\n",
"print('mae', '=', sklearn_metric_loss_score('mae', y_pred, y_test))"
2021-08-23 19:36:51 -04:00
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
2021-08-23 19:36:51 -04:00
"r2 = 0.8540590968156087\n",
"mse = 1929120783.4023921\n",
"mae = 28944.167002684408\n"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"slideshow": {
"slide_type": "slide"
},
"tags": []
}
},
{
"cell_type": "code",
"execution_count": 11,
2021-02-22 22:10:41 -08:00
"source": [
"from flaml.data import get_output_from_log\n",
"time_history, best_valid_loss_history, valid_loss_history, config_history, train_loss_history = \\\n",
2021-04-08 09:29:55 -07:00
" get_output_from_log(filename=settings['log_file_name'], time_budget=60)\n",
2021-02-22 22:10:41 -08:00
"\n",
"for config in config_history:\n",
" print(config)"
2021-08-23 19:36:51 -04:00
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-08-23 19:36:51 -04:00
"output_type": "stream",
"name": "stdout",
"text": [
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 4, 'num_leaves': 4, 'min_child_samples': 20, 'learning_rate': 0.09999999999999995, 'log_max_bin': 8, 'colsample_bytree': 1.0, 'reg_alpha': 0.0009765625, 'reg_lambda': 1.0}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 4, 'num_leaves': 4, 'min_child_samples': 20, 'learning_rate': 0.09999999999999995, 'log_max_bin': 8, 'colsample_bytree': 1.0, 'reg_alpha': 0.0009765625, 'reg_lambda': 1.0}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 4, 'num_leaves': 4, 'min_child_samples': 12, 'learning_rate': 0.26770501231052046, 'log_max_bin': 7, 'colsample_bytree': 1.0, 'reg_alpha': 0.001348364934537134, 'reg_lambda': 1.4442580148221913}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 4, 'num_leaves': 4, 'min_child_samples': 12, 'learning_rate': 0.26770501231052046, 'log_max_bin': 7, 'colsample_bytree': 1.0, 'reg_alpha': 0.001348364934537134, 'reg_lambda': 1.4442580148221913}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 11, 'num_leaves': 4, 'min_child_samples': 9, 'learning_rate': 0.7260594590615893, 'log_max_bin': 9, 'colsample_bytree': 0.9285002286474459, 'reg_alpha': 0.0036840681931986645, 'reg_lambda': 0.7532480505730402}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 11, 'num_leaves': 4, 'min_child_samples': 9, 'learning_rate': 0.7260594590615893, 'log_max_bin': 9, 'colsample_bytree': 0.9285002286474459, 'reg_alpha': 0.0036840681931986645, 'reg_lambda': 0.7532480505730402}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 13, 'num_leaves': 5, 'min_child_samples': 5, 'learning_rate': 0.7590459488450945, 'log_max_bin': 8, 'colsample_bytree': 0.8304072431299575, 'reg_alpha': 0.001951378031519758, 'reg_lambda': 0.04792552866398477}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 13, 'num_leaves': 5, 'min_child_samples': 5, 'learning_rate': 0.7590459488450945, 'log_max_bin': 8, 'colsample_bytree': 0.8304072431299575, 'reg_alpha': 0.001951378031519758, 'reg_lambda': 0.04792552866398477}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 44, 'num_leaves': 4, 'min_child_samples': 4, 'learning_rate': 0.41929025492645006, 'log_max_bin': 8, 'colsample_bytree': 0.7610534336273627, 'reg_alpha': 0.0009765625, 'reg_lambda': 0.009280655005879927}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 44, 'num_leaves': 4, 'min_child_samples': 4, 'learning_rate': 0.41929025492645006, 'log_max_bin': 8, 'colsample_bytree': 0.7610534336273627, 'reg_alpha': 0.0009765625, 'reg_lambda': 0.009280655005879927}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 141, 'num_leaves': 17, 'min_child_samples': 3, 'learning_rate': 0.17402065726724145, 'log_max_bin': 8, 'colsample_bytree': 0.6649148062238498, 'reg_alpha': 0.0009765625, 'reg_lambda': 0.006761362450996487}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 141, 'num_leaves': 17, 'min_child_samples': 3, 'learning_rate': 0.17402065726724145, 'log_max_bin': 8, 'colsample_bytree': 0.6649148062238498, 'reg_alpha': 0.0009765625, 'reg_lambda': 0.006761362450996487}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 88, 'num_leaves': 70, 'min_child_samples': 4, 'learning_rate': 0.09348689572544734, 'log_max_bin': 7, 'colsample_bytree': 0.5967846088487322, 'reg_alpha': 0.006958608037974516, 'reg_lambda': 0.001895876878997586}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 88, 'num_leaves': 70, 'min_child_samples': 4, 'learning_rate': 0.09348689572544734, 'log_max_bin': 7, 'colsample_bytree': 0.5967846088487322, 'reg_alpha': 0.006958608037974516, 'reg_lambda': 0.001895876878997586}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 166, 'num_leaves': 34, 'min_child_samples': 2, 'learning_rate': 0.11549142333280608, 'log_max_bin': 8, 'colsample_bytree': 0.6469726212777197, 'reg_alpha': 0.032619809462956464, 'reg_lambda': 0.00406523645285879}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 166, 'num_leaves': 34, 'min_child_samples': 2, 'learning_rate': 0.11549142333280608, 'log_max_bin': 8, 'colsample_bytree': 0.6469726212777197, 'reg_alpha': 0.032619809462956464, 'reg_lambda': 0.00406523645285879}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 108, 'num_leaves': 169, 'min_child_samples': 2, 'learning_rate': 0.07154128424526202, 'log_max_bin': 9, 'colsample_bytree': 0.591579264701285, 'reg_alpha': 0.01435520144866301, 'reg_lambda': 0.006874802748054271}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 108, 'num_leaves': 169, 'min_child_samples': 2, 'learning_rate': 0.07154128424526202, 'log_max_bin': 9, 'colsample_bytree': 0.591579264701285, 'reg_alpha': 0.01435520144866301, 'reg_lambda': 0.006874802748054271}}\n",
"{'Current Learner': 'lgbm', 'Current Sample': 15480, 'Current Hyper-parameters': {'n_estimators': 256, 'num_leaves': 79, 'min_child_samples': 4, 'learning_rate': 0.06020420143131026, 'log_max_bin': 10, 'colsample_bytree': 0.6501336877031868, 'reg_alpha': 0.11324823332770402, 'reg_lambda': 0.007122448821650475}, 'Best Learner': 'lgbm', 'Best Hyper-parameters': {'n_estimators': 256, 'num_leaves': 79, 'min_child_samples': 4, 'learning_rate': 0.06020420143131026, 'log_max_bin': 10, 'colsample_bytree': 0.6501336877031868, 'reg_alpha': 0.11324823332770402, 'reg_lambda': 0.007122448821650475}}\n"
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"slideshow": {
"slide_type": "subslide"
},
"tags": []
}
},
{
"cell_type": "code",
"execution_count": 12,
2021-02-22 22:10:41 -08:00
"source": [
"import numpy as np\n",
"\n",
"plt.title('Learning Curve')\n",
"plt.xlabel('Wall Clock Time (s)')\n",
"plt.ylabel('Validation r2')\n",
2021-04-08 09:29:55 -07:00
"plt.scatter(time_history, 1 - np.array(valid_loss_history))\n",
"plt.step(time_history, 1 - np.array(best_valid_loss_history), where='post')\n",
2021-02-22 22:10:41 -08:00
"plt.show()"
2021-08-23 19:36:51 -04:00
],
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
],
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"277.314375pt\" version=\"1.1\" viewBox=\"0 0 385.78125 277.314375\" width=\"385.78125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 277.314375 \nL 385.78125 277.314375 \nL 385.78125 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.78125 239.758125 \nL 378.58125 239.758125 \nL 378.58125 22.318125 \nL 43.78125 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"PathCollection_1\">\n <defs>\n <path d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" id=\"m9e50c90c0e\" style=\"stroke:#1f77b4;\"/>\n </defs>\n <g clip-path=\"url(#pe183d4fd05)\">\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"58.999432\" xlink:href=\"#m9e50c90c0e\" y=\"229.874489\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"60.29259\" xlink:href=\"#m9e50c90c0e\" y=\"165.947004\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"61.230038\" xlink:href=\"#m9e50c90c0e\" y=\"83.318294\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"63.355922\" xlink:href=\"#m9e50c90c0e\" y=\"70.153617\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"66.439931\" xlink:href=\"#m9e50c90c0e\" y=\"59.476113\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"70.788765\" xlink:href=\"#m9e50c90c0e\" y=\"38.274163\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"86.025719\" xlink:href=\"#m9e50c90c0e\" y=\"37.526888\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"133.283873\" xlink:href=\"#m9e50c90c0e\" y=\"35.069197\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"164.218892\" xlink:href=\"#m9e50c90c0e\" y=\"34.775195\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"363.363068\" xlink:href=\"#m9e50c90c0e\" y=\"32.201761\"/>\n </g>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"mf8f9691493\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"56.223439\" xlink:href=\"#mf8f9691493\" y=\"239.758125\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <defs>\n <path d=\"M 31.78125 66.40625 \nQ 24.171875 66.40625 20.328125 58.90625 \nQ 16.5 51.421875 16.5 36.375 \nQ 16.5 21.390625 20.328125 13.890625 \nQ 24.171875 6.390625 31.78125 6.390625 \nQ 39.453125 6.390625 43.28125 13.890625 \nQ 47.125 21.390625 47.125 36.375 \nQ 47.125 51.421875 43.28125 58.90625 \nQ 39.453125 66.40625 31.78125 66.40625 \nz\nM 31.78125 74.21875 \nQ 44.046875 74.21875 50.515625 64.515625 \nQ 56.984375 54.828125 56.984375 36.375 \nQ 56.984375 17.96875 50.515625 8.265625 \nQ 44.046875 -1.421875 31.78125 -1.421875 \nQ 19.53125 -1.421875 13.0625 8.265625 \nQ 6.59375 17.96875 6.59375 36.375 \nQ 6.59375 54.828125 13.0625 64.515625 \nQ 19.53125 74.21875 31.78125 74.21875 \nz\n\" id=\"DejaVuSans-48\"/>\n </defs>\n <g transform=\"translate(53.042189 254.356562)scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-48\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_2\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"107.77538\" xlink:href=\"#mf8f9691493\" y=\"239.758125\"/>\n </g>\n
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEWCAYAAABrDZDcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAdJklEQVR4nO3dfZwcVZ3v8c83QyBBHgJmZCEPJCwhCgoJRhAfAXUTWAVckAX2tVfxIboLrCveIFFEFi73hZtdvPi6US9wEfXyHEMIGIkogisgSSBAEnAwPEgyAUkIQYwjSSa/+0dVh0rT09Mzmeqe7vq+X69+TdepU1W/A53+9TlVdUoRgZmZFdeQRgdgZmaN5URgZlZwTgRmZgXnRGBmVnBOBGZmBedEYGZWcE4EZlVIer+kjkbHYZYnJwIbtCQ9K+nDjYwhIv4rIibmtX9JUyX9StKrktZKulfSCXkdz6wSJwIrNEltDTz2KcAtwA+B0cA+wIXAx/qxL0nyv2frF39wrOlIGiLpfElPSXpJ0s2S9s6sv0XSC5JeSX9tH5JZd62k70paIGkjcEza8/jvkh5Lt7lJ0rC0/tGSVme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KuSpgGn5hqVmZnVTY89goh4FHhG0i/LyjdHxHW5R2ZmZnVR9fLRiOgGtkras07xmJlZnVUbGir5E7BM0l3AxlJhRPxLblGZmVnd1JII5qavPkvPJ1wBtAFXR8RlFeqcClxEciXSoxFxRn+OZWZm/dNrIoiIH/Rnx5LagNnAR4DVwGJJ8yPi8UydCcBM4L0R8bKkt/TnWGZm1n95zjV0BLAyIp6OiE3AjSSXnmZ9DpgdES8
},
"metadata": {
"needs_background": "light"
}
}
],
"metadata": {
"slideshow": {
"slide_type": "slide"
}
}
2021-02-22 22:10:41 -08:00
},
{
2021-07-24 20:10:43 -04:00
"cell_type": "markdown",
2021-02-22 22:10:41 -08:00
"source": [
"## 3. Comparison with alternatives\n",
"\n",
"### FLAML's accuracy"
2021-08-23 19:36:51 -04:00
],
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 13,
"source": [
"print('flaml r2', '=', 1 - sklearn_metric_loss_score('r2', y_pred, y_test))"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
2021-08-23 19:36:51 -04:00
"flaml r2 = 0.8540590968156087\n"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"tags": []
}
2021-02-22 22:10:41 -08:00
},
{
2021-07-24 20:10:43 -04:00
"cell_type": "markdown",
2021-02-22 22:10:41 -08:00
"source": [
"### Default LightGBM"
2021-08-23 19:36:51 -04:00
],
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 14,
2021-02-22 22:10:41 -08:00
"source": [
"from lightgbm import LGBMRegressor\n",
"lgbm = LGBMRegressor()"
2021-08-23 19:36:51 -04:00
],
"outputs": [],
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 15,
"source": [
"lgbm.fit(X_train, y_train)"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-08-23 19:36:51 -04:00
"output_type": "execute_result",
2021-02-22 22:10:41 -08:00
"data": {
2021-05-08 02:50:50 +00:00
"text/plain": [
"LGBMRegressor()"
]
2021-02-22 22:10:41 -08:00
},
"metadata": {},
2021-08-23 19:36:51 -04:00
"execution_count": 15
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 16,
"source": [
"y_pred = lgbm.predict(X_test)\n",
"from flaml.ml import sklearn_metric_loss_score\n",
"print('default lgbm r2', '=', 1 - sklearn_metric_loss_score('r2', y_pred, y_test))"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
"default lgbm r2 = 0.8296179648694404\n"
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"tags": []
}
2021-02-22 22:10:41 -08:00
},
{
2021-07-24 20:10:43 -04:00
"cell_type": "markdown",
2021-02-22 22:10:41 -08:00
"source": [
"### Optuna LightGBM Tuner"
2021-08-23 19:36:51 -04:00
],
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 17,
2021-02-22 22:10:41 -08:00
"source": [
2021-07-24 20:10:43 -04:00
"# !pip install optuna==2.8.0;"
2021-08-23 19:36:51 -04:00
],
"outputs": [],
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 18,
2021-02-22 22:10:41 -08:00
"source": [
"from sklearn.model_selection import train_test_split\n",
"train_x, val_x, train_y, val_y = train_test_split(X_train, y_train, test_size=0.1)\n",
"import optuna.integration.lightgbm as lgb\n",
"dtrain = lgb.Dataset(train_x, label=train_y)\n",
"dval = lgb.Dataset(val_x, label=val_y)\n",
"params = {\n",
" \"objective\": \"regression\",\n",
" \"metric\": \"regression\",\n",
" \"verbosity\": -1,\n",
"}\n"
2021-08-23 19:36:51 -04:00
],
"outputs": [],
"metadata": {}
2021-02-22 22:10:41 -08:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 19,
"source": [
"%%time\n",
"model = lgb.train(params, dtrain, valid_sets=[dtrain, dval], verbose_eval=10000) \n"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stderr",
2021-07-24 20:10:43 -04:00
"text": [
2021-08-23 19:36:51 -04:00
"\u001b[32m[I 2021-08-22 21:13:20,495]\u001b[0m A new study created in memory with name: no-name-11015170-733e-470d-817a-413f55382d0c\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 14%|#4 | 1/7 [00:01<00:08, 1.49s/it]\u001b[32m[I 2021-08-22 21:13:22,006]\u001b[0m Trial 0 finished with value: 1923826918.4421172 and parameters: {'feature_fraction': 0.8999999999999999}. Best is trial 0 with value: 1923826918.4421172.\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 29%|##8 | 2/7 [00:02<00:07, 1.44s/it]\u001b[32m[I 2021-08-22 21:13:23,335]\u001b[0m Trial 1 finished with value: 1935542284.5841475 and parameters: {'feature_fraction': 0.6}. Best is trial 0 with value: 1923826918.4421172.\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 43%|####2 | 3/7 [00:04<00:05, 1.44s/it]\u001b[32m[I 2021-08-22 21:13:24,762]\u001b[0m Trial 2 finished with value: 1959693958.979498 and parameters: {'feature_fraction': 0.7}. Best is trial 0 with value: 1923826918.4421172.\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 57%|#####7 | 4/7 [00:05<00:04, 1.38s/it]\u001b[32m[I 2021-08-22 21:13:26,021]\u001b[0m Trial 3 finished with value: 2237193094.1989536 and parameters: {'feature_fraction': 0.4}. Best is trial 0 with value: 1923826918.4421172.\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 71%|#######1 | 5/7 [00:06<00:02, 1.36s/it]\u001b[32m[I 2021-08-22 21:13:27,314]\u001b[0m Trial 4 finished with value: 1988198059.953293 and parameters: {'feature_fraction': 0.5}. Best is trial 0 with value: 1923826918.4421172.\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 86%|########5 | 6/7 [00:08<00:01, 1.37s/it]\u001b[32m[I 2021-08-22 21:13:28,719]\u001b[0m Trial 5 finished with value: 1959693958.979498 and parameters: {'feature_fraction': 0.8}. Best is trial 0 with value: 1923826918.4421172.\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 100%|##########| 7/7 [00:09<00:00, 1.42s/it]\u001b[32m[I 2021-08-22 21:13:30,240]\u001b[0m Trial 6 finished with value: 1961388150.442425 and parameters: {'feature_fraction': 1.0}. Best is trial 0 with value: 1923826918.4421172.\u001b[0m\n",
"feature_fraction, val_score: 1923826918.442117: 100%|##########| 7/7 [00:09<00:00, 1.39s/it]\n",
"num_leaves, val_score: 1902337773.833954: 5%|5 | 1/20 [00:02<00:41, 2.21s/it]\u001b[32m[I 2021-08-22 21:13:32,454]\u001b[0m Trial 7 finished with value: 1902337773.8339543 and parameters: {'num_leaves': 62}. Best is trial 7 with value: 1902337773.8339543.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 10%|# | 2/20 [00:04<00:42, 2.35s/it]\u001b[32m[I 2021-08-22 21:13:35,126]\u001b[0m Trial 8 finished with value: 1892120308.4363017 and parameters: {'num_leaves': 78}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 15%|#5 | 3/20 [00:06<00:34, 2.03s/it]\u001b[32m[I 2021-08-22 21:13:36,422]\u001b[0m Trial 9 finished with value: 1924633212.447515 and parameters: {'num_leaves': 26}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 20%|## | 4/20 [00:07<00:27, 1.70s/it]\u001b[32m[I 2021-08-22 21:13:37,340]\u001b[0m Trial 10 finished with value: 1975840134.2036633 and parameters: {'num_leaves': 12}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 25%|##5 | 5/20 [00:13<00:46, 3.12s/it]\u001b[32m[I 2021-08-22 21:13:43,773]\u001b[0m Trial 11 finished with value: 1923702276.2852578 and parameters: {'num_leaves': 204}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 30%|### | 6/20 [00:20<00:59, 4.24s/it]\u001b[32m[I 2021-08-22 21:13:50,646]\u001b[0m Trial 12 finished with value: 1939984702.0007648 and parameters: {'num_leaves': 214}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 35%|###5 | 7/20 [00:23<00:49, 3.79s/it]\u001b[32m[I 2021-08-22 21:13:53,368]\u001b[0m Trial 13 finished with value: 1942261187.1568937 and parameters: {'num_leaves': 61}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 40%|#### | 8/20 [00:33<01:09, 5.81s/it]\u001b[32m[I 2021-08-22 21:14:03,909]\u001b[0m Trial 14 finished with value: 1962322296.1656826 and parameters: {'num_leaves': 234}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 45%|####5 | 9/20 [00:38<01:00, 5.52s/it]\u001b[32m[I 2021-08-22 21:14:08,728]\u001b[0m Trial 15 finished with value: 1933575055.0360022 and parameters: {'num_leaves': 131}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1892120308.436302: 50%|##### | 10/20 [00:41<00:47, 4.70s/it]\u001b[32m[I 2021-08-22 21:14:11,527]\u001b[0m Trial 16 finished with value: 1907396468.702243 and parameters: {'num_leaves': 64}. Best is trial 8 with value: 1892120308.4363017.\u001b[0m\n",
"num_leaves, val_score: 1880656950.656438: 55%|#####5 | 11/20 [00:46<00:43, 4.83s/it]\u001b[32m[I 2021-08-22 21:14:16,641]\u001b[0m Trial 17 finished with value: 1880656950.6564376 and parameters: {'num_leaves': 141}. Best is trial 17 with value: 1880656950.6564376.\u001b[0m\n",
"num_leaves, val_score: 1880656950.656438: 60%|###### | 12/20 [00:51<00:38, 4.80s/it]\u001b[32m[I 2021-08-22 21:14:21,399]\u001b[0m Trial 18 finished with value: 1906428309.75546 and parameters: {'num_leaves': 139}. Best is trial 17 with value: 1880656950.6564376.\u001b[0m\n",
"num_leaves, val_score: 1880656950.656438: 65%|######5 | 13/20 [00:56<00:35, 5.07s/it]\u001b[32m[I 2021-08-22 21:14:27,074]\u001b[0m Trial 19 finished with value: 1897071192.2731016 and parameters: {'num_leaves': 161}. Best is trial 17 with value: 1880656950.6564376.\u001b[0m\n",
"num_leaves, val_score: 1880656950.656438: 70%|####### | 14/20 [01:01<00:28, 4.81s/it]\u001b[32m[I 2021-08-22 21:14:31,276]\u001b[0m Trial 20 finished with value: 1910775598.9420693 and parameters: {'num_leaves': 95}. Best is trial 17 with value: 1880656950.6564376.\u001b[0m\n",
"num_leaves, val_score: 1880656950.656438: 75%|#######5 | 15/20 [01:04<00:22, 4.44s/it]\u001b[32m[I 2021-08-22 21:14:34,857]\u001b[0m Trial 21 finished with value: 1890350018.7742429 and parameters: {'num_leaves': 101}. Best is trial 17 with value: 1880656950.6564376.\u001b[0m\n",
"num_leaves, val_score: 1874647481.354196: 80%|######## | 16/20 [01:10<00:19, 4.84s/it]\u001b[32m[I 2021-08-22 21:14:40,645]\u001b[0m Trial 22 finished with value: 1874647481.354196 and parameters: {'num_leaves': 174}. Best is trial 22 with value: 1874647481.354196.\u001b[0m\n",
"num_leaves, val_score: 1874647481.354196: 85%|########5 | 17/20 [01:16<00:15, 5.12s/it]\u001b[32m[I 2021-08-22 21:14:46,424]\u001b[0m Trial 23 finished with value: 1929626032.4915411 and parameters: {'num_leaves': 176}. Best is trial 22 with value: 1874647481.354196.\u001b[0m\n",
"num_leaves, val_score: 1874647481.354196: 90%|######### | 18/20 [01:22<00:10, 5.35s/it]\u001b[32m[I 2021-08-22 21:14:52,288]\u001b[0m Trial 24 finished with value: 1926786945.429698 and parameters: {'num_leaves': 177}. Best is trial 22 with value: 1874647481.354196.\u001b[0m\n",
"num_leaves, val_score: 1874647481.354196: 95%|#########5| 19/20 [01:30<00:06, 6.26s/it]\u001b[32m[I 2021-08-22 21:15:00,672]\u001b[0m Trial 25 finished with value: 1936436149.7610657 and parameters: {'num_leaves': 248}. Best is trial 22 with value: 1874647481.354196.\u001b[0m\n",
"num_leaves, val_score: 1870787631.458499: 100%|##########| 20/20 [01:35<00:00, 5.93s/it]\u001b[32m[I 2021-08-22 21:15:05,849]\u001b[0m Trial 26 finished with value: 1870787631.4584987 and parameters: {'num_leaves': 152}. Best is trial 26 with value: 1870787631.4584987.\u001b[0m\n",
"num_leaves, val_score: 1870787631.458499: 100%|##########| 20/20 [01:35<00:00, 4.78s/it]\n",
"bagging, val_score: 1870787631.458499: 10%|# | 1/10 [00:07<01:06, 7.43s/it]\u001b[32m[I 2021-08-22 21:15:13,289]\u001b[0m Trial 27 finished with value: 2237757312.870728 and parameters: {'bagging_fraction': 0.44000087334449334, 'bagging_freq': 6}. Best is trial 27 with value: 2237757312.870728.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 20%|## | 2/10 [00:15<01:01, 7.71s/it]\u001b[32m[I 2021-08-22 21:15:21,655]\u001b[0m Trial 28 finished with value: 2162729069.0272393 and parameters: {'bagging_fraction': 0.5075440331178458, 'bagging_freq': 3}. Best is trial 28 with value: 2162729069.0272393.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 30%|### | 3/10 [00:21<00:49, 7.05s/it]\u001b[32m[I 2021-08-22 21:15:27,150]\u001b[0m Trial 29 finished with value: 2003355452.8831115 and parameters: {'bagging_fraction': 0.757776235401641, 'bagging_freq': 1}. Best is trial 29 with value: 2003355452.8831115.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 40%|#### | 4/10 [00:28<00:42, 7.02s/it]\u001b[32m[I 2021-08-22 21:15:34,105]\u001b[0m Trial 30 finished with value: 2169017536.089679 and parameters: {'bagging_fraction': 0.5470758964212703, 'bagging_freq': 4}. Best is trial 29 with value: 2003355452.8831115.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 50%|##### | 5/10 [00:33<00:32, 6.49s/it]\u001b[32m[I 2021-08-22 21:15:39,358]\u001b[0m Trial 31 finished with value: 1949886129.0973551 and parameters: {'bagging_fraction': 0.7729694462744219, 'bagging_freq': 1}. Best is trial 31 with value: 1949886129.0973551.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 60%|###### | 6/10 [00:40<00:26, 6.53s/it]\u001b[32m[I 2021-08-22 21:15:45,996]\u001b[0m Trial 32 finished with value: 2082597134.5380604 and parameters: {'bagging_fraction': 0.6293524485160634, 'bagging_freq': 6}. Best is trial 31 with value: 1949886129.0973551.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 70%|####### | 7/10 [00:46<00:19, 6.57s/it]\u001b[32m[I 2021-08-22 21:15:52,653]\u001b[0m Trial 33 finished with value: 2128522268.181099 and parameters: {'bagging_fraction': 0.5194460357854906, 'bagging_freq': 4}. Best is trial 31 with value: 1949886129.0973551.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 80%|######## | 8/10 [00:53<00:12, 6.49s/it]\u001b[32m[I 2021-08-22 21:15:58,939]\u001b[0m Trial 34 finished with value: 1972329936.356194 and parameters: {'bagging_fraction': 0.7021495661140726, 'bagging_freq': 2}. Best is trial 31 with value: 1949886129.0973551.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 90%|######### | 9/10 [00:58<00:06, 6.15s/it]\u001b[32m[I 2021-08-22 21:16:04,316]\u001b[0m Trial 35 finished with value: 2035847515.436036 and parameters: {'bagging_fraction': 0.7365019160691924, 'bagging_freq': 1}. Best is trial 31 with value: 1949886129.0973551.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 100%|##########| 10/10 [01:05<00:00, 6.27s/it]\u001b[32m[I 2021-08-22 21:16:10,869]\u001b[0m Trial 36 finished with value: 2089685881.7609503 and parameters: {'bagging_fraction': 0.5702856203071842, 'bagging_freq': 6}. Best is trial 31 with value: 1949886129.0973551.\u001b[0m\n",
"bagging, val_score: 1870787631.458499: 100%|##########| 10/10 [01:05<00:00, 6.50s/it]\n",
"feature_fraction_stage2, val_score: 1870787631.458499: 17%|#6 | 1/6 [00:05<00:25, 5.10s/it]\u001b[32m[I 2021-08-22 21:16:15,976]\u001b[0m Trial 37 finished with value: 1915845450.4267912 and parameters: {'feature_fraction': 0.9799999999999999}. Best is trial 37 with value: 1915845450.4267912.\u001b[0m\n",
"feature_fraction_stage2, val_score: 1870787631.458499: 33%|###3 | 2/6 [00:09<00:20, 5.02s/it]\u001b[32m[I 2021-08-22 21:16:20,814]\u001b[0m Trial 38 finished with value: 1870787631.4584987 and parameters: {'feature_fraction': 0.852}. Best is trial 38 with value: 1870787631.4584987.\u001b[0m\n",
"feature_fraction_stage2, val_score: 1870787631.458499: 50%|##### | 3/6 [00:14<00:14, 4.95s/it]\u001b[32m[I 2021-08-22 21:16:25,594]\u001b[0m Trial 39 finished with value: 1870787631.4584987 and parameters: {'feature_fraction': 0.8839999999999999}. Best is trial 38 with value: 1870787631.4584987.\u001b[0m\n",
"feature_fraction_stage2, val_score: 1870787631.458499: 67%|######6 | 4/6 [00:20<00:10, 5.08s/it]\u001b[32m[I 2021-08-22 21:16:30,990]\u001b[0m Trial 40 finished with value: 1915845450.4267912 and parameters: {'feature_fraction': 0.948}. Best is trial 38 with value: 1870787631.4584987.\u001b[0m\n",
"feature_fraction_stage2, val_score: 1870787631.458499: 83%|########3 | 5/6 [00:25<00:05, 5.19s/it]\u001b[32m[I 2021-08-22 21:16:36,418]\u001b[0m Trial 41 finished with value: 1870787631.4584987 and parameters: {'feature_fraction': 0.9159999999999999}. Best is trial 38 with value: 1870787631.4584987.\u001b[0m\n",
"feature_fraction_stage2, val_score: 1870787631.458499: 100%|##########| 6/6 [00:31<00:00, 5.39s/it]\u001b[32m[I 2021-08-22 21:16:42,282]\u001b[0m Trial 42 finished with value: 1870787631.4584987 and parameters: {'feature_fraction': 0.82}. Best is trial 38 with value: 1870787631.4584987.\u001b[0m\n",
"feature_fraction_stage2, val_score: 1870787631.458499: 100%|##########| 6/6 [00:31<00:00, 5.24s/it]\n",
"regularization_factors, val_score: 1870787631.458499: 5%|5 | 1/20 [00:05<01:41, 5.36s/it]\u001b[32m[I 2021-08-22 21:16:47,653]\u001b[0m Trial 43 finished with value: 1870787631.491234 and parameters: {'lambda_l1': 6.212193776886605e-06, 'lambda_l2': 3.009357838100163e-08}. Best is trial 43 with value: 1870787631.491234.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 10%|# | 2/20 [00:12<01:44, 5.82s/it]\u001b[32m[I 2021-08-22 21:16:54,524]\u001b[0m Trial 44 finished with value: 1870787534.9732666 and parameters: {'lambda_l1': 4.443479994016017e-08, 'lambda_l2': 3.556819404354524e-05}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 15%|#5 | 3/20 [00:17<01:36, 5.65s/it]\u001b[32m[I 2021-08-22 21:16:59,795]\u001b[0m Trial 45 finished with value: 1870787622.4979687 and parameters: {'lambda_l1': 0.014465195791714083, 'lambda_l2': 2.1021138174252987e-07}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 20%|## | 4/20 [00:22<01:28, 5.52s/it]\u001b[32m[I 2021-08-22 21:17:05,006]\u001b[0m Trial 46 finished with value: 1870787619.5326774 and parameters: {'lambda_l1': 1.429709851157171e-06, 'lambda_l2': 4.419238564285042e-06}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 25%|##5 | 5/20 [00:28<01:22, 5.51s/it]\u001b[32m[I 2021-08-22 21:17:10,496]\u001b[0m Trial 47 finished with value: 1870787590.2959824 and parameters: {'lambda_l1': 0.06926729801332972, 'lambda_l2': 1.6922599199508456e-08}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 30%|### | 6/20 [00:33<01:16, 5.44s/it]\u001b[32m[I 2021-08-22 21:17:15,768]\u001b[0m Trial 48 finished with value: 1870787630.8453631 and parameters: {'lambda_l1': 2.052098028013423e-08, 'lambda_l2': 2.3337138419589934e-07}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 35%|###5 | 7/20 [00:38<01:10, 5.39s/it]\u001b[32m[I 2021-08-22 21:17:21,046]\u001b[0m Trial 49 finished with value: 1876699891.9815595 and parameters: {'lambda_l1': 4.304944401004946e-06, 'lambda_l2': 0.0007656130560392606}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 40%|#### | 8/20 [00:44<01:04, 5.37s/it]\u001b[32m[I 2021-08-22 21:17:26,372]\u001b[0m Trial 50 finished with value: 1894915643.8553405 and parameters: {'lambda_l1': 5.783302142631901e-07, 'lambda_l2': 0.005857904967523283}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1870787534.973267: 45%|####5 | 9/20 [00:49<00:58, 5.32s/it]\u001b[32m[I 2021-08-22 21:17:31,570]\u001b[0m Trial 51 finished with value: 1877059069.215943 and parameters: {'lambda_l1': 2.9196198134708893, 'lambda_l2': 4.6093049397982125e-05}. Best is trial 44 with value: 1870787534.9732666.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 50%|##### | 10/20 [00:54<00:53, 5.34s/it]\u001b[32m[I 2021-08-22 21:17:36,944]\u001b[0m Trial 52 finished with value: 1853015384.453637 and parameters: {'lambda_l1': 0.09558504914610533, 'lambda_l2': 3.220273228431258}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 55%|#####5 | 11/20 [01:00<00:49, 5.45s/it]\u001b[32m[I 2021-08-22 21:17:42,672]\u001b[0m Trial 53 finished with value: 1896992309.3706267 and parameters: {'lambda_l1': 6.575749289036579, 'lambda_l2': 7.662096538085835}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 60%|###### | 12/20 [01:06<00:44, 5.56s/it]\u001b[32m[I 2021-08-22 21:17:48,473]\u001b[0m Trial 54 finished with value: 1893493622.3798478 and parameters: {'lambda_l1': 0.0008722383951977965, 'lambda_l2': 0.13339065517857865}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 65%|######5 | 13/20 [01:12<00:39, 5.68s/it]\u001b[32m[I 2021-08-22 21:17:54,425]\u001b[0m Trial 55 finished with value: 1895459424.4650118 and parameters: {'lambda_l1': 0.046018652714269824, 'lambda_l2': 3.596577171855534}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 70%|####### | 14/20 [01:17<00:33, 5.57s/it]\u001b[32m[I 2021-08-22 21:17:59,760]\u001b[0m Trial 56 finished with value: 1902235965.6523015 and parameters: {'lambda_l1': 0.0004372538444200538, 'lambda_l2': 0.018403234102680837}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 75%|#######5 | 15/20 [01:23<00:27, 5.57s/it]\u001b[32m[I 2021-08-22 21:18:05,311]\u001b[0m Trial 57 finished with value: 1870787547.884662 and parameters: {'lambda_l1': 1.5644444125721077e-08, 'lambda_l2': 3.06684587723285e-05}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 80%|######## | 16/20 [01:28<00:22, 5.56s/it]\u001b[32m[I 2021-08-22 21:18:10,860]\u001b[0m Trial 58 finished with value: 1952628057.3679152 and parameters: {'lambda_l1': 0.41090501100060367, 'lambda_l2': 0.4784149571785825}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 85%|########5 | 17/20 [01:34<00:16, 5.66s/it]\u001b[32m[I 2021-08-22 21:18:16,748]\u001b[0m Trial 59 finished with value: 1874516545.805995 and parameters: {'lambda_l1': 4.63176126114126e-05, 'lambda_l2': 0.0002597320589400073}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 90%|######### | 18/20 [01:40<00:11, 5.80s/it]\u001b[32m[I 2021-08-22 21:18:22,861]\u001b[0m Trial 60 finished with value: 1870787615.0912282 and parameters: {'lambda_l1': 0.007392465833323452, 'lambda_l2': 4.3888082066628725e-06}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 95%|#########5| 19/20 [01:46<00:05, 5.72s/it]\u001b[32m[I 2021-08-22 21:18:28,403]\u001b[0m Trial 61 finished with value: 1859899631.3896043 and parameters: {'lambda_l1': 1.573671858757602e-07, 'lambda_l2': 0.0021763888923074476}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 100%|##########| 20/20 [01:51<00:00, 5.70s/it]\u001b[32m[I 2021-08-22 21:18:34,066]\u001b[0m Trial 62 finished with value: 1905701773.7289548 and parameters: {'lambda_l1': 0.7977530430827201, 'lambda_l2': 0.6661855838737094}. Best is trial 52 with value: 1853015384.453637.\u001b[0m\n",
"regularization_factors, val_score: 1853015384.453637: 100%|##########| 20/20 [01:51<00:00, 5.59s/it]\n",
"min_data_in_leaf, val_score: 1853015384.453637: 20%|## | 1/5 [00:04<00:19, 4.95s/it]\u001b[32m[I 2021-08-22 21:18:39,027]\u001b[0m Trial 63 finished with value: 1859286747.0773554 and parameters: {'min_child_samples': 10}. Best is trial 63 with value: 1859286747.0773554.\u001b[0m\n",
"min_data_in_leaf, val_score: 1853015384.453637: 40%|#### | 2/5 [00:09<00:14, 4.87s/it]\u001b[32m[I 2021-08-22 21:18:43,705]\u001b[0m Trial 64 finished with value: 1877906183.7743464 and parameters: {'min_child_samples': 5}. Best is trial 63 with value: 1859286747.0773554.\u001b[0m\n",
"min_data_in_leaf, val_score: 1853015384.453637: 60%|###### | 3/5 [00:15<00:10, 5.15s/it]\u001b[32m[I 2021-08-22 21:18:49,514]\u001b[0m Trial 65 finished with value: 1996406986.7947733 and parameters: {'min_child_samples': 100}. Best is trial 63 with value: 1859286747.0773554.\u001b[0m\n",
"min_data_in_leaf, val_score: 1853015384.453637: 80%|######## | 4/5 [00:22<00:05, 5.82s/it]\u001b[32m[I 2021-08-22 21:18:56,904]\u001b[0m Trial 66 finished with value: 1983678395.4383106 and parameters: {'min_child_samples': 50}. Best is trial 63 with value: 1859286747.0773554.\u001b[0m\n",
"min_data_in_leaf, val_score: 1853015384.453637: 100%|##########| 5/5 [00:28<00:00, 5.92s/it]\u001b[32m[I 2021-08-22 21:19:03,042]\u001b[0m Trial 67 finished with value: 1906448776.6538603 and parameters: {'min_child_samples': 25}. Best is trial 63 with value: 1859286747.0773554.\u001b[0m\n",
"min_data_in_leaf, val_score: 1853015384.453637: 100%|##########| 5/5 [00:28<00:00, 5.79s/it]"
2021-07-24 20:10:43 -04:00
]
},
{
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-07-24 20:10:43 -04:00
"text": [
2021-08-23 19:36:51 -04:00
"CPU times: user 5min 24s, sys: 17.3 s, total: 5min 41s\n",
"Wall time: 5min 42s\n"
2021-07-24 20:10:43 -04:00
]
},
{
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stderr",
2021-05-08 02:50:50 +00:00
"text": [
"\n"
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"tags": [
"outputPrepend"
]
}
2021-02-22 22:10:41 -08:00
},
2021-04-10 21:14:28 -04:00
{
"cell_type": "markdown",
2021-08-23 19:36:51 -04:00
"source": [],
"metadata": {}
2021-04-10 21:14:28 -04:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 20,
"source": [
"y_pred = model.predict(X_test)\n",
"from flaml.ml import sklearn_metric_loss_score\n",
"print('Optuna LightGBM Tuner r2', '=', 1 - sklearn_metric_loss_score('r2', y_pred, y_test))"
],
2021-05-08 02:50:50 +00:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
2021-08-23 19:36:51 -04:00
"Optuna LightGBM Tuner r2 = 0.8428464421292586\n"
2021-05-08 02:50:50 +00:00
]
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"tags": []
}
2021-04-10 21:14:28 -04:00
},
{
"cell_type": "markdown",
"source": [
"## 4. Add a customized LightGBM learner in FLAML\n",
"The native API of LightGBM allows one to specify a custom objective function in the model constructor. You can easily enable it by adding a customized LightGBM learner in FLAML. In the following example, we show how to add such a customized LightGBM learner with a custom objective function."
2021-08-23 19:36:51 -04:00
],
"metadata": {}
2021-04-10 21:14:28 -04:00
},
{
"cell_type": "markdown",
"source": [
"### Create a customized LightGBM learner with a custom objective function"
2021-08-23 19:36:51 -04:00
],
"metadata": {}
2021-04-10 21:14:28 -04:00
},
2021-02-22 22:10:41 -08:00
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 21,
2021-04-10 21:14:28 -04:00
"source": [
"\n",
"import numpy as np \n",
"\n",
"''' define your customized objective function '''\n",
"def my_loss_obj(y_true, y_pred):\n",
" c = 0.5\n",
" residual = y_pred - y_true\n",
" grad = c * residual /(np.abs(residual) + c)\n",
" hess = c ** 2 / (np.abs(residual) + c) ** 2\n",
" # rmse grad and hess\n",
" grad_rmse = residual\n",
" hess_rmse = 1.0\n",
" \n",
" # mae grad and hess\n",
" grad_mae = np.array(residual)\n",
" grad_mae[grad_mae > 0] = 1.\n",
" grad_mae[grad_mae <= 0] = -1.\n",
" hess_mae = 1.0\n",
"\n",
" coef = [0.4, 0.3, 0.3]\n",
" return coef[0] * grad + coef[1] * grad_rmse + coef[2] * grad_mae, \\\n",
" coef[0] * hess + coef[1] * hess_rmse + coef[2] * hess_mae\n",
"\n",
"\n",
"from flaml.model import LGBMEstimator\n",
"\n",
"''' create a customized LightGBM learner class with your objective function '''\n",
"class MyLGBM(LGBMEstimator):\n",
" '''LGBMEstimator with my_loss_obj as the objective function\n",
" '''\n",
"\n",
" def __init__(self, **params):\n",
" super().__init__(objective=my_loss_obj, **params)"
2021-08-23 19:36:51 -04:00
],
"outputs": [],
"metadata": {}
2021-04-10 21:14:28 -04:00
},
{
"cell_type": "markdown",
"source": [
"### Add the customized learner in FLAML"
2021-08-23 19:36:51 -04:00
],
"metadata": {}
2021-04-10 21:14:28 -04:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 22,
2021-04-10 21:14:28 -04:00
"source": [
"automl = AutoML()\n",
"automl.add_learner(learner_name='my_lgbm', learner_class=MyLGBM)\n",
"settings = {\n",
2021-07-24 20:10:43 -04:00
" \"time_budget\": 150, # total running time in seconds\n",
2021-04-10 21:14:28 -04:00
" \"metric\": 'r2', # primary metrics for regression can be chosen from: ['mae','mse','r2']\n",
" \"estimator_list\": ['my_lgbm',], # list of ML learners; we tune lightgbm in this example\n",
" \"task\": 'regression', # task type \n",
" \"log_file_name\": 'houses_experiment_my_lgbm.log', # flaml log file\n",
"}\n",
"automl.fit(X_train=X_train, y_train=y_train, **settings)"
2021-08-23 19:36:51 -04:00
],
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"[flaml.automl: 08-22 21:19:04] {1130} INFO - Evaluation method: cv\n",
"[flaml.automl: 08-22 21:19:04] {634} INFO - Using RepeatedKFold\n",
"[flaml.automl: 08-22 21:19:04] {1155} INFO - Minimizing error metric: 1-r2\n",
"[flaml.automl: 08-22 21:19:04] {1175} INFO - List of ML learners in AutoML Run: ['my_lgbm']\n",
"[flaml.automl: 08-22 21:19:04] {1358} INFO - iteration 0, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:04] {1515} INFO - at 0.2s,\tbest my_lgbm's error=2.9888,\tbest my_lgbm's error=2.9888\n",
"[flaml.automl: 08-22 21:19:04] {1358} INFO - iteration 1, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:04] {1515} INFO - at 0.3s,\tbest my_lgbm's error=2.9888,\tbest my_lgbm's error=2.9888\n",
"[flaml.automl: 08-22 21:19:04] {1358} INFO - iteration 2, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:04] {1515} INFO - at 0.5s,\tbest my_lgbm's error=1.7087,\tbest my_lgbm's error=1.7087\n",
"[flaml.automl: 08-22 21:19:04] {1358} INFO - iteration 3, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:05] {1515} INFO - at 0.6s,\tbest my_lgbm's error=0.3465,\tbest my_lgbm's error=0.3465\n",
"[flaml.automl: 08-22 21:19:05] {1358} INFO - iteration 4, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:05] {1515} INFO - at 0.8s,\tbest my_lgbm's error=0.3465,\tbest my_lgbm's error=0.3465\n",
"[flaml.automl: 08-22 21:19:05] {1358} INFO - iteration 5, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:05] {1515} INFO - at 1.0s,\tbest my_lgbm's error=0.3005,\tbest my_lgbm's error=0.3005\n",
"[flaml.automl: 08-22 21:19:05] {1358} INFO - iteration 6, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:05] {1515} INFO - at 1.2s,\tbest my_lgbm's error=0.3005,\tbest my_lgbm's error=0.3005\n",
"[flaml.automl: 08-22 21:19:05] {1358} INFO - iteration 7, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:05] {1515} INFO - at 1.3s,\tbest my_lgbm's error=0.3005,\tbest my_lgbm's error=0.3005\n",
"[flaml.automl: 08-22 21:19:05] {1358} INFO - iteration 8, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:06] {1515} INFO - at 1.6s,\tbest my_lgbm's error=0.2709,\tbest my_lgbm's error=0.2709\n",
"[flaml.automl: 08-22 21:19:06] {1358} INFO - iteration 9, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:06] {1515} INFO - at 1.8s,\tbest my_lgbm's error=0.2709,\tbest my_lgbm's error=0.2709\n",
"[flaml.automl: 08-22 21:19:06] {1358} INFO - iteration 10, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:07] {1515} INFO - at 2.8s,\tbest my_lgbm's error=0.1852,\tbest my_lgbm's error=0.1852\n",
"[flaml.automl: 08-22 21:19:07] {1358} INFO - iteration 11, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:08] {1515} INFO - at 3.9s,\tbest my_lgbm's error=0.1852,\tbest my_lgbm's error=0.1852\n",
"[flaml.automl: 08-22 21:19:08] {1358} INFO - iteration 12, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:09] {1515} INFO - at 4.7s,\tbest my_lgbm's error=0.1852,\tbest my_lgbm's error=0.1852\n",
"[flaml.automl: 08-22 21:19:09] {1358} INFO - iteration 13, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:10] {1515} INFO - at 5.7s,\tbest my_lgbm's error=0.1852,\tbest my_lgbm's error=0.1852\n",
"[flaml.automl: 08-22 21:19:10] {1358} INFO - iteration 14, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:11] {1515} INFO - at 6.8s,\tbest my_lgbm's error=0.1852,\tbest my_lgbm's error=0.1852\n",
"[flaml.automl: 08-22 21:19:11] {1358} INFO - iteration 15, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:12] {1515} INFO - at 8.1s,\tbest my_lgbm's error=0.1804,\tbest my_lgbm's error=0.1804\n",
"[flaml.automl: 08-22 21:19:12] {1358} INFO - iteration 16, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:13] {1515} INFO - at 9.0s,\tbest my_lgbm's error=0.1804,\tbest my_lgbm's error=0.1804\n",
"[flaml.automl: 08-22 21:19:13] {1358} INFO - iteration 17, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:17] {1515} INFO - at 12.9s,\tbest my_lgbm's error=0.1777,\tbest my_lgbm's error=0.1777\n",
"[flaml.automl: 08-22 21:19:17] {1358} INFO - iteration 18, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:18] {1515} INFO - at 14.3s,\tbest my_lgbm's error=0.1777,\tbest my_lgbm's error=0.1777\n",
"[flaml.automl: 08-22 21:19:18] {1358} INFO - iteration 19, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:20] {1515} INFO - at 15.7s,\tbest my_lgbm's error=0.1777,\tbest my_lgbm's error=0.1777\n",
"[flaml.automl: 08-22 21:19:20] {1358} INFO - iteration 20, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:28] {1515} INFO - at 24.1s,\tbest my_lgbm's error=0.1777,\tbest my_lgbm's error=0.1777\n",
"[flaml.automl: 08-22 21:19:28] {1358} INFO - iteration 21, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:32] {1515} INFO - at 27.9s,\tbest my_lgbm's error=0.1777,\tbest my_lgbm's error=0.1777\n",
"[flaml.automl: 08-22 21:19:32] {1358} INFO - iteration 22, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:34] {1515} INFO - at 30.4s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:19:34] {1358} INFO - iteration 23, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:36] {1515} INFO - at 32.4s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:19:36] {1358} INFO - iteration 24, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:41] {1515} INFO - at 36.9s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:19:41] {1358} INFO - iteration 25, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:51] {1515} INFO - at 47.4s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:19:51] {1358} INFO - iteration 26, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:52] {1515} INFO - at 48.3s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:19:52] {1358} INFO - iteration 27, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:19:59] {1515} INFO - at 55.1s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:19:59] {1358} INFO - iteration 28, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:00] {1515} INFO - at 56.3s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:20:00] {1358} INFO - iteration 29, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:01] {1515} INFO - at 57.0s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:20:01] {1358} INFO - iteration 30, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:16] {1515} INFO - at 72.2s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:20:16] {1358} INFO - iteration 31, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:18] {1515} INFO - at 74.1s,\tbest my_lgbm's error=0.1715,\tbest my_lgbm's error=0.1715\n",
"[flaml.automl: 08-22 21:20:18] {1358} INFO - iteration 32, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:22] {1515} INFO - at 78.3s,\tbest my_lgbm's error=0.1669,\tbest my_lgbm's error=0.1669\n",
"[flaml.automl: 08-22 21:20:22] {1358} INFO - iteration 33, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:26] {1515} INFO - at 82.0s,\tbest my_lgbm's error=0.1669,\tbest my_lgbm's error=0.1669\n",
"[flaml.automl: 08-22 21:20:26] {1358} INFO - iteration 34, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:29] {1515} INFO - at 84.6s,\tbest my_lgbm's error=0.1669,\tbest my_lgbm's error=0.1669\n",
"[flaml.automl: 08-22 21:20:29] {1358} INFO - iteration 35, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:46] {1515} INFO - at 101.8s,\tbest my_lgbm's error=0.1669,\tbest my_lgbm's error=0.1669\n",
"[flaml.automl: 08-22 21:20:46] {1358} INFO - iteration 36, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:47] {1515} INFO - at 102.9s,\tbest my_lgbm's error=0.1669,\tbest my_lgbm's error=0.1669\n",
"[flaml.automl: 08-22 21:20:47] {1358} INFO - iteration 37, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:55] {1515} INFO - at 111.2s,\tbest my_lgbm's error=0.1597,\tbest my_lgbm's error=0.1597\n",
"[flaml.automl: 08-22 21:20:55] {1358} INFO - iteration 38, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:20:58] {1515} INFO - at 114.5s,\tbest my_lgbm's error=0.1597,\tbest my_lgbm's error=0.1597\n",
"[flaml.automl: 08-22 21:20:58] {1358} INFO - iteration 39, current learner my_lgbm\n",
"[flaml.automl: 08-22 21:21:37] {1515} INFO - at 153.5s,\tbest my_lgbm's error=0.1597,\tbest my_lgbm's error=0.1597\n",
"[flaml.automl: 08-22 21:21:37] {1592} INFO - selected model: LGBMRegressor(colsample_bytree=0.8251774147208681,\n",
" learning_rate=0.21049408131691624, max_bin=512,\n",
" min_child_samples=19, n_estimators=196, num_leaves=195,\n",
" objective=<function my_loss_obj at 0x7f85d9922c10>,\n",
" reg_alpha=0.0009765625, reg_lambda=0.0117923889609937,\n",
" verbose=-1)\n",
"[flaml.automl: 08-22 21:21:39] {1633} INFO - retrain my_lgbm for 1.6s\n",
"[flaml.automl: 08-22 21:21:39] {1636} INFO - retrained model: LGBMRegressor(colsample_bytree=0.8251774147208681,\n",
" learning_rate=0.21049408131691624, max_bin=512,\n",
" min_child_samples=19, n_estimators=196, num_leaves=195,\n",
" objective=<function my_loss_obj at 0x7f85d9922c10>,\n",
" reg_alpha=0.0009765625, reg_lambda=0.0117923889609937,\n",
" verbose=-1)\n",
"[flaml.automl: 08-22 21:21:39] {1199} INFO - fit succeeded\n",
"[flaml.automl: 08-22 21:21:39] {1200} INFO - Time taken to find the best model: 111.22549629211426\n",
"[flaml.automl: 08-22 21:21:39] {1205} WARNING - Time taken to find the best model is 74% of the provided time budget and not all estimators' hyperparameter search converged. Consider increasing the time budget.\n"
]
}
],
"metadata": {
"tags": []
}
2021-04-10 21:14:28 -04:00
},
{
"cell_type": "code",
2021-08-23 19:36:51 -04:00
"execution_count": 23,
"source": [
"print('Best hyperparmeter config:', automl.best_config)\n",
"print('Best r2 on validation data: {0:.4g}'.format(1-automl.best_loss))\n",
"print('Training duration of best run: {0:.4g} s'.format(automl.best_config_train_time))\n",
"\n",
"y_pred = automl.predict(X_test)\n",
"print('Predicted labels', y_pred)\n",
"print('True labels', y_test)\n",
"\n",
"from flaml.ml import sklearn_metric_loss_score\n",
"print('r2', '=', 1 - sklearn_metric_loss_score('r2', y_pred, y_test))\n",
"print('mse', '=', sklearn_metric_loss_score('mse', y_pred, y_test))\n",
"print('mae', '=', sklearn_metric_loss_score('mae', y_pred, y_test))"
],
2021-02-22 22:10:41 -08:00
"outputs": [
{
2021-07-24 20:10:43 -04:00
"output_type": "stream",
2021-08-23 19:36:51 -04:00
"name": "stdout",
2021-05-08 02:50:50 +00:00
"text": [
2021-08-23 19:36:51 -04:00
"Best hyperparmeter config: {'n_estimators': 196, 'num_leaves': 195, 'min_child_samples': 19, 'learning_rate': 0.21049408131691624, 'log_max_bin': 10, 'colsample_bytree': 0.8251774147208681, 'reg_alpha': 0.0009765625, 'reg_lambda': 0.0117923889609937}\n",
"Best r2 on validation data: 0.8403\n",
"Training duration of best run: 8.28 s\n",
"Predicted labels [137336.50894266 249721.8950541 155077.11127769 ... 191822.32898046\n",
" 197332.92376977 286448.29599298]\n",
2021-07-24 20:10:43 -04:00
"True labels 14740 136900.0\n",
"10101 241300.0\n",
"20566 200700.0\n",
"2670 72500.0\n",
"15709 460000.0\n",
" ... \n",
"13132 121200.0\n",
"8228 137500.0\n",
"3948 160900.0\n",
"8522 227300.0\n",
"16798 265600.0\n",
"Name: median_house_value, Length: 5160, dtype: float64\n",
2021-08-23 19:36:51 -04:00
"r2 = 0.8498843855121221\n",
"mse = 1984304232.0760334\n",
"mae = 29465.919207148785\n"
2021-05-08 02:50:50 +00:00
]
2021-02-22 22:10:41 -08:00
}
],
2021-08-23 19:36:51 -04:00
"metadata": {
"tags": []
}
2021-02-22 22:10:41 -08:00
}
],
"metadata": {
2021-07-24 20:10:43 -04:00
"interpreter": {
2021-08-23 16:26:46 -04:00
"hash": "ea9f131eb1b7663628f6445553ba215a834e2f0b4d18774746f0f47938ce4671"
2021-07-24 20:10:43 -04:00
},
2021-02-22 22:10:41 -08:00
"kernelspec": {
2021-08-23 19:36:51 -04:00
"name": "python3",
"display_name": "Python 3.8.0 64-bit ('blend': conda)"
2021-02-22 22:10:41 -08:00
},
"language_info": {
"name": "python",
2021-08-23 19:36:51 -04:00
"version": "3.8.0",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
2021-02-22 22:10:41 -08:00
}
},
"nbformat": 4,
"nbformat_minor": 2
}