4.9 KiB
4.9 KiB
In [ ]:
from pathlib import Path
import numpy as np
import pandas as pd
DATA_PATH = Path("data/synthetic_security_flows.csv")
RANDOM_STATE = 42
In [ ]:
# TODO 1: load DATA_PATH into a DataFrame named df
df = None
# TODO 2: display the first five rows
print("Shape:", None)
df
In [ ]:
# TODO 3: store the original label column in y_text
y_text = None
# TODO 4: create X using only numeric columns and exclude Label
X = None
print("Feature matrix shape:", None)
print("Original labels:")
print(None)
In [ ]:
# BENIGN becomes 0. Every attack family becomes 1.
# TODO 5: normalize labels with strip() and upper(), then create y_binary
y_binary = None
# TODO 6: calculate class_counts sorted by class index
class_counts = None
print(class_counts)
print("Attack rate:", None)
In [ ]:
sample_index = 0
# TODO 7: select one row from X as sample_features and its target as sample_target
sample_features = None
sample_target = None
print("Selected feature vector:")
print(sample_features)
print("Binary target:", sample_target)
In [ ]:
assert isinstance(df, pd.DataFrame)
assert "Label" not in X.columns
assert set(y_binary.unique()) == {0, 1}
assert len(X) == len(y_binary)
assert class_counts.loc[0] > class_counts.loc[1]
assert len(sample_features) == X.shape[1]
print("✓ Lab 1 completed")