Issue
# 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
I'm facing the error mentioned in the title. I am trying to classify different types of attack into subclasses. I'm working on the CIC IDS IOT 2023 dataset. The above error is occuring when the code is trying to compute()
the data.
Solution
The lambda
get only one parametre each time , is the one you need use (not 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'
)
Also I corrected the condition with multiple values , see this question
Answered By - حمزة نبيل
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.