领域自适应:重加权何时有效?
Domain adaptation
拟合加权常数分类器,构造无标签输入完全相同却需要不同答案的两个目标世界。
domain-adaptation部署总体改变,受限模型的最佳选择也会变
训练时某输入类别常见,部署时却罕见。源分数衡量旧混合下的表现,不自动代表新总体。领域自适应在不同源域、目标域之间处理相关预测任务,使用协议允许的目标信息。
无监督领域自适应有目标输入,但没有目标训练标签;监督或半监督变体有部分目标标签。Pan 与 Yang 综述第2、4节区分迁移场景和域差别。术语用法不尽相同,应明确哪些源/目标数据可用。先读重要性采样与泛化。
重加权需要稳定的条件机制
一个重要特例是协变量漂移:
输入分布改变,固定输入处的标签分布不变。目标支持由源覆盖、损失可积时,任意固定预测器 h 满足:
把源期望按 x、y展开,概率比约掉 p_S(x),再用条件相等把 p_S(y|x)换成 p_T(y|x),就得到目标联合期望。连续输入改为密度和积分,使用对应支持条件。Sugiyama、Krauledat 与 Müller 第2.1–2.2节在已知密度比条件下分析协变量漂移与重要性加权学习。
由此得到加权经验风险最小化:
固定预测器的总体恒等式,不保证最小训练损失是无偏测试估计。同一数据上学习会产生选择影响,估计概率比还会增加误差;验证必须对应目标风险。
两类别例子中,胜者改变了
源输入概率(9/10,1/10),目标(1/10,9/10),两个域的正标签概率都为 η=(1/10,9/10)。常数零分类器源错误9/50、目标错误41/50;常数一相反,所以最佳常数模型改变。
输入权重为(1/9,9)。源计数[[81,9],[1,9]],列为负/正,恰好再现构造的源联合概率。给这100条观察重加权,正质量82、总质量100,因此加权常数拟合选类别1。
更丰富的预测器 h(x)=x,在两个域错误都为1/10。纯协变量漂移下,条件相同、分类损失相同时,逐点 Bayes 分类器不变;重加权仍可能影响受限模型族、正则化、有限数据或评估。本常数例子没有宣称每个最优分类器都会变。
拟合可用信息与目标真值分开
完整 Python3.12 程序用源分组计数和目标输入比例拟合常数标签,不把目标标签传给拟合函数。另一个审计函数计算两个假想目标世界的风险,让假设可精确检查。
from fractions import Fraction as F
def probability(values, positive=False):
values=list(values)
if not 1<=len(values)<=8 or any(type(v) not in (int,F) or not 0<=v<=1 or (positive and v==0) for v in values) or sum(values,F(0))!=1:
raise ValueError('one to eight normalized rational probabilities required')
return list(map(F,values))
def audit(source_x, target_x, eta_source, candidates, eta_target=None):
ps=probability(source_x,True);pt=probability(target_x);n=len(ps)
es=list(eta_source);et=list(es if eta_target is None else eta_target);candidates=[list(h) for h in candidates]
if len(pt)!=n or len(es)!=n or len(et)!=n or any(type(v) not in (int,F) or not 0<=v<=1 for v in es+et):
raise ValueError('matching rational conditional positive-label probabilities required')
if not 1<=len(candidates)<=8 or any(len(h)!=n or any(type(v) is not int or v not in (0,1) for v in h) for h in candidates):
raise ValueError('bounded binary candidate predictions required')
ratios=[t/s for s,t in zip(ps,pt)];rows=[]
for h in candidates:
source_errors=[F(v) if pred==0 else 1-F(v) for v,pred in zip(es,h)]
target_errors=[F(v) if pred==0 else 1-F(v) for v,pred in zip(et,h)]
source=sum(p*e for p,e in zip(ps,source_errors))
weighted=sum(p*w*e for p,w,e in zip(ps,ratios,source_errors))
target=sum(p*e for p,e in zip(pt,target_errors));rows.append((source,weighted,target))
return ratios,rows
def fit_constant(counts, target_x):
counts=[list(row) for row in counts]
if not 1<=len(counts)<=8 or any(len(row)!=2 or any(type(v) is not int or not 0<=v<=100000 for v in row) or sum(row)==0 for row in counts):
raise ValueError('nonempty negative/positive count pairs required for each source category')
total=sum(map(sum,counts));ps=[F(sum(row),total) for row in counts];eta=[F(row[1],sum(row)) for row in counts]
ratios,rows=audit(ps,target_x,eta,[[0]*len(ps),[1]*len(ps)])
source_best=min(range(2),key=lambda i:(rows[i][0],i))
weighted_best=min(range(2),key=lambda i:(rows[i][1],i))
return source_best,weighted_best,ps,eta,ratios
if __name__=='__main__':
target_x=[F(1,10),F(9,10)];counts=[[81,9],[1,9]]
separate,adapted,ps,eta,ratios=fit_constant(counts,target_x)
print('unweighted/weighted constant labels:',separate,adapted)
print('input importance ratios:',*[str(v) for v in ratios])
candidates=[[0,0],[1,1],[0,1]]
for name,target_eta in [('unchanged label mechanism',eta),('flipped label mechanism',[1-v for v in eta])]:
_,rows=audit(ps,target_x,eta,candidates,target_eta)
print(name,'(source, weighted source, actual target risk)')
for h,row in zip(candidates,rows):print(h,*map(str,row))
输出:
unweighted/weighted constant labels: 0 1
input importance ratios: 1/9 9
unchanged label mechanism (source, weighted source, actual target risk)
[0, 0] 9/50 41/50 41/50
[1, 1] 41/50 9/50 9/50
[0, 1] 1/10 1/10 1/10
flipped label mechanism (source, weighted source, actual target risk)
[0, 0] 9/50 41/50 9/50
[1, 1] 41/50 9/50 41/50
[0, 1] 1/10 1/10 9/10
代码使用精确分数,支持至多八输入类别、八候选分类器。接口要求全部源类别概率为正,比只覆盖目标支持更强,作为方便的约定;常数拟合平局选0。K个候选、m个类别的风险求值 O(Km),另计有理数位成本。
分组计数有意构造为指定源分布,所以经验与总体计算在这里相同,不说明任意样本估计的密度比都精确。审计中的目标条件概率是模拟真值,无监督拟合器拿不到。
匹配输入分布,不能识别改变的标签
第二世界保留相同源数据和目标输入比例,把目标条件概率翻转为(9/10,1/10)。所有输入权重、加权源风险不变;选中的常数一模型,真实目标错误却由9/50变为41/50。看似很强的 h(x)=x,真实目标错误为9/10,而加权源估计仍为1/10。
两个目标世界提供完全相同的无标签输入。只看到这些源标签与目标输入的算法,没有额外假设或目标信息,就无法知道哪个标签机制成立。这个明确歧义解释了为何仅做边缘分布对齐不能认证目标准确性。
目标重要区域若在源中罕见,权重也会不稳定。源支持为零时,任何权重都不能凭空补标签。裁剪、平滑比值改变偏差/方差取舍,必须说明。IWCV 论文第2.2节区分一致性论证与有限样本稳定性。
标签漂移假设给定标签的输入分布稳定、标签先验改变;条件或概念漂移改变标签机制。它们是不同模型,不是同一个校正的别名。表示对齐、伪标签、对抗自适应各有假设;把输入压成一团能让域看起来一致,也可能删除标签信息。
分布的哪一部分变了?
- 两类别例子的重要性比是多少?
答案1: 1/9、9,目标输入概率除以源输入概率。
- 为什么常数零在源看起来好,在第一个目标世界却差?
答案2: 类别混合比例反转,错误从9/50变为41/50。
- 审计的两个目标世界中,什么不变?
答案3: 源有标签数据与目标输入比例,只有看不到的目标标签机制改变。
- 纯协变量漂移必然改变不受限 Bayes 分类器吗?
答案4: 不会。条件与损失不变时,逐点决定不变;受限模型的最佳拟合可以变。
优化适应前先审计假设
项目:改变目标输入比例,重算风险表;再在原始、翻转的目标标签机制之间插值,记录加权源风险与真实目标风险的差距。如果采集少量目标审计样本,要与适应、阈值调整分开。
大实验中,在相同目标协议下比较仅源训练、重加权、表示自适应及允许的目标监督基线,报告支持重叠、比值估计、分域指标与不确定性。迁移学习提供更广的复用背景,本章补上成功适应结论必须经受检验的分布假设。
先判断,再看解释
第二目标世界中,输入加权为何失败?
学习目标
- 推导协变量漂移下的目标风险恒等式。
- 在不提供目标标签时拟合加权模型。
- 构造条件漂移反例检验边缘对齐。
先修与延伸
查看知识关联图 →参考文献
- Covariate Shift Adaptation by Importance Weighted Cross Validation
Masashi Sugiyama; Matthias Krauledat; Klaus-Robert Müller · 2007 - A Survey on Transfer Learning — accepted author manuscript
Sinno Jialin Pan; Qiang Yang
版本1 · 编写状态: 已完成记录中的技术复核
查看技术检查记录(AI)
Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.
- 单AI作者技术检查:限定的一手来源位置、假设、原创推导、精确/字面参照及对应双语公式、例子、习题。不冒充人工或第二代理独立审校。
- 每篇四项CPython3.12.4针对性测试通过。精确有理指标、四结果任务风险、源/冻结/梯度拟合与域漂移风险用字面或解析参照核对。无外部运行依赖。
- 完整正文、公式、代码和习题迁入;测试只读取正式MDX,删除临时目录回退及草稿跳过,状态断言更新为checked。没有修改算法或独立参照,最终记录绑定两语SHA。
- 出版导航将已发表主题指向完整文章并移除对应待写措辞,未发表目标保留目录入口;原理、公式、程序与习题未改,重新绑定最终正文SHA。
核对的来源位置:
- Covariate Shift Adaptation by Importance Weighted Cross Validation · JMLR8:985–1005; coverSubmitted6/06, Revised8/06, Published5/07. Physicalpages1–4, Sections2.1–2.2: unchanged conditional, known finite density ratios, misspecification and finite-sample instability. Original exact categorical example; not a reproduction of IWCV experiments.
- A Survey on Transfer Learning — accepted author manuscript · Accepted manuscript Sections2 and4: domain/task distinctions and transductive/domain-adaptation settings; classification of methods as context, not a guarantee that marginal alignment preserves label information.
相关主题