INNER CODE UNIT · Python
load_sample
google/fully-homomorphic-encryption · demos/cc_fraud/cleartext/evaluate_cleartext.py:20
def load_sample(
data_path: str, feature_cols: list[str], sample_idx: int
) -> tuple[np.ndarray, int]:
"""Loads a single sample from the dataset."""
resolved_data_path = resolve_path(data_path)
if not os.path.exists(resolved_data_path):
raise FileNotFoundError(
f"Data file not found at {data_path} (resolved: {resolved_data_path})"
)
if data_path.endswith(".parquet"):
df = pd.read_parquet(resolved_data_path)
X = df[feature_cols].values.astype(np.float32)
y = df["is_fraud"].values.astype(np.int64)
# Retrieve the test split (same random seed/stratify as train.py)
_, X_test, _, y_test = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y
)