refine the code (#276)

This commit is contained in:
WinstonLiyt
2024-09-19 17:15:01 +08:00
committed by GitHub
parent e9846f4ae3
commit ce5f26f308
2 changed files with 4 additions and 9 deletions
@@ -6,15 +6,12 @@ from sklearn.pipeline import Pipeline
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
def prepreprocess(debug_mode=False):
def prepreprocess():
"""
This method loads the data, drops the unnecessary columns, and splits it into train and validation sets.
"""
# Load and preprocess the data
data_df = pd.read_csv("/kaggle/input/train.csv")
if debug_mode:
data_df = data_df.sample(frac=0.1, random_state=42)
data_df = data_df
data_df = data_df.drop(["id"], axis=1)
X = data_df.drop(["class"], axis=1)
@@ -81,11 +78,11 @@ def preprocess_transform(X: pd.DataFrame, preprocessor):
return X_transformed
def preprocess_script(debug_mode=False):
def preprocess_script():
"""
This method applies the preprocessing steps to the training, validation, and test datasets.
"""
X_train, X_valid, y_train, y_valid = prepreprocess(debug_mode=debug_mode)
X_train, X_valid, y_train, y_valid = prepreprocess()
# Fit the preprocessor on the training data
preprocessor = preprocess_fit(X_train)
@@ -96,8 +93,6 @@ def preprocess_script(debug_mode=False):
# Load and preprocess the test data
submission_df = pd.read_csv("/kaggle/input/test.csv")
if debug_mode:
data_df = data_df.sample(frac=0.1, random_state=42)
passenger_ids = submission_df["id"]
submission_df = submission_df.drop(["id"], axis=1)
X_test = preprocess_transform(submission_df, preprocessor)
@@ -13,7 +13,7 @@ KG_FEATURE_PREPROCESS_SCRIPT = """import pickle
from fea_share_preprocess import preprocess_script
X_train, X_valid, y_train, y_valid, X_test, passenger_ids = preprocess_script(debug_mode=True)
X_train, X_valid, y_train, y_valid, X_test, passenger_ids = preprocess_script()
pickle.dump(X_train, open("X_train.pkl", "wb"))
pickle.dump(X_valid, open("X_valid.pkl", "wb"))