类型错误:<lambda>() 缺少 6 个必需的位置参数:'b'、'c'、'd'、'e'、'f' 和 'g'

问题描述 投票:0回答:1
# Create a new column 'new_label' based on the 'label' column
selected_data['new_label'] = selected_data['label'].apply(lambda a,b,c,d,e,f,g: 'DDoS' if a.startswith('DDoS') else 'Mirai' if b.startswith('Mirai') else 'Recon' if c.startswith('Recon' or 'Vulnerability') else 'Spoofing' if d.startswith('DNS' or 'MITM') 
  else 'Benign' if e.startswith('Benign') else 'Web' if f.startswith('Browser' or 'Backdoor' or 'XSS' or 'Uploading' or 'Sql' or 'Command') else 'BruteForce' if g.startswith('Dictionary') else 'other', meta=('new_label', 'object'))

# Compute the result
selected_data = selected_data.compute()
selected_data
TypeError                                 Traceback (most recent call last)
<ipython-input-40-cdf5d20f0f25> in <cell line: 6>()
      4 
      5 # Compute the result
----> 6 selected_data = selected_data.compute()
      7 selected_data

我遇到了标题中提到的错误。我试图将不同类型的攻击分为子类。我正在研究 CIC IDS IOT 2023 数据集。当代码尝试

compute()
数据时,会发生上述错误。

python machine-learning deep-learning multiclass-classification
1个回答
0
投票

lambda
每次只获取一个参数,是你需要使用的参数(不是6个):

selected_data['new_label'] = selected_data['label'].apply(
   lambda label: 'DDoS' if label.startswith('DDoS')
   else 'Recon' if label.startswith(('Recon', 'Vulnerability'))
   else 'Other'
)

我还用多个值纠正了条件

© www.soinside.com 2019 - 2024. All rights reserved.