33from sklearn .model_selection import cross_val_score , train_test_split
44from sklearn .metrics import make_scorer
55from spotPython .utils .metrics import mapk_scorer
6+ import pandas as pd
67
78
89def evaluate_model (model , fun_control ):
@@ -42,14 +43,16 @@ def evaluate_hold_out(model, fun_control):
4243 if fun_control ["scaler" ] is not None :
4344 scaler = fun_control ["scaler" ]()
4445 X_train = scaler .fit_transform (X_train )
46+ X_train = pd .DataFrame (
47+ X_train , columns = train_df .drop (target_column , axis = 1 ).columns
48+ ) # Maintain column names
4549 model .fit (X_train , y_train )
4650 except Exception as err :
4751 print (f"Error in evaluate_hold_out(). Call to fit() failed. { err = } , { type (err )= } " )
4852 try :
49- # convert to numpy array, see https://github.com/scikit-learn/scikit-learn/pull/26772
50- X_test = np .array (X_test )
5153 if fun_control ["scaler" ] is not None :
5254 X_test = scaler .transform (X_test )
55+ X_test = pd .DataFrame (X_test , columns = train_df .drop (target_column , axis = 1 ).columns ) # Maintain column names
5356 y_test = np .array (y_test )
5457 if fun_control ["predict_proba" ] or fun_control ["task" ] == "classification" :
5558 df_preds = model .predict_proba (X_test )
@@ -59,7 +62,6 @@ def evaluate_hold_out(model, fun_control):
5962 except Exception as err :
6063 print (f"Error in evaluate_hold_out(). Call to predict() failed. { err = } , { type (err )= } " )
6164 df_eval = np .nan
62- df_eval = np .nan
6365 return df_eval , df_preds
6466
6567
0 commit comments