<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Long Vu on Medium]]></title>
        <description><![CDATA[Stories by Long Vu on Medium]]></description>
        <link>https://medium.com/@longvu2?source=rss-fc7a2e03a08f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xsOtXiI9bkcLmV1MPj1-DA.jpeg</url>
            <title>Stories by Long Vu on Medium</title>
            <link>https://medium.com/@longvu2?source=rss-fc7a2e03a08f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 09:50:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@longvu2/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Leveraging Tune for Large Scale Experiments]]></title>
            <link>https://longvu2.medium.com/leveraging-tune-for-a-large-number-of-experiments-787daffde9ed?source=rss-fc7a2e03a08f------2</link>
            <guid isPermaLink="false">https://medium.com/p/787daffde9ed</guid>
            <dc:creator><![CDATA[Long Vu]]></dc:creator>
            <pubDate>Mon, 04 Oct 2021 02:33:44 GMT</pubDate>
            <atom:updated>2021-10-12T22:00:56.307Z</atom:updated>
            <content:encoded><![CDATA[<p>Ray is an open source platform that has been used extensively in both research and industry to scale Python workload [1]. Tune (or Ray Tune) is a library that executes experiments and performs hyperparameter optimization at large scale [2]. Tune provides a rich set of schedulers, search algorithms, HPO algorithms so that users can search the best hyperparameter settings for the input ML/AI algorithms.</p><p>This post is not about hyperparameter tuning with Tune, since it is a well discussed topic and you can find many resources elsewhere. Instead, we will discuss how to leverage Ray Tune to run a large set of Python workload (or tasks) in parallel. For example, we have <strong>N</strong> input dat sets and <strong>M</strong> input ML algorithms, for each data set, we want to run all ML algorithms, so we end up with <strong>N x M </strong>experiments. In many cases, we can end up with tens of thousands of data sets and thousands of ML algorithms (or pipelines), the number of experiments will be in the order of hundreds thousands or millions.</p><p>Let’s start with common objectives of system that runs a large scale experiments. First, we want experiments to be run in parallel, especially on a cluster of nodes. Second, we want to save the output of each experiment to a separate file (Ideally, we want a centralized data base server for storing experiment output, but this will be discussed in another future post). Third, we want to terminate some long-running experiment that runs longer than a predefined timeout period. Finally, since the system may crash at anytime during its execution, we want to specify explicitly which new experiments need to be executed. In the below sections, we will discuss how to use Ray Tune and multi-threaded Python to achieve these objectives.</p><p>To setup a ray cluster, please refer to Ray official documentation, it is quite straight forward [3].</p><p>You can start Tune by calling tune.run function as simple as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4847fc81174b9d3063272b2d513f46ba/href">https://medium.com/media/4847fc81174b9d3063272b2d513f46ba/href</a></iframe><p>Here, Tune will start a new log folder and names it “tune_sample” under ray_results default folder, for this new run of many experiments. By default, num_sample of tune.run is 1, so only one trial is executed. In this example, we have three input parameters for the trial_evaluator method: input_arg1, input_arg2, and timeout. If we stop here, our code only executes one trial, which takes a random number for input_arg1 from a list of [1, 2, 3], and takes a random number for input_arg2 in the range of 0 and 10, and timeout is fixed as 300 seconds. However, we have four objectives above. So, we need to extend the code to achieve our objectives. Please be patient since we will need to go over several important steps before you can get the big picture clearly.</p><p>First, we will define a worker function that accepts the ‘config’ input parameter as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5087fefacc6370a2b6cea16c6879554c/href">https://medium.com/media/5087fefacc6370a2b6cea16c6879554c/href</a></iframe><p>This worker function is the one that actually performs one task or one experiment. For example, the worker can receive as input the config that includes input_arg1 and input_arg2, and use these two parameters for the experiment. Note that timeout is not a required input of the worker, although it might still be included, but it is not used by the worker. We will come back to this point shortly below. The worker will store the outcome of the experiment in a variable named “outcomes”, or any name that you prefer. Then, the worker will call tune.report function so that Tune will store the output of the experiment the log file named ‘result.json’. The file result.json actually is a dictionary that contains the key experiement_output as it is specified in tune.report function. Since experiemnt_output is equal to the outcomes variable, the experiment output is saved to result.json file by Tune. Now, please note that one worker can be complete very quickly while another worker might take a much longer time to complete since they might have different config in the input. So, we need to terminate the slow worker that runs longer than our desired timeout seconds. We will do that as follows.</p><p>We define the trial_evaluator method, which is called by tune.run above. The trial_evaluator method accepts the config parameter as input, it then will create a new thread, assign the target of the thread to the worker method defined above, the input config parameter is given to the worker method directly. Note that, config is a dictionary that has a key named timeout. Technically, the timeout variable is not required by the worker thread so we can remove the key timeout from the input config before giving the modified config to the worker thread. After creating the thread for the worker, trial_evaluator will start the thread so that the code inside the worker function can run. Then, trial_evaluator waits for timeout seconds (line 12). After that, it checks if the worker thread is still alive, if so, it will terminate the worker thread.</p><p>This is a distributed environment where processes run in different machines or cores. How can the worker thread be terminated ? The key is that we can call tune.report in line 14 below to notify Tune that there is a new event that needs Tune’s attention for this particular trial (i.e., the trial is being executed, or the current running version of trial_evaluator method).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a380d81f49e949f191efbcf4ae683c60/href">https://medium.com/media/a380d81f49e949f191efbcf4ae683c60/href</a></iframe><p>What happens when tune.report is called on line 14 ? We will come back to this point shortly below. But, first look at the final tune.run call below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/087c91edfcd66005d108346a62a15e58/href">https://medium.com/media/087c91edfcd66005d108346a62a15e58/href</a></iframe><p>In this above code of tune.run, we pass an instance of the CustomStopper class, which is responsible to handling the call to tune.report(terminate=1) on line 14 of the trial_evaluator method. When tune.report function is called, the __call__ method of the CustomStopper class is called. We define the CustomStopper class below. In this code segment, we check if ‘terminate’ exist in the dictionary ‘result’, which is created by Tune for each trial that calls tune.report. So, if ‘terminate’ exists, we return True, which notifies Tune that we want to terminate the current trial. In this case, Tune will terminate the current trial, and the worker thread is terminated, since it is running in the same process as the current trial.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d30ccc9a2d763fd8dba632d55f5cd38a/href">https://medium.com/media/d30ccc9a2d763fd8dba632d55f5cd38a/href</a></iframe><p>The final point is that how to specify the actual experiments that we want Tune to run and in a certain order, instead of letting Tune pick the experiments at random. For this, we use the BasicVariantScheduler, the default Tune’s scheduler that uses the scheduling FIFO algorithm. The BasicVariantScheduler accepts point_to_evalute as an input parameter, which is a list of points that we want to be executed, in a certain order determined by the list index. In order to specify the order of experiments for the BasicVariantScheduler, we can simply create an ordered list of experiments and give it to BasicVariantScheduler through the point_to_evaluate input parameter. That also means we do not need to specify any search space for input_arg1 and input_arg2 in the config input parameter of tune.run method, so they are both None in the above code.</p><p>The use point_to_evalute variable of BasicVariantScheduler also allows us specify any list of experiments. That means, if the current run crashes, we can check and create a list of only new experiments that were not done by previous run, and ask Tune to run on the new ones.</p><p>You can refer to the full version of the code at [4].</p><p>In the below screen cut, the console has output during the execution of the the main.py script in [4]. As you can see, there are four processes running in parallel since we have four trials. The ‘outcomes’ variable has different values for different processes, the worker sleeps for a random period (i.e., we want to test if a process is terminated when it does not complete by a specified timeout seconds).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*P5bnoryodw5CRf7PR6AFZg.png" /></figure><p>This below screen shows that there are four trials, and one of them completes with the experiment_output key that we created and specified in tune.report function call.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gGNLMKJLWXek6Ak0Dc5qOQ.png" /></figure><p>This is the final console output. All of four trials complete but one of them is terminated by us forcing it to terminate due to time out violation. So, that trial does not have the experiment_output, meanwhile other trials have values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xBM0zQyx4OwDmc2BsaWfXg.png" /></figure><h3>Conclusion</h3><p>In this post, we have presented a method that combines Tune and threaded Python programming to run a large set of parallel experiments. This method achieves four objectives we presented in the beginning of the post.</p><h3>Reference</h3><p>[1] <a href="https://www.ray.io/">https://www.ray.io/</a></p><p>[2] <a href="https://docs.ray.io/en/latest/tune/index.html">https://docs.ray.io/en/latest/tune/index.html</a></p><p>[3] <a href="https://docs.ray.io/en/latest/cluster/index.html">https://docs.ray.io/en/latest/cluster/index.html</a></p><p>[4] <a href="https://github.com/lhvu2/tune_large_experiments">https://github.com/lhvu2/tune_large_experiments</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=787daffde9ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Benchmarking Outlier Detection Algorithms]]></title>
            <link>https://longvu2.medium.com/benchmarking-outlier-detection-algorithms-5fed922a65cf?source=rss-fc7a2e03a08f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fed922a65cf</guid>
            <dc:creator><![CDATA[Long Vu]]></dc:creator>
            <pubDate>Thu, 22 Apr 2021 02:59:26 GMT</pubDate>
            <atom:updated>2021-04-23T15:25:51.717Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many different outlier detection algorithms that have been developed and published over the years. In this post, we will benchmark these algorithms.</p><h3>Methodology</h3><p>In this section, we will discuss the outlier detection algorithms in our benchmark, the oracle algorithm, data sets, and the metric for evaluation.</p><h4><strong>Algorithms</strong></h4><p>We will use the <strong>Python toolkit</strong> for <strong>detecting outlying objects</strong> in multivariate data (PYOD) [1]. PYOD is an open source Python-based library that includes many outlier detection algorithms. In our benchmarking study, we will focus on the following 19 algorithms. As you can see, these include algorithms from last century to 2020. And they include different types, from Linear Model to Outlier Ensemble, from Probabilistic to Neural Networks, and so on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05d52df25de203df98c72eb482aeeb67/href">https://medium.com/media/05d52df25de203df98c72eb482aeeb67/href</a></iframe><h4><strong>The Oracle algorithm</strong></h4><p>In order to evaluate and compare these above algorithms in fair manner, we need a baseline algorithm. So, we define the Oracle algorithm, which always gives the best of 19 algorithm for an input data set. That is, the Oracle ‘knows’ which one is the best for a given data set, so the name ‘Oracle’. In our study, we will compare the performance of 19 algorithms against the Oracle on the benchmark data sets below. Obviously, since the Oracle is always the best, 19 algorithms will have a lower performance compared to the Oracle. However, the less inferior an algorithm than the Oracle, the better it is.</p><h4>Data sets</h4><p>We will use the Outlier Detection DataSets (ODDS) [2] to benchmark the 19 algorithms against the Oracle. ODDS has been widely used in many scientific papers. These 31 data sets are listed in the below table, you can also find the basic information about number of rows (i.e., data points), number of columns (i.e., dimensions), number of outliers, and percentage of outliers. These give you the overall diversity of the data sets in the study.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ebc05f86ec46e55df1ad432a735e3d7/href">https://medium.com/media/0ebc05f86ec46e55df1ad432a735e3d7/href</a></iframe><p>For each benchmarking data set above, we have ground truth labels. That is, an item has label 0 if it is a normal item while the item has label 1 if it is an outlier. As shown in the <strong>%outliers</strong> column, these data sets are highly skew and most of them have few outliers. This skewness is important since it decides how we select the benchmarking evaluation metric below.</p><h4>Evaluation Metric</h4><p>Given the skewness of the benchmarking data sets and the labels of 0 and 1, we use AUC ROC [3] as the metric to measure the performance of these 19 algorithms on the 31 data sets. Note that, AUC ROC has been widely used for measuring ML algorithm performance in the context of classification. Since we have normal and anomalous data points (with labels of 0 and 1, respectively), the outlier detection algorithms work like a classifier. Moreover, AUC ROC works well with highly imbalanced data sets, which is suitable for our ODDS. That explains why AUC ROC is used in this study.</p><p>We define an experiment run as a pair of one algorithm <em>A</em> and a data set <em>D</em>. So, we have a total of 19 * 31 = 589 experiment runs. For each experiment run, we call the fit() and predict() methods of the algorithm <em>A</em>, then given the output of predict(), we calculate AUC-ROC score using the ground truth labels of <em>D</em>.</p><p>For each data set <em>D</em>, the highest of 19 AUC-ROC scores indicates the Oracle’s score <strong><em>s</em></strong>. Then, for each algorithm <em>A </em>(out of 19 algorithms), let <strong><em>r</em></strong> be A’s AUC-ROC score on <em>D</em>. We calculate the regret AUC-ROC score for A as: <strong><em>s</em></strong><em> - </em><strong><em>r</em></strong><em>. </em>So, the regret AUC-ROC of an algorithm on a data set is a non-negative number.</p><p>For 31 data sets, each algorithm <em>A</em> has 31 regret AUC-ROC scores. We then rank the 19 algorithms based on the median regret AUC-ROC score out of these 31 AUC-ROC scores. The smaller the median regret ROC, the better the algorithm is.</p><h3>Results</h3><p>As shown in the below table, Minimum Covariance Determinant (MCD) algorithm is the best outlier detection in our benchmarking study. Its median regret AUC-ROC is 0.03. Meanwhile, MO_GAAL, a recent algorithm developed in 2020, is the worst with a median regret AUC-ROC of 0.39. Isolation Forest, a very popular algorithm due to its robustness, ranks second in our benchmarking study with a median regret AUC-ROC of 0.06.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79172d2dd87c73788d919074930473e4/href">https://medium.com/media/79172d2dd87c73788d919074930473e4/href</a></iframe><h3>Reference</h3><p>[1]. PYOD, <a href="https://pyod.readthedocs.io/en/latest/">https://pyod.readthedocs.io/en/latest/</a></p><p>[2]. ODDS, <a href="http://odds.cs.stonybrook.edu/">http://odds.cs.stonybrook.edu/</a></p><p>[3]. Understanding AUC-ROC Curve, <a href="https://towardsdatascience.com/understanding-auc-roc-curve-68b2303cc9c5">https://towardsdatascience.com/understanding-auc-roc-curve-68b2303cc9c5</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fed922a65cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Windowless Transformation for Multivariate Time Series]]></title>
            <link>https://longvu2.medium.com/windowless-transformation-for-multivariate-time-series-f0d1593b574c?source=rss-fc7a2e03a08f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0d1593b574c</guid>
            <dc:creator><![CDATA[Long Vu]]></dc:creator>
            <pubDate>Wed, 04 Nov 2020 19:43:25 GMT</pubDate>
            <atom:updated>2020-11-11T01:32:03.906Z</atom:updated>
            <content:encoded><![CDATA[<p>Time series data are taken over time and may have the temporal dependency and an internal structure (such as autocorrelation, stationarity, and seasonality) that should be accounted for. Time series analysis has been an important scientific topic in both academia and industry, and historically, statistical methods such as ARIMA [1], Holt Winters [2], BAT [3][4] are the go-to modeling tools for time series analysis. Recently, machine learning and deep learning models have achieved improved performance in time series modeling. While deep learning techniques may not require a feature engineering step prior to applying the final estimator in the pipeline, machine learning estimators such as Random Forest, XGBoost, Linear Regression, SVM may benefit greatly from feature engineering.</p><p>In this post, we focus on a method to transform time series raw data into features that are ready to be consumed by machine learning estimators.</p><h3>Introduction</h3><p>Existing techniques usually segment time series data into windows, apply different computations (or transformations) on each window, and merge the transformed output of all windows to generate final results. There are different types of windows such as sliding window, tumbling window, in which sliding window is more popular.</p><p>Deciding the right window size is a critical factor. There have been different techniques that tried to learn the window size from data values or from the temporal information of the time series. However, there is no universal method that worked for all types of time series, especially for multivariate time series that include individual time series with distinct internal structures.</p><p>In this post, we present a different way to do feature engineering for time series as follows. For each data point in the input (univariate) time series, define a max look back window <strong>m</strong>. A good value of <strong>m</strong> would be<strong> </strong>one third of the length of the time series. Then, create a list <strong>L</strong> of look back windows of sizes <em>base</em>¹, <em>base</em>², <em>base</em>³, <em>base</em>⁴, …., <em>base</em>ⁿ , so that <em>base</em>ⁿ ≤ <strong>m</strong>, in which <em>base</em> can be an integer such as 2, 3, 4, … Then, for each window size in <strong>L</strong>, compute the rolling values such as <em>mean</em>, <em>std</em>, <em>max</em>, <em>min</em>, etc. These are standard Python functions that can be used in a straightforward fashion. Below, we introduce a different function that uses Discrete Cosine Transform for each window in <strong>L</strong>, and then keep only the most significant coefficients as data features. Doing this, we ensure that the most significant information of each window is retained in the final feature values.</p><p>The same above procedure can be applied for all individual time series in a multivariate time series to transform multivariate time series into features for ML estimators. The reason the title of this post is “Windowless Transformation” is because the user does not need to manually specify the look back window size for each individual time series, instead multiple look back windows can be applied as above to compute the transformed features.</p><p>Figure 1 shows the overview architecture of our presented solution. The input multivariate time series goes through a chain of nested transformers: Time series transformer, column transformer, and rolling transformer. These transformers transform input multivariate time series and concatenate the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*sIDYaFxwU78KUH773EkqBA.png" /></figure><p>In the following sections, we will discuss these above transformers in detail.</p><h3>Time Series Transformer</h3><p>As the outermost layer of the nested architecture, this transformer is responsible for two main tasks:</p><ul><li>Loop through all columns or all time series in the multivariate time series, and for each time series, create and execute a column transformer, as shown in lines 3 and 4 below.</li><li>Aggregate the output of column transformers in the correct format and return to the caller of this transformer, as shown in lines 6 and 8 below.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61d957a55c3d4f859fd6cd4c4c38f354/href">https://medium.com/media/61d957a55c3d4f859fd6cd4c4c38f354/href</a></iframe><h3>Column Transformer</h3><p>This transformer creates multiple look back windows from each data point in the input univariate time series. As discussed above, this transformer creates a list <strong>L</strong> of look back windows of sizes <em>base</em>¹, <em>base</em>², <em>base</em>³, <em>base</em>⁴, …., <em>base</em>ⁿ , so that <em>base</em>ⁿ ≤ <strong>m</strong>, in which <em>base</em> can be an integer such as 2, 3, 4, … as shown in line 5 below. If there is a specified max look back value, then that value is used as <strong>m</strong>. Otherwise, as a rule of thump, as mentioned above, <strong>m</strong> should be one third of the length of the time series (line 4 below).</p><p>Also, this transformer includes a sklearn FeatureUnion [5] object that concatenates results of all rolling transformer objects (line 11 below). Using Feature Union, we allow all rolling transformers (each handles a different look back window) to run in parallel and the final result is obtained by concatenation of all output of these rolling transformers. This allows a fast and clean implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ea1e5d972dfb04ec4391e0d206e9620/href">https://medium.com/media/0ea1e5d972dfb04ec4391e0d206e9620/href</a></iframe><p>As shown in line 12 above, the column transformer actually calls the ‘transform’ method of its Feature Union object, which calls all of its rolling transformers. Each rolling transformer is responsible for transforming one single look back window length as we discuss next.</p><h3>Rolling Transformer</h3><p>This transformer first converts the input 2D numpy array X into a Pandas data frame (line 2). Then, it uses the rolling and apply function of the data frame that calls a function named ‘compute’ (line 3). More about ‘compute’ function will follow below. After the ‘compute’ function outputs the results, the column transformer will need to prepend the output data frame with np.nan to make sure that the shape is correct (lines 6–8). This is important since the outer Feature Union will only concatenate (by column) the transformed matrices that have the same number of rows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be5c509881cb1b5bd9ca0a369521cbc8/href">https://medium.com/media/be5c509881cb1b5bd9ca0a369521cbc8/href</a></iframe><p>The ‘compute’ method is a helper method (or a work around trick) that is used to allow data frame rolling function to output more than one scalar.</p><p>At its core, this ‘column’ function uses the Discrete Cosine Transform [6] to calculate the coefficients of the input data as shown below. DCT-2 (i.e., type 2) is used here since it is the most common variant of discrete cosine transform. Note that, the output of DCT-2 has the same length as the input of DCT-2 (line 3). However, we do not want to keep all coefficients in the output, instead, only the largest coefficients (in absolute value) are kept so that we can reduce memory usage while retaining most of useful information of the input data (lines 4–8). If the input ‘data’ is too short, zeros will be padded at the end (line 6). The output is in the format of Pandas Series, which allows the outer FeatureUnion to concatenate these series and create the correct output format.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1c0ec04d03bfc62fc00aa6ee02fca45/href">https://medium.com/media/f1c0ec04d03bfc62fc00aa6ee02fca45/href</a></iframe><h3>Source code</h3><p>Source code of our presented solution are available at: <a href="https://github.com/lhvu2/ts_windowless_transformer">https://github.com/lhvu2/ts_windowless_transformer</a></p><h3>References</h3><ol><li>PJ Brockwell, RA Davis, MV Calder, “Introduction to time series and forecasting”, 2002, Springer.</li><li>Prajakta S. Kalekar, “Time series Forecasting using Holt-Winters Exponential Smoothing”, 2004</li><li>De Livera, Alysha M. “Automatic forecasting with a modified exponential smoothing state space framework.” Monash Econometrics and Business Statistics Working Papers 10, no. 10 (2010).</li><li>De Livera, Alysha M., Rob J. Hyndman, and Ralph D. Snyder. “Forecasting time series with complex seasonal patterns using exponential smoothing.” Journal of the American Statistical Association 106, no. 496 (2011): 1513–1527.</li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.FeatureUnion.html">https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.FeatureUnion.html</a></li><li><a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.dct.html">https://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.dct.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0d1593b574c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Train an AutoML Joint Optimizer]]></title>
            <link>https://longvu2.medium.com/how-to-train-an-automl-joint-optimizer-dbe0e71cfd72?source=rss-fc7a2e03a08f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbe0e71cfd72</guid>
            <dc:creator><![CDATA[Long Vu]]></dc:creator>
            <pubDate>Tue, 20 Oct 2020 21:04:31 GMT</pubDate>
            <atom:updated>2020-11-04T20:59:30.731Z</atom:updated>
            <content:encoded><![CDATA[<p>You decide that the sklearn Random Forest classifier will be used as the classification model for your data set. However, you don’t know what the values of n_estimators (i.e., number of trees) and max_depth (i.e., tree height) should be set so that Random Forest works best with your data set. In AutoML literature, n_estimators and max_depth are hyperparameters that can be tuned by a joint optimizer and the tuning process is called ‘Hyperparameter Optimization’ or HPO.</p><p>Methods for doing HPO on machine learning models can be classified into two types. Evaluation-based joint optimizers<em> </em>go through each step such as construction, training, and evaluation of each candidate model in their search spaces to find the best model for the input data set [1]. Meanwhile, metalearning-based joint optimizers<em> </em>leverage<em> </em>experience obtained while finding optimal models for past data sets to find best models for similar data sets in the future [2][3]. Here, we focus on the evaluation-based joint optimizers; specifically, we discuss how to develop and train an evaluation-based joint optimizer (or joint optimizer for the rest of this post).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ck4dEQdBJK7nJIYMyYsmTQ.jpeg" /></figure><h3>System Overview</h3><p>Figure 1 shows how components in an AutoML system interact during the training of the joint optimizer. The hyperparameter search space (or hyperparameter space) includes hyperparameters of the input pretrained estimator, which is Random Forest classifier in our context. For example, Random Forest classifier has n_estimators, max_depth, max_features, etc. in its hyperparameter space [4]. The joint optimizer takes the hyperpameter space and creates suggested configuration(s). A configuration includes all hyperparamters in the search space in which each hyperparamter is set with a specific value by the joint optimizer. Given the suggested configuration(s) from the joint optimizer, the evaluator trains and scores the input pretrained estimator with the suggested configuration(s) on the input data set (note that a train/test split scheme might be applied at the evaluator for a fair performance evaluation on suggested configuration(s)). Then, the evaluator returns evaluated configuration(s) to the joint optimizer. The evaluated configuration(s) are the suggested configuration(s) with evaluation scores. These step 2 and step 3 in Figure 1 are repeated until the joint optimizer satisfies some pre-specified condition and the training ends. The output of the system can include the trained joint optimizer and the trained estimator. An example of a joint optimizer using sklearn KNN regressor is available at [7]. In the following sections, we discuss in details each of the step in Figure 1.</p><h3>Hyperparameter Search Space</h3><p>The hyperparameter search space is a dictionary in Python. As discussed in the sample Python code in [5][6], the hyperparameter search space is defined as a dictionary data structure in the constructor to the optimizer. For example, if we are optimizing the hyperparameters for the scikit-learn Random Forest classifier, then we could use the following configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f769cba4f6a7d9af86b425b02a42da7/href">https://medium.com/media/0f769cba4f6a7d9af86b425b02a42da7/href</a></iframe><p>Figure 2 shows an example of eight suggested configurations for the above api_config hyperparameter search space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*MqO3A6YC6w5XPbsBb0Cu6Q.jpeg" /></figure><h3>Joint Optimizer</h3><p>The joint optimizer is a search algorithm that recommends the best configuration to train the input pretrained estimator on the input data set. There are different methods in literature for searching best configurations for the input pretrained estimator and input data set. In this post, we present a simple example of a joint optimizer that includes an internal regression model to predict the performance score of the pretrained estimator on the input data set; and thus selects the best (lowest score) configuration. The internal regression model can be any regressor such as Random Forest, Linear Regression, etc. For example, the internal regression model can be the KNN regressor that learns from evaluated configurations and predicts the scores for new configurations [7]. In this case, the core component of the joint optimizer can be a KNN regressor, as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1ec2ab66690ea6a862e999a15766c0c/href">https://medium.com/media/e1ec2ab66690ea6a862e999a15766c0c/href</a></iframe><p>Here, joint_op is a sklearn Pipeline object that includes a StandardScalar as the transformer and the KNeighborsRegressor as the final estimator. The training set of this joint_op is a tabular data set that includes all evaluated configurations in Figure 2 with evaluation scores. Note that each configuration has the format of the api_config above where each key of the dictionary has a specific value. The joint optimizer maintains an internal cache of evaluated configurations that have been evaluated by the evaluator so far. So, the more interactions the joint optimizer has with the evaluator, the set of evaluated configurations is larger, or the training set of the joint optimizer is larger, and the joint optimizer potentially becomes better.</p><p>Once the joint_op is trained with all evaluated configurations, we need to use the joint_op to compute the next suggested configuration(s). Usually, a list of candidates is created, and then the final suggested configuration(s) are computed from these candidates. There are different methods to create the list of candidates. For example, some methods find the candidates around the best evaluated configuration(s) in the joint optimizer internal cache and add some variance around these configurations to create the final suggested configurations [8]. Here, we present a very simple method by creating a list of random configurations as candidates, as follows:</p><p>candidates = rs.suggest_dict([], [], api_config, n_suggestions=500, random=np.random)</p><p>Given a list of 500 random configurations, we call joint_op.predict(X=candidates) to obtain predicted scores for all 500 candidates. Then, we can select a subset of candidates as the suggested configurations and send them to the evaluator. Normally, the lower the predicted score, the better the candidate configuration is. Another method to create the final suggested configurations is similar to exploit/explore idea in Reinforcement Learning. That is, the final suggested configurations combine some configurations with lowest scores from the above 500 configurations, and other configurations taken at random from the above 500 configurations.</p><h3>Evaluator</h3><p>The interaction between the evaluator and the joint optimizer is similar to the interaction between the environment and the agent in Reinforcement Learning. That is, the evaluator receives the suggested configurations from the joint optimizer, trains the input pretrained estimator, scores the trained estimator on the input data set, and sends the suggested configurations with scores (i.e., the evaluated configurations) back to the joint optimizer.</p><p>Bayes Opt Benchmark is a very good open source Python package that works as an evaluator [5][6].</p><h3>Initialization</h3><p>Since the internal regression model needs a certain amount of training data (or evaluated configurations) to work well. In the first several interactions between the joint optimizer and evaluator, the joint optimizer can recommend suggestion(s) taken at random from the hyperparameter search space. Once it has sufficient evaluated configurations, the joint optimizer can train and use the internal regression model to create suggested configuration(s).</p><h3>Implementation</h3><p>We provide a sample joint optimizer that uses sklearn KNN regressor to recommend next suggestions for the evaluator, for any pair of (data set, input pretrained estimator) here [7]. In this implementation, the suggest() function sends suggested configurations to the evaluator and the observe() function receives the evaluated configurations from the evaluator. Once the joint optimizer receives the evaluated configurations, it builds a new KNN regressor and prepares the next suggestions.</p><h3>References</h3><p>[1]. <a href="https://papers.nips.cc/paper/5872-efficient-and-robust-automated-machine-learning">Feurer, M., Klein, A., Eggensperger, K., Springenberg, J., Blum, M. and Hutter, F., 2015. “Efficient and robust automated machine learning.”, NeurIPS, 2015</a></p><p>[2]. <a href="https://papers.nips.cc/paper/7595-probabilistic-matrix-factorization-for-automated-machine-learning.pdf">Fusi, N., Sheth, R. and Elibol, M., “Probabilistic matrix factorization for automated machine learning”. NeurIPS, 2018.</a></p><p>[3]. <a href="https://arxiv.org/abs/1810.03548">Vanschoren, J., “Meta-learning: A survey.” arXiv preprint arXiv:1810.03548, 2018.</a></p><p>[4]. <a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html">https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html</a></p><p>[5]. <a href="https://github.com/rdturnermtl/bbo_challenge_starter_kit/">https://github.com/rdturnermtl/bbo_challenge_starter_kit/</a></p><p>[6]. <a href="https://bayesmark.readthedocs.io/en/latest/index.html">https://bayesmark.readthedocs.io/en/latest/index.html</a></p><p>[7]. <a href="https://github.com/lhvu2/automl_joint_optimizer">https://github.com/lhvu2/automl_joint_optimizer</a></p><p>[8]. <a href="https://github.com/uber-research/TuRBO">https://github.com/uber-research/TuRBO</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbe0e71cfd72" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>