Created
October 30, 2020 00:19
-
-
Save aagnone3/10ba702d7de8f86330e7e152499150bb to your computer and use it in GitHub Desktop.
sf_crime_12.py
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
def time_split(df, validation_pct=0.2): | |
df = df.sort_values("Dates") | |
split_date = df.loc[df.index[int(len(df) * (1 - validation_pct))], "Dates"] | |
return df.index[df["Dates"] <= split_date], df.index[df["Dates"] > split_date] | |
train_idx, validation_idx = time_split(train, validation_pct=0.2) | |
print(f"Training data has {len(train_idx)} samples from {train.loc[train_idx, 'Dates'].min()} to {train.loc[train_idx, 'Dates'].max()}") | |
print(f"Validation data has {len(validation_idx)} samples from {train.loc[validation_idx, 'Dates'].min()} to {train.loc[validation_idx, 'Dates'].max()}") | |
train.drop("Dates", axis=1, inplace=True) | |
to = TabularPandas(train, | |
procs=[Categorify, FillMissing, Normalize], | |
cat_names=cat, | |
cont_names=cont, | |
y_names="TargetedCategory", | |
splits=[list(train_idx), list(validation_idx)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment