<?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 Ivan Panico on Medium]]></title>
        <description><![CDATA[Stories by Ivan Panico on Medium]]></description>
        <link>https://medium.com/@iv.panico?source=rss-bdb668fa3a56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*junlBBxGa3DEuvQy2rGMOQ.jpeg</url>
            <title>Stories by Ivan Panico on Medium</title>
            <link>https://medium.com/@iv.panico?source=rss-bdb668fa3a56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 05:13:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iv.panico/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[A Primer on Domain Adaptation]]></title>
            <link>https://medium.com/data-science/a-primer-on-domain-adaptation-cf6abf7087a3?source=rss-bdb668fa3a56------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf6abf7087a3</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[optimal-transport]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[domain-adaptation]]></category>
            <dc:creator><![CDATA[Ivan Panico]]></dc:creator>
            <pubDate>Mon, 03 Feb 2020 12:03:38 GMT</pubDate>
            <atom:updated>2020-02-10T09:39:13.100Z</atom:updated>
            <content:encoded><![CDATA[<h4>From theory to applications</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ndtb-JCA5-J17nFByHrIQ.jpeg" /></figure><blockquote>This article is a summary of a joint work by <a href="http://linkedin.com/in/pirminlemberger">Pirmin Lemberger</a> and <a href="https://www.linkedin.com/in/ivan-panico/">Ivan Panico</a> linked at the bottom of this post.</blockquote><blockquote>Disclaimer : As subscript support in unicode is still lacking on Medium we chose to use the following notation for subscript: p_S = p subscript S. For more readable notations we refer to the arXiv paper.</blockquote><h3>Domain adaptation — a rich and somewhat confusing history</h3><p>Machine learning (ML) aims at making statistical predictions for some phenomena given appropriate data in sufficient quantity. In <strong>supervised machine learning</strong> this data comes as a set of observations where some target quantity, or category, or label, is dependent on some measurable features. In the standard setting it is assumed that all observations are independent and sampled from one and the same distribution. The role of an ML algorithm is then to convert this training data into a function that accurately predicts the labels of unseen observations given their features.</p><blockquote>Classical theory of ML assumes that the new observations from the test set, for which we want to make predictions are drawn from the same population as those from the training set. This, however, is an ideal situation rarely met in practice.</blockquote><p><strong>The training set is then said to be biased with respect to the test set</strong>. Depending on the situation, this bias can either be known or unknown as we shall see. Domain adaptation (DA), which is the subject of this review, is a collection of methods that aims at compensating somehow for the statistical asymmetry between the train set and the test set. As a matter of fact, domain adaptation is everything but a new topic in ML. There are several reasons however that make it difficult for a newcomer to build a coherent overview of domain adaptation:</p><ul><li>Research papers on DA which treat the subject within some specific discipline use a specialized vocabulary and concepts that will not apply elsewhere.</li><li>Even for research on DA that is not specialized to some specific discipline <strong>there is no universal terminology agreement</strong> for referring to different types of domain adaptation. This often creates confusion.</li><li>DA is <strong>sometimes confused with transfer learning</strong> (TL) which is currently a hot topic in NLP and Deep Learning in general. While TL deals with transferring knowledge gained on one task to use it on another, DA, which is our focus, deals with one single task for which the training and test observations have different statistical properties.</li><li>The literature which deals with DA from a <strong>rigorous statistical learning perspective is sometimes heavy on mathematical technicalities</strong> which makes it a difficult read for the more hands-on data scientists.</li><li>On the other hand, <strong>more practical papers often give a too descriptive account</strong> of DA leaving much to be desired in terms of conceptual consistency.</li></ul><p>Therefore, rather than aiming at completeness, which leads to exhibiting a tedious catalog of methods, this pedagogical review aims at a coherent presentation of four important special cases: <strong><em>prior shift</em></strong>, <strong><em>covariate shift</em></strong>, <strong><em>concept shift</em></strong> and <strong><em>subspace mapping</em></strong> that we shall all define shortly. The goal of this introductory review is to help the reader to build an intuition about this vast domain. For a more in-depth discussion, you can refer to our <a href="https://arxiv.org/abs/2001.09994"><strong><em>technical article</em></strong></a>.</p><p>Let us now move on to the description of the four special cases of DA we consider. Henceforth, the source domain will refer to the population from which training observations are drawn while the target domain will refer to the population from which test observations are drawn. Objects related to the source domain will be “subscripted” _S while object related to the target domain will be “subscripted” _T.</p><h3>Four important cases of domain adaptation</h3><h4>Prior shift</h4><p>Prior shift refers to a situation in which the source distribution <em>p</em>_S used for picking the training observations is biased with respect to the target distribution <em>p</em>_T because the <strong>prior distribution of the labels</strong> <em>y</em>_<em>i</em> in both domains <strong>are different</strong>. We will focus here on classification where {ω_1, …, ω_<em>n</em>} is a finite set of labels. The most interesting and difficult case is one in which the prior distribution of the labels in the target is unknown while observations in the source are selected according to their label using some known strategy. Stratified sampling for instance selects an equal number of observations (<em>y</em>_<em>j </em>= ω<em>_k</em>, <strong>x_</strong><em>j</em>) in each class ω<em>_k</em>. The <strong>class conditional distributions</strong> <em>p</em>_S(<strong>x</strong>|<em>y</em>) = <em>p</em>_T(<strong>x</strong>|<em>y</em>) on the other hand are supposed to be <strong>the same</strong> in both domains. Figure 1 illustrates the situation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*X1-8tauQDJ4MxqCmuuuDrA.png" /><figcaption>Figure 1 : The prior shift corresponds to a situation in which the prior distributions p_S(y) and p_T(y) on labels are different in the source and in the target (middle). The class conditional distributions p_S(<strong>x</strong>|y) and p_T(<strong>x</strong>|y) on the other hand are supposed to be the same in both domains (left). The resulting joint distributions are shown on the right.</figcaption></figure><p>Without getting into technicalities, a nice method to deal with this kind of situation is based on the <strong>expectation maximization</strong> (EM) algorithm within the <strong>maximum likelihood</strong> framework of ML. Recall that this approach to ML assumes that the unknown distribution <em>p</em>_T(<strong>x</strong>,<em>y</em>) is parameterized by parameters <strong>θ</strong> and then looks for the parameters <strong>θ</strong>_ML that maximize the probability of observations in a given train set. The EM algorithm on the other hand is an iterative method that finds <strong>θ</strong>_ML in the particular case when the probability <em>p</em>_T results by marginalization over unobserved (or latent) variables. The idea then, when using EM to deal with the prior shift, is <strong>to treat the unobserved categorical variables</strong> <em>y</em>_<em>i</em> in the target observations <strong>as the latent variables</strong> and the list of unknown prior probabilities of the categories <em>p</em>_T(ω<em>_j</em>) as the parameters θ<em>_j</em>. Once <strong>EM</strong> has produced estimate for these prior probabilities, we can use them to compute posterior probabilities <em>p</em>_T(<em>y</em>=ω_<em>j</em>|<strong>x</strong>) in the target and thus make predictions. Intuitively, at each step of the procedure, the current predictor is used to update the prior probability of the target which, in turn, is used to correct the predictor by a factor depending on it. See Figure 2 for a visual illustration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*4FXE9QfskURTTDLDzLv7EA.png" /><figcaption>Figure 2: Intuitive vision of the EM algorithm applied to prior shift. Here (s) represent the index of the step of the procedure.</figcaption></figure><p>One nice thing with the method we describe is that it comes with a statistical test which can discriminate between situation in which you should or should not use it.</p><h4>Covariate shift</h4><p>Covariate shift, also sometimes termed “real concept drift”, describes a situation where the source distribution is biased because the <strong>training observations were sampled</strong> <strong>depending on their features</strong> <strong>in proportions</strong> <em>p</em>_S(<strong>x</strong>) <strong>that do not match the target distribution</strong> <em>p</em>_T(<strong>x</strong>). This should be contrasted with the prior shift we discussed earlier where a bias existed in the source distribution because observations were selected according to their label <em>y</em> in proportions <em>p</em>_S(<em>y</em>) that did not match <em>p</em>_T(<em>y</em>). Covariate shift assumes however that the dependence of the response <em>y</em> on the features <strong>x</strong>, as described by the conditional probability <em>p</em>_S(<em>y</em>|<strong>x</strong>) in the source, is the same as in the target population <em>p</em>_T(<em>y</em>|<strong>x</strong>). The situation is depicted in Figure 3 for the cases where <strong>x</strong> is either 1D or 2D.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*1zPYK3x834_1ebSahpL86Q.png" /><figcaption>Figure 3: The covariate shift corresponds to a situation where the source p_S(<strong>x</strong>) and target p_T(<strong>x</strong>) features distribution are different. Top: a 1D example. Bottom: a 2D example where the dashed curve symbolically represents the unchanged conditional probability p_S(y|<strong>x</strong>) = p_S(y|<strong>x</strong>).</figcaption></figure><p>We emphasize that the target feature distribution <em>p</em>_T(<strong>x</strong>) is assumed to be known in the presence of a covariate shift. This again is in contrast with the prior shift where the target label distribution <em>p</em>_T(<em>y</em>) was assumed to be unknown. In other words, covariate and prior shift are <strong><em>not</em></strong> symmetric cases that would result by simply swapping features <strong>x </strong>with labels <em>y</em>.</p><p>A covariate shift typically occurs when the cost or the difficulty of picking an observation with given features <strong>x</strong> strongly impacts the probability of selecting an observation (<strong>x</strong>,<em>y</em>) thus making it practically impossible to replicate the target feature distribution <em>p</em>_T(<strong>x</strong>) in the training set. A typical example could be a survey were some categories of individuals are more difficult to reach than others while the model should be able to classify all categories equally well.</p><p>In contrast with the prior shift, the method we present in our article is based on the <strong>PAC formulation of ML</strong>. Very roughly, PAC theory aims at using the data available in the source to find a predictor that will (probably and approximately) minimize the prediction risk in the target domain. As we know that the marginal <em>p</em>_S(<strong>x</strong>) is biased with respect to <em>p</em>_T(<strong>x</strong>), the strategy is to introduce a <strong>reweighting factor</strong> <em>w</em>(<strong>x</strong>) so that the corrected version <em>w</em>(<strong>x</strong>)<em> p</em>_S(<strong>x</strong>) of the source distribution is close, in a sense to be made precise, to the target <em>p</em>_T(<strong>x</strong>). Various discrepancy measures between distributions are available. We chose to dive into the so called <strong>MMD </strong>measure (<strong>Maximal Mean Discrepancy</strong>) both for its elegance and because it nicely illustrates kernel methods. Minimizing the MMD measure between <em>w</em>(<strong>x</strong>)<em> p</em>_S(<strong>x</strong>) and <em>p</em>_T(<strong>x</strong>) with respect to <em>w</em> is known as KMM (<strong>Kernel Mean Matching</strong>). It eventually leads to a simple quadratic optimization problem for finding <em>w</em>(<strong>x</strong>) for which many solvers are available.</p><p>In this case no statistical test is able to precisely indicate if the method will be helpful or not, but the main guidance is that <em>p</em>_S(<strong>x</strong>) and <em>p</em>_T(<strong>x</strong>) should not be too different.</p><h4>Concept shift</h4><p>Concept shift, or real concept shift as it is sometimes referred to, characterizes a situation in which the dependence of the target variable <em>y</em> on the features <strong>x</strong> is different in the source and in the target. In other words, the conditional distributions <em>p</em>_S(<em>y</em>|<strong>x</strong>) ≠ <em>p</em>_T(<em>y</em>|<strong>x</strong>) differ. The prior distributions over features are however supposed to coincide, <em>p</em>_S(<strong>x</strong>)=<em>p</em>_T(<strong>x</strong>). Figure 4 depicts the situation symbolically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*zkjBWfKJZwNoT8SX4S1d4Q.png" /><figcaption>Figure 4: In a concept shift the conditional distributions p_S(y|<strong>x</strong>) and pT(y|<strong>x</strong>), depicted as a dashed frontier, are different in the source and in the target while the prior distributions p_S(<strong>x</strong>) and p_T(<strong>x</strong>) are equal.</figcaption></figure><p>Just like for the prior shift we discussed earlier, we generally know nothing about the target labels here either. Therefore we cannot simply deal with a concept shift by inserting a reweighting factor <em>w </em>:= <em>p</em>_T(<em>y</em>|<strong>x</strong>) / <em>p</em>_S(<em>y</em>|<strong>x</strong>) in the definition of the true risk that we want to minimize.</p><p>Concept shift often takes the form of a <em>concept drift</em>, where the conditional probability <em>p</em>_T(<em>y</em>|<strong>x</strong>) depends explicitly on the time, in other words it occurs in <em>non-stationary</em> environments, for instance in aging systems whose dynamics changes progressively.</p><p>Algorithms that deal with drift are globally termed <em>adaptive algorithms</em> as they are designed to dynamically adapt to evolving settings. The core of the difficulty one faces in such dynamic environments is to be able to distinguish a random outlier of the response variable <em>y</em> from a genuine drift in the relationship which binds <strong>x</strong> and <em>y</em>. Here are a few basic strategies that can be used to deal with a concept shift:</p><ol><li>Periodically retrain the model with fresh data selected from a sliding time window.</li><li>Periodically update the model with fresh data while keeping part of the old data.</li><li>Weight training data inversely proportional to their age, if the algorithm allows to do so.</li><li>Use an iterative scheme were a new model learns to correct the most recent model (similar to a boosting).</li><li>Detect drift and select a new model accordingly.</li></ol><p>Organizing the wealth of existing methods that deal with the concept shift problem is a challenge by itself. One way to do this considers that any such adaptive system has four parts as figure shows:</p><ul><li>the <em>Learning Algorithm Module</em> that actually gets trained,</li><li>a <em>Memory Module</em> that defines which data is presented to the learning algorithm,</li><li>a <em>Loss Estimation Module</em> that tracks the performance of the learning algorithm,</li><li>the <em>Change Detection Module</em> that processes the information provided to it by the loss estimation module and updates the Learning Algorithm module when necessary.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*7yPnCvPG57h79XrJHr7plQ.png" /><figcaption>Figure 5: The four modules of an adaptive system.</figcaption></figure><p>An in-depth description of all options for these four modules is outside the scope of this introduction.</p><p>The number of applications that deal with concept drift is so large that whole studies have been devoted solely to categorize such tasks into a coherent framework. Three groups of applications, that have different goals and use different kind of data have been identified:</p><ul><li><strong>Monitoring and control applications</strong>: applications in this group aim at monitoring some automated production process in order to measure its quality or to detect possible outliers. Changes occur fast, typically within minutes or seconds.</li><li><strong>Information management applications</strong>: Applications in this group aim at organizing information. Typically, data comes in as a sequence of time stamped web documents that should be classified or characterized. Drift could happen gradually of suddenly over several days or weeks.</li><li><strong>Diagnostics applications</strong>. Tasks in this group aim at characterizing the health of populations of economies that happen over months or years and are gradual.</li></ul><p>Each of these applications in each category generally use different techniques to deal with the concept shift they face.</p><p>The mathematical framework, based on an extension of the PAC theory, we describe in the article address the case where the drift is continuous and slow enough.</p><h4>Subspace mapping</h4><p>Let’s not deviate from tradition and imagine that we want to train a classifier to recognize pictures of cats and dogs. Assume that our training set contains pictures shot under specific lighting conditions which include, say, exposure, color balance and a specific kind of background. How then should we optimize our classifier to <strong>classify images of these same pets shoot under very different lighting</strong> conditions? This is typically a problem of <em>subspace mapping</em>. More generally, subspace mapping deals with situations where the source and target examples are selected likewise but there is an unknown twist, or coordinate change <em>T</em>, between the features <strong>x</strong> describing these in the source and those describing them in the target <strong>x</strong>’=<em>T</em>(<strong>x</strong>). More precisely, in terms of the joint probability distributions we assume that for a subspace mapping:</p><ul><li><em>p</em>_T(<em>T</em>(<strong>x</strong>),<em>y</em>) = <em>p</em>_S(<strong>x</strong>,<em>y</em>) for some unknown distortion <em>T</em> between the descriptions in the source and target domains.</li></ul><p>By marginalizing and conditioning the above equality we respectively obtain:</p><ul><li><em>p</em>_T(<em>T</em>(<strong>x</strong>)) = <em>p</em>_S(<strong>x</strong>)</li><li><em>p</em>_T(<em>y</em>|<em>T</em>(<strong>x</strong>)) = <em>p</em>_S(<em>y</em>|<strong>x</strong>)</li></ul><p>In words: predictions <em>y</em> match for observations described by <strong>x</strong> in the source and by <em>T</em>(<strong>x</strong>) in the target. In particular, the first equation implies that <em>p</em>_T(<strong>x</strong>) ≠ <em>p</em>_S(<strong>x</strong>) and the second implies <em>p</em>_T(<em>y</em>|<strong>x</strong>) ≠ <em>p</em>_S(<em>y</em>|<strong>x</strong>) . Thus, another way to look at subspace mapping is as a composition of a covariate shift with a concept shift both characterized by a change of coordinates <em>T</em> on features. There is a wide range of methods that try to deal with a subspace mapping. We chose to focus on the optimal transport approach illustrated in Figure 6:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*Hm8yMQixd2xq4VT35DzT0Q.png" /><figcaption>Figure 6: optimal transport methods looks for a “low cost” non-linear transformation <em>T</em> from the source to the target.</figcaption></figure><p>Optimal transport (OT) is currently the most generic, elegant and powerful method for dealing with subspace mapping. In short, <strong>optimal transport looks for a mapping</strong> <em>T</em> <strong>that morphs the source joint distribution</strong> <em>p</em>_S <strong>into the target joint distribution</strong> <em>p</em>_T <strong>while using minimal effort</strong> to move mass from one to the other. Of course, we don’t know the labels <em>y</em>_<em>i</em> in the target (this is why we want to predict them) and thus we don’t have a direct access to <em>p</em>_T. We can however use a predictor <em>h</em>(<strong>x</strong>_<em>i</em>) as a proxy to these labels. A clear formulation of OT along these lines leads to a double minimizing procedure where the effort to move <em>p</em>_S towards <em>p</em>_T is minimized simultaneously on the transport mapping <em>T</em> and on the prediction function <em>h</em>. A simple minimization procedure alternates between optimizing <em>h</em> with fixed <em>T</em> and the optimizing <em>T </em>for fixed <em>h</em>. Optimizing for <em>h</em> can be done using any ML API while optimizing for <em>T</em> can leverage recent progress in OT optimizers.</p><p>Although the mathematics of OT has already been known for decades, it has long been ignored by data scientists, mainly due to its heavy computational cost. But things have changed lately due to various computational tricks that allow for fast optimization.</p><h4>Conclusion</h4><p>The need for systematic procedures for dealing with situations where a training data set does not faithfully reflect the real world is still understated by many practitioners despite its practical importance in machine learning. We analyze that this is mainly due to the myriad of methods available and to the lack of a unified and well accepted terminology for describing the different DA scenarios. For these reasons data scientists most often favor various tricks, like guessing an appropriate resampling ratio or generating fictitious data, to build appropriate training sets.</p><p>We hope this review can make some contribution in clarifying and spreading awareness of this important topic of data science to a wider audience of data scientists. If we succeeded, you probably want to know <a href="https://arxiv.org/abs/2001.09994">more</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf6abf7087a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/a-primer-on-domain-adaptation-cf6abf7087a3">A Primer on Domain Adaptation</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>