You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于分类器结果一致性创建Pandas DataFrame列的问题排查

分类器结果匹配筛选异常排查与解决

问题场景

使用两个ML分类器对数据分类得到0、1、2三类结果,希望按分类结果匹配情况拆分DataFrame,操作步骤如下:

  1. 创建匹配判断列:
analyze['noclean_match'] = analyze['vader_class_form']==analyze['roberta_class_formatted']
analyze['clean_match'] = analyze['vader_class_no_SW'] == analyze['roberta_class_nosw']
  1. 筛选匹配样本用于人工检查:
manual_exam = analyze[analyze['clean_match'] == True].sample(n=50)
manual_exam.reset_index(drop=True, inplace = True)

预期筛选出的样本中两个分类器结果一致,但检查时发现:

print(manual_exam['vader_class_form'].iloc[1])
print(manual_exam['roberta_class_formatted'].iloc[1]) 

输出为:

2
1

DataFrame结构信息:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 1405 entries, 0 to 33
Data columns (total 8 columns):
 #   Column                   Non-Null Count  Dtype 
---  ------                   --------------  ----- 
 0   job_id                   1405 non-null   object
 1   formatted                1405 non-null   object
 2   vader_class_form         1405 non-null   int64 
 3   roberta_class_formatted  1405 non-null   int64 
 4   vader_class_no_SW        1405 non-null   int64 
 5   roberta_class_nosw       1405 non-null   int64 
 6   noclean_match            1405 non-null   bool  
 7   clean_match              1405 non-null   bool 

问题根源

筛选逻辑和检查逻辑不匹配:

  • clean_match判断的是去停用词后的分类结果(vader_class_no_SW与roberta_class_nosw)是否相等
  • 但你检查的是未去停用词的分类结果(vader_class_form与roberta_class_formatted),这两组是完全独立的分类结果,本来就可能存在差异,所以出现不一致是正常现象,并非代码逻辑错误。

解决方法

根据你的实际需求选择对应方案:

  1. 验证去停用词后的匹配样本:检查对应列即可,代码如下:
print(manual_exam['vader_class_no_SW'].iloc[1])
print(manual_exam['roberta_class_nosw'].iloc[1])
  1. 筛选未去停用词时的匹配样本:修改筛选条件为noclean_match == True,代码如下:
manual_exam = analyze[analyze['noclean_match'] == True].sample(n=50)
manual_exam.reset_index(drop=True, inplace = True)
  1. 快速验证匹配逻辑正确性:随机抽取一条clean_match为True的行,验证对应列是否真的相等:
test_row = analyze[analyze['clean_match'] == True].iloc[0]
print(test_row['vader_class_no_SW'], test_row['roberta_class_nosw'])

内容的提问来源于stack exchange,提问作者Ja4H3ad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 13:50:17