{"id":3856,"date":"2020-09-10T19:00:18","date_gmt":"2020-09-10T19:00:18","guid":{"rendered":"https:\/\/www.aiproblog.com\/index.php\/2020\/09\/10\/hyperopt-for-automated-machine-learning-with-scikit-learn\/"},"modified":"2020-09-10T19:00:18","modified_gmt":"2020-09-10T19:00:18","slug":"hyperopt-for-automated-machine-learning-with-scikit-learn","status":"publish","type":"post","link":"https:\/\/www.aiproblog.com\/index.php\/2020\/09\/10\/hyperopt-for-automated-machine-learning-with-scikit-learn\/","title":{"rendered":"HyperOpt for Automated Machine Learning With Scikit-Learn"},"content":{"rendered":"<p>Author: Jason Brownlee<\/p>\n<div>\n<p>Automated Machine Learning (AutoML) refers to techniques for automatically discovering well-performing models for predictive modeling tasks with very little user involvement.<\/p>\n<p>HyperOpt is an open-source library for large scale AutoML and HyperOpt-Sklearn is a wrapper for HyperOpt that supports AutoML with HyperOpt for the popular Scikit-Learn machine learning library, including the suite of data preparation transforms and classification and regression algorithms.<\/p>\n<p>In this tutorial, you will discover how to use HyperOpt for automatic machine learning with Scikit-Learn in Python.<\/p>\n<p>After completing this tutorial, you will know:<\/p>\n<ul>\n<li>Hyperopt-Sklearn is an open-source library for AutoML with scikit-learn data preparation and machine learning models.<\/li>\n<li>How to use Hyperopt-Sklearn to automatically discover top-performing models for classification tasks.<\/li>\n<li>How to use Hyperopt-Sklearn to automatically discover top-performing models for regression tasks.<\/li>\n<\/ul>\n<p>Let&rsquo;s get started.<\/p>\n<div id=\"attachment_10491\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-10491\" loading=\"lazy\" class=\"size-full wp-image-10491\" src=\"https:\/\/machinelearningmastery.com\/wp-content\/uploads\/2020\/06\/HyperOpt-for-Automated-Machine-Learning-With-Scikit-Learn.jpg\" alt=\"HyperOpt for Automated Machine Learning With Scikit-Learn\" width=\"800\" height=\"532\" srcset=\"http:\/\/3qeqpr26caki16dnhd19sv6by6v.wpengine.netdna-cdn.com\/wp-content\/uploads\/2020\/06\/HyperOpt-for-Automated-Machine-Learning-With-Scikit-Learn.jpg 800w, http:\/\/3qeqpr26caki16dnhd19sv6by6v.wpengine.netdna-cdn.com\/wp-content\/uploads\/2020\/06\/HyperOpt-for-Automated-Machine-Learning-With-Scikit-Learn-300x200.jpg 300w, http:\/\/3qeqpr26caki16dnhd19sv6by6v.wpengine.netdna-cdn.com\/wp-content\/uploads\/2020\/06\/HyperOpt-for-Automated-Machine-Learning-With-Scikit-Learn-768x511.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\"><\/p>\n<p id=\"caption-attachment-10491\" class=\"wp-caption-text\">HyperOpt for Automated Machine Learning With Scikit-Learn<br \/>Photo by <a href=\"https:\/\/flickr.com\/photos\/neillwphoto\/22975134619\/\">Neil Williamson<\/a>, some rights reserved.<\/p>\n<\/div>\n<h2>Tutorial Overview<\/h2>\n<p>This tutorial is divided into four parts; they are:<\/p>\n<ol>\n<li>HyperOpt and HyperOpt-Sklearn<\/li>\n<li>How to Install and Use HyperOpt-Sklearn<\/li>\n<li>HyperOpt-Sklearn for Classification<\/li>\n<li>HyperOpt-Sklearn for Regression<\/li>\n<\/ol>\n<h2>HyperOpt and HyperOpt-Sklearn<\/h2>\n<p><a href=\"http:\/\/hyperopt.github.io\/hyperopt\/\">HyperOpt<\/a> is an open-source Python library for Bayesian optimization developed by <a href=\"https:\/\/www.linkedin.com\/in\/james-bergstra\">James Bergstra<\/a>.<\/p>\n<p>It is designed for large-scale optimization for models with hundreds of parameters and allows the optimization procedure to be scaled across multiple cores and multiple machines.<\/p>\n<p>The library was explicitly used to optimize machine learning pipelines, including data preparation, model selection, and model hyperparameters.<\/p>\n<blockquote>\n<p>Our approach is to expose the underlying expression graph of how a performance metric (e.g. classification accuracy on validation examples) is computed from hyperparameters that govern not only how individual processing steps are applied, but even which processing steps are included.<\/p>\n<\/blockquote>\n<p>&mdash; <a href=\"https:\/\/dl.acm.org\/doi\/10.5555\/3042817.3042832\">Making a Science of Model Search: Hyperparameter Optimization in Hundreds of Dimensions for Vision Architectures<\/a>, 2013.<\/p>\n<p>HyperOpt is challenging to use directly, requiring the optimization procedure and search space to be carefully specified.<\/p>\n<p>An extension to HyperOpt was created called <a href=\"http:\/\/hyperopt.github.io\/hyperopt-sklearn\/\">HyperOpt-Sklearn<\/a> that allows the HyperOpt procedure to be applied to data preparation and machine learning models provided by the popular <a href=\"https:\/\/scikit-learn.org\/stable\/\">Scikit-Learn open-source machine learning library<\/a>.<\/p>\n<p>HyperOpt-Sklearn wraps the HyperOpt library and allows for the automatic search of data preparation methods, machine learning algorithms, and model hyperparameters for classification and regression tasks.<\/p>\n<blockquote>\n<p>&hellip; we introduce Hyperopt-Sklearn: a project that brings the benefits of automatic algorithm configuration to users of Python and scikit-learn. Hyperopt-Sklearn uses Hyperopt to describe a search space over possible configurations of Scikit-Learn components, including preprocessing and classification modules.<\/p>\n<\/blockquote>\n<p>&mdash; <a href=\"https:\/\/conference.scipy.org\/proceedings\/scipy2014\/pdfs\/komer.pdf\">Hyperopt-Sklearn: Automatic Hyperparameter Configuration for Scikit-Learn<\/a>, 2014.<\/p>\n<p>Now that we are familiar with HyperOpt and HyperOpt-Sklearn, let&rsquo;s look at how to use HyperOpt-Sklearn.<\/p>\n<h2>How to Install and Use HyperOpt-Sklearn<\/h2>\n<p>The first step is to install the HyperOpt library.<\/p>\n<p>This can be achieved using the pip package manager as follows:<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">sudo pip install hyperopt<\/pre>\n<p>Once installed, we can confirm that the installation was successful and check the version of the library by typing the following command:<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">sudo pip show hyperopt<\/pre>\n<p>This will summarize the installed version of HyperOpt, confirming that a modern version is being used.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">Name: hyperopt\r\nVersion: 0.2.3\r\nSummary: Distributed Asynchronous Hyperparameter Optimization\r\nHome-page: http:\/\/hyperopt.github.com\/hyperopt\/\r\nAuthor: James Bergstra\r\nAuthor-email: james.bergstra@gmail.com\r\nLicense: BSD\r\nLocation: ...\r\nRequires: tqdm, six, networkx, future, scipy, cloudpickle, numpy\r\nRequired-by:<\/pre>\n<p>Next, we must install the HyperOpt-Sklearn library.<\/p>\n<p>This too can be installed using pip, although we must perform this operation manually by cloning the repository and running the installation from the local files, as follows:<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">git clone git@github.com:hyperopt\/hyperopt-sklearn.git\r\ncd hyperopt-sklearn\r\nsudo pip install .\r\ncd ..<\/pre>\n<p>Again, we can confirm that the installation was successful by checking the version number with the following command:<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">sudo pip show hpsklearn<\/pre>\n<p>This will summarize the installed version of HyperOpt-Sklearn, confirming that a modern version is being used.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">Name: hpsklearn\r\nVersion: 0.0.3\r\nSummary: Hyperparameter Optimization for sklearn\r\nHome-page: http:\/\/hyperopt.github.com\/hyperopt-sklearn\/\r\nAuthor: James Bergstra\r\nAuthor-email: anon@anon.com\r\nLicense: BSD\r\nLocation: ...\r\nRequires: nose, scikit-learn, numpy, scipy, hyperopt\r\nRequired-by:<\/pre>\n<p>Now that the required libraries are installed, we can review the HyperOpt-Sklearn API.<\/p>\n<p>Using HyperOpt-Sklearn is straightforward. The search process is defined by creating and configuring an instance of the HyperoptEstimator class.<\/p>\n<p>The algorithm used for the search can be specified via the &ldquo;<em>algo<\/em>&rdquo; argument, the number of evaluations performed in the search is specified via the &ldquo;<em>max_evals<\/em>&rdquo; argument, and a limit can be imposed on evaluating each pipeline via the &ldquo;<em>trial_timeout<\/em>&rdquo; argument.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# define search\r\nmodel = HyperoptEstimator(..., algo=tpe.suggest, max_evals=50, trial_timeout=120)<\/pre>\n<p>Many different optimization algorithms are available, including:<\/p>\n<ul>\n<li>Random Search<\/li>\n<li>Tree of Parzen Estimators<\/li>\n<li>Annealing<\/li>\n<li>Tree<\/li>\n<li>Gaussian Process Tree<\/li>\n<\/ul>\n<p>The &ldquo;<em>Tree of Parzen Estimators<\/em>&rdquo; is a good default, and you can learn more about the types of algorithms in the paper &ldquo;<a href=\"https:\/\/papers.nips.cc\/paper\/4443-algorithms-for-hyper-parameter-optimization.pdf\">Algorithms for Hyper-Parameter Optimization<\/a>. [PDF]&rdquo;<\/p>\n<p>For classification tasks, the &ldquo;<em>classifier<\/em>&rdquo; argument specifies the search space of models, and for regression, the &ldquo;<em>regressor<\/em>&rdquo; argument specifies the search space of models, both of which can be set to use predefined lists of models provided by the library, e.g. &ldquo;<em>any_classifier<\/em>&rdquo; and &ldquo;<em>any_regressor<\/em>&ldquo;.<\/p>\n<p>Similarly, the search space of data preparation is specified via the &ldquo;<em>preprocessing<\/em>&rdquo; argument and can also use a pre-defined list of preprocessing steps via &ldquo;<em>any_preprocessing<\/em>.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# define search\r\nmodel = HyperoptEstimator(classifier=any_classifier('cla'), preprocessing=any_preprocessing('pre'), ...)<\/pre>\n<p>For more on the other arguments to the search, you can review the source code for the class directly:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/hyperopt\/hyperopt-sklearn\/blob\/master\/hpsklearn\/estimator.py#L429\">Arguments to the HyperoptEstimator Class<\/a><\/li>\n<\/ul>\n<p>Once the search is defined, it can be executed by calling the <em>fit()<\/em> function.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# perform the search\r\nmodel.fit(X_train, y_train)<\/pre>\n<p>At the end of the run, the best-performing model can be evaluated on new data by calling the <em>score()<\/em> function.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# summarize performance\r\nacc = model.score(X_test, y_test)\r\nprint(\"Accuracy: %.3f\" % acc)<\/pre>\n<p>Finally, we can retrieve the <em>Pipeline<\/em> of transforms, models, and model configurations that performed the best on the training dataset via the <em>best_model()<\/em> function.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# summarize the best model\r\nprint(model.best_model())<\/pre>\n<p>Now that we are familiar with the API, let&rsquo;s look at some worked examples.<\/p>\n<h2>HyperOpt-Sklearn for Classification<\/h2>\n<p>In this section, we will use HyperOpt-Sklearn to discover a model for the sonar dataset.<\/p>\n<p>The sonar dataset is a standard machine learning dataset comprised of 208 rows of data with 60 numerical input variables and a target variable with two class values, e.g. binary classification.<\/p>\n<p>Using a test harness of repeated stratified 10-fold cross-validation with three repeats, a naive model can achieve an accuracy of about 53 percent. A top-performing model can achieve accuracy on this same test harness of about 88 percent. This provides the bounds of expected performance on this dataset.<\/p>\n<p>The dataset involves predicting whether sonar returns indicate a rock or simulated mine.<\/p>\n<ul>\n<li><a href=\"https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/sonar.csv\">Sonar Dataset (sonar.csv)<\/a><\/li>\n<li><a href=\"https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/sonar.names\">Sonar Dataset Description (sonar.names)<\/a><\/li>\n<\/ul>\n<p>No need to download the dataset; we will download it automatically as part of our worked examples.<\/p>\n<p>The example below downloads the dataset and summarizes its shape.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\"># summarize the sonar dataset\r\nfrom pandas import read_csv\r\n# load dataset\r\nurl = 'https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/sonar.csv'\r\ndataframe = read_csv(url, header=None)\r\n# split into input and output elements\r\ndata = dataframe.values\r\nX, y = data[:, :-1], data[:, -1]\r\nprint(X.shape, y.shape)<\/pre>\n<p>Running the example downloads the dataset and splits it into input and output elements. As expected, we can see that there are 208 rows of data with 60 input variables.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">(208, 60) (208,)<\/pre>\n<p>Next, let&rsquo;s use HyperOpt-Sklearn to find a good model for the sonar dataset.<\/p>\n<p>We can perform some basic data preparation, including converting the target string to class labels, then split the dataset into train and test sets.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# minimally prepare dataset\r\nX = X.astype('float32')\r\ny = LabelEncoder().fit_transform(y.astype('str'))\r\n# split into train and test sets\r\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1)<\/pre>\n<p>Next, we can define the search procedure. We will explore all classification algorithms and all data transforms available to the library and use the TPE, or Tree of Parzen Estimators, search algorithm, described in &ldquo;<a href=\"https:\/\/papers.nips.cc\/paper\/4443-algorithms-for-hyper-parameter-optimization.pdf\">Algorithms for Hyper-Parameter Optimization<\/a>.&rdquo;<\/p>\n<p>The search will evaluate 50 pipelines and limit each evaluation to 30 seconds.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# define search\r\nmodel = HyperoptEstimator(classifier=any_classifier('cla'), preprocessing=any_preprocessing('pre'), algo=tpe.suggest, max_evals=50, trial_timeout=30)<\/pre>\n<p>We then start the search.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# perform the search\r\nmodel.fit(X_train, y_train)<\/pre>\n<p>At the end of the run, we will report the performance of the model on the holdout dataset and summarize the best performing pipeline.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# summarize performance\r\nacc = model.score(X_test, y_test)\r\nprint(\"Accuracy: %.3f\" % acc)\r\n# summarize the best model\r\nprint(model.best_model())<\/pre>\n<p>Tying this together, the complete example is listed below.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\"># example of hyperopt-sklearn for the sonar classification dataset\r\nfrom pandas import read_csv\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.preprocessing import LabelEncoder\r\nfrom hpsklearn import HyperoptEstimator\r\nfrom hpsklearn import any_classifier\r\nfrom hpsklearn import any_preprocessing\r\nfrom hyperopt import tpe\r\n# load dataset\r\nurl = 'https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/sonar.csv'\r\ndataframe = read_csv(url, header=None)\r\n# split into input and output elements\r\ndata = dataframe.values\r\nX, y = data[:, :-1], data[:, -1]\r\n# minimally prepare dataset\r\nX = X.astype('float32')\r\ny = LabelEncoder().fit_transform(y.astype('str'))\r\n# split into train and test sets\r\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1)\r\n# define search\r\nmodel = HyperoptEstimator(classifier=any_classifier('cla'), preprocessing=any_preprocessing('pre'), algo=tpe.suggest, max_evals=50, trial_timeout=30)\r\n# perform the search\r\nmodel.fit(X_train, y_train)\r\n# summarize performance\r\nacc = model.score(X_test, y_test)\r\nprint(\"Accuracy: %.3f\" % acc)\r\n# summarize the best model\r\nprint(model.best_model())<\/pre>\n<p>Running the example may take a few minutes.<\/p>\n<p>The progress of the search will be reported and you will see some warnings that you can safely ignore.<\/p>\n<p>At the end of the run, the best-performing model is evaluated on the holdout dataset and the Pipeline discovered is printed for later use.<\/p>\n<p><strong>Note<\/strong>: Your <a href=\"https:\/\/machinelearningmastery.com\/different-results-each-time-in-machine-learning\/\">results may vary<\/a> given the stochastic nature of the algorithm or evaluation procedure, or differences in numerical precision. Consider running the example a few times and compare the average outcome.<\/p>\n<p>In this case, we can see that the chosen model achieved an accuracy of about 85.5 percent on the holdout test set. The Pipeline involves a gradient boosting model with no pre-processing.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">Accuracy: 0.855\r\n{'learner': GradientBoostingClassifier(ccp_alpha=0.0, criterion='friedman_mse', init=None,\r\n                           learning_rate=0.009132299586303643, loss='deviance',\r\n                           max_depth=None, max_features='sqrt',\r\n                           max_leaf_nodes=None, min_impurity_decrease=0.0,\r\n                           min_impurity_split=None, min_samples_leaf=1,\r\n                           min_samples_split=2, min_weight_fraction_leaf=0.0,\r\n                           n_estimators=342, n_iter_no_change=None,\r\n                           presort='auto', random_state=2,\r\n                           subsample=0.6844206624548879, tol=0.0001,\r\n                           validation_fraction=0.1, verbose=0,\r\n                           warm_start=False), 'preprocs': (), 'ex_preprocs': ()}<\/pre>\n<p>The printed model can then be used directly, e.g. the code copy-pasted into another project.<\/p>\n<p>Next, let&rsquo;s take a look at using HyperOpt-Sklearn for a regression predictive modeling problem.<\/p>\n<h2>HyperOpt-Sklearn for Regression<\/h2>\n<p>In this section, we will use HyperOpt-Sklearn to discover a model for the housing dataset.<\/p>\n<p>The housing dataset is a standard machine learning dataset comprised of 506 rows of data with 13 numerical input variables and a numerical target variable.<\/p>\n<p>Using a test harness of repeated stratified 10-fold cross-validation with three repeats, a naive model can achieve a mean absolute error (MAE) of about 6.6. A top-performing model can achieve a MAE on this same test harness of about 1.9. This provides the bounds of expected performance on this dataset.<\/p>\n<p>The dataset involves predicting the house price given details of the house suburb in the American city of Boston.<\/p>\n<ul>\n<li><a href=\"https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/housing.csv\">Housing Dataset (housing.csv)<\/a><\/li>\n<li><a href=\"https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/housing.names\">Housing Description (housing.names)<\/a><\/li>\n<\/ul>\n<p>No need to download the dataset; we will download it automatically as part of our worked examples.<\/p>\n<p>The example below downloads the dataset and summarizes its shape.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\"># summarize the auto insurance dataset\r\nfrom pandas import read_csv\r\n# load dataset\r\nurl = 'https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/housing.csv'\r\ndataframe = read_csv(url, header=None)\r\n# split into input and output elements\r\ndata = dataframe.values\r\nX, y = data[:, :-1], data[:, -1]\r\nprint(X.shape, y.shape)<\/pre>\n<p>Running the example downloads the dataset and splits it into input and output elements. As expected, we can see that there are 63 rows of data with one input variable.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">(208, 60), (208,)<\/pre>\n<p>Next, we can use HyperOpt-Sklearn to find a good model for the auto insurance dataset.<\/p>\n<p>Using HyperOpt-Sklearn for regression is the same as using it for classification, except the &ldquo;<em>regressor<\/em>&rdquo; argument must be specified.<\/p>\n<p>In this case, we want to optimize the MAE, therefore, we will set the &ldquo;<em>loss_fn<\/em>&rdquo; argument to the <em>mean_absolute_error()<\/em> function provided by the scikit-learn library.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">...\r\n# define search\r\nmodel = HyperoptEstimator(regressor=any_regressor('reg'), preprocessing=any_preprocessing('pre'), loss_fn=mean_absolute_error, algo=tpe.suggest, max_evals=50, trial_timeout=30)<\/pre>\n<p>Tying this together, the complete example is listed below.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\"># example of hyperopt-sklearn for the housing regression dataset\r\nfrom pandas import read_csv\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.metrics import mean_absolute_error\r\nfrom hpsklearn import HyperoptEstimator\r\nfrom hpsklearn import any_regressor\r\nfrom hpsklearn import any_preprocessing\r\nfrom hyperopt import tpe\r\n# load dataset\r\nurl = 'https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/housing.csv'\r\ndataframe = read_csv(url, header=None)\r\n# split into input and output elements\r\ndata = dataframe.values\r\ndata = data.astype('float32')\r\nX, y = data[:, :-1], data[:, -1]\r\n# split into train and test sets\r\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1)\r\n# define search\r\nmodel = HyperoptEstimator(regressor=any_regressor('reg'), preprocessing=any_preprocessing('pre'), loss_fn=mean_absolute_error, algo=tpe.suggest, max_evals=50, trial_timeout=30)\r\n# perform the search\r\nmodel.fit(X_train, y_train)\r\n# summarize performance\r\nmae = model.score(X_test, y_test)\r\nprint(\"MAE: %.3f\" % mae)\r\n# summarize the best model\r\nprint(model.best_model())<\/pre>\n<p>Running the example may take a few minutes.<\/p>\n<p>The progress of the search will be reported and you will see some warnings that you can safely ignore.<\/p>\n<p>At the end of the run, the best performing model is evaluated on the holdout dataset and the Pipeline discovered is printed for later use.<\/p>\n<p><strong>Note<\/strong>: Your <a href=\"https:\/\/machinelearningmastery.com\/different-results-each-time-in-machine-learning\/\">results may vary<\/a> given the stochastic nature of the algorithm or evaluation procedure, or differences in numerical precision. Consider running the example a few times and compare the average outcome.<\/p>\n<p>In this case, we can see that the chosen model achieved a MAE of about 0.883 on the holdout test set, which appears skillful. The Pipeline involves an <em>XGBRegressor<\/em> model with no pre-processing.<\/p>\n<p><strong>Note<\/strong>: for the search to use XGBoost, you must have the <a href=\"https:\/\/machinelearningmastery.com\/install-xgboost-python-macos\/\">XGBoost library installed<\/a>.<\/p>\n<pre class=\"urvanov-syntax-highlighter-plain-tag\">MAE: 0.883\r\n{'learner': XGBRegressor(base_score=0.5, booster='gbtree',\r\n             colsample_bylevel=0.5843250948679669, colsample_bynode=1,\r\n             colsample_bytree=0.6635160670570662, gamma=6.923399395303031e-05,\r\n             importance_type='gain', learning_rate=0.07021104887683309,\r\n             max_delta_step=0, max_depth=3, min_child_weight=5, missing=nan,\r\n             n_estimators=4000, n_jobs=1, nthread=None, objective='reg:linear',\r\n             random_state=0, reg_alpha=0.5690202874759704,\r\n             reg_lambda=3.3098341637038, scale_pos_weight=1, seed=1,\r\n             silent=None, subsample=0.7194797262656784, verbosity=1), 'preprocs': (), 'ex_preprocs': ()}<\/pre>\n<\/p>\n<h2>Further Reading<\/h2>\n<p>This section provides more resources on the topic if you are looking to go deeper.<\/p>\n<ul>\n<li><a href=\"https:\/\/dl.acm.org\/doi\/10.5555\/3042817.3042832\">Making a Science of Model Search: Hyperparameter Optimization in Hundreds of Dimensions for Vision Architectures<\/a>, 2013.<\/li>\n<li><a href=\"https:\/\/github.com\/hyperopt\/hyperopt\">Hyperopt GitHub Project<\/a>.<\/li>\n<li><a href=\"http:\/\/hyperopt.github.io\/hyperopt\/\">Hyperopt Homepage<\/a>.<\/li>\n<li><a href=\"https:\/\/github.com\/hyperopt\/hyperopt-sklearn\">Hyperopt-Sklearn GitHub Project<\/a>.<\/li>\n<li><a href=\"http:\/\/hyperopt.github.io\/hyperopt-sklearn\/\">Hyperopt-Sklearn Homepage<\/a>.<\/li>\n<li><a href=\"https:\/\/conference.scipy.org\/proceedings\/scipy2014\/pdfs\/komer.pdf\">Hyperopt-Sklearn: Automatic Hyperparameter Configuration for Scikit-Learn<\/a>, 2014.<\/li>\n<\/ul>\n<h2>Summary<\/h2>\n<p>In this tutorial, you discovered how to use HyperOpt for automatic machine learning with Scikit-Learn in Python.<\/p>\n<p>Specifically, you learned:<\/p>\n<ul>\n<li>Hyperopt-Sklearn is an open-source library for AutoML with scikit-learn data preparation and machine learning models.<\/li>\n<li>How to use Hyperopt-Sklearn to automatically discover top-performing models for classification tasks.<\/li>\n<li>How to use Hyperopt-Sklearn to automatically discover top-performing models for regression tasks.<\/li>\n<\/ul>\n<p><strong>Do you have any questions?<\/strong><br \/>\nAsk your questions in the comments below and I will do my best to answer.<\/p>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/machinelearningmastery.com\/hyperopt-for-automated-machine-learning-with-scikit-learn\/\">HyperOpt for Automated Machine Learning With Scikit-Learn<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/machinelearningmastery.com\/\">Machine Learning Mastery<\/a>.<\/p>\n<\/div>\n<p><a href=\"https:\/\/machinelearningmastery.com\/hyperopt-for-automated-machine-learning-with-scikit-learn\/\">Go to Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: Jason Brownlee Automated Machine Learning (AutoML) refers to techniques for automatically discovering well-performing models for predictive modeling tasks with very little user involvement. HyperOpt [&hellip;] <span class=\"read-more-link\"><a class=\"read-more\" href=\"https:\/\/www.aiproblog.com\/index.php\/2020\/09\/10\/hyperopt-for-automated-machine-learning-with-scikit-learn\/\">Read More<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":3857,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[24],"tags":[],"_links":{"self":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/3856"}],"collection":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=3856"}],"version-history":[{"count":0,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/3856\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media\/3857"}],"wp:attachment":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=3856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=3856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=3856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}