Last active
August 30, 2021 14:56
-
-
Save bkaankuguoglu/77c8342a4181e43e61094db912e8b86c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import train_test_split | |
def feature_label_split(df, target_col): | |
y = df[[target_col]] | |
X = df.drop(columns=[target_col]) | |
return X, y | |
def train_val_test_split(df, target_col, test_ratio): | |
val_ratio = test_ratio / (1 - test_ratio) | |
X, y = feature_label_split(df, target_col) | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=test_ratio, shuffle=False) | |
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=val_ratio, shuffle=False) | |
return X_train, X_val, X_test, y_train, y_val, y_test | |
X_train, X_val, X_test, y_train, y_val, y_test = train_val_test_split(df_features, 'value', 0.2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment