GitHub Action commited on
Commit
8f1b35b
·
1 Parent(s): 01242e9

Sync from GitHub: 3d2620f3f8b6b28524e97ac1994f93c8326be76c

Browse files
Files changed (1) hide show
  1. training_service.py +10 -2
training_service.py CHANGED
@@ -53,14 +53,22 @@ def make_splits(df, test_frac=0.05, time_col='step', min_test_fraud=100, random_
53
  """
54
  Returns: X_train, X_test, y_train, y_test
55
  """
 
 
 
 
 
 
56
  # Temporal test split
57
  if time_col in df.columns:
58
  cutoff = df[time_col].quantile(1 - test_frac)
59
  train_df = df[df[time_col] <= cutoff].reset_index(drop=True)
60
  test_df = df[df[time_col] > cutoff].reset_index(drop=True)
61
  else:
62
- train_df = df.copy()
63
- test_df = pd.DataFrame(columns=df.columns)
 
 
64
 
65
  # Fallback to stratified split if test set is poor
66
  if (test_df.empty) or (test_df['isFraud'].sum() < min_test_fraud):
 
53
  """
54
  Returns: X_train, X_test, y_train, y_test
55
  """
56
+ # Normalize column names
57
+ if 'is_fraud' in df.columns:
58
+ df = df.rename(columns={'is_fraud': 'isFraud'})
59
+ if 'fraud' in df.columns:
60
+ df = df.rename(columns={'fraud': 'isFraud'})
61
+
62
  # Temporal test split
63
  if time_col in df.columns:
64
  cutoff = df[time_col].quantile(1 - test_frac)
65
  train_df = df[df[time_col] <= cutoff].reset_index(drop=True)
66
  test_df = df[df[time_col] > cutoff].reset_index(drop=True)
67
  else:
68
+ # Random split if no time column
69
+ train_df, test_df = train_test_split(df, test_size=test_frac, stratify=df.get('isFraud'), random_state=42)
70
+ train_df = train_df.reset_index(drop=True)
71
+ test_df = test_df.reset_index(drop=True)
72
 
73
  # Fallback to stratified split if test set is poor
74
  if (test_df.empty) or (test_df['isFraud'].sum() < min_test_fraud):