Skip to content

Instantly share code, notes, and snippets.

@singhrahuldps
Created June 1, 2019 04:51
Show Gist options
  • Save singhrahuldps/5830ac62070d918929c5918e1642d469 to your computer and use it in GitHub Desktop.
Save singhrahuldps/5830ac62070d918929c5918e1642d469 to your computer and use it in GitHub Desktop.
# splits ratings dataframe to training and validation dataframes
def get_data(ratings, valid_pct:float = 0.2):
# shuffle the indexes
ln = random.sample(range(0, len(ratings)), len(ratings))
# split based on the given validation set percentage
part = int(len(ln)*valid_pct)
valid_index = ln[0:part]
train_index = ln[part:]
valid = ratings.iloc[valid_index]
train = ratings.iloc[train_index]
return [train,valid]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment