jamescalam commited on
Commit
b77b27d
1 Parent(s): 6d4b7d4

Update movielens-recent-ratings.py

Browse files
Files changed (1) hide show
  1. movielens-recent-ratings.py +12 -2
movielens-recent-ratings.py CHANGED
@@ -2,6 +2,7 @@ import datasets
2
  import pandas as pd
3
  import re
4
  import json
 
5
 
6
  _CITATION = """\
7
  @InProceedings{huggingface:dataset,
@@ -81,13 +82,22 @@ class MovieLens(datasets.GeneratorBasedBuilder):
81
  df = df[
82
  ["imdb_id", "movie_id", "user_id", "rating", "title", "poster"]
83
  ]
 
 
 
 
84
  # save
85
- df.to_json(new_url+"/ratings.jsonl", orient="records", lines=True)
 
86
 
87
  return [
88
  datasets.SplitGenerator(
89
  name=datasets.Split.TRAIN,
90
- gen_kwargs={"filepath": new_url+"/ratings.jsonl"}
 
 
 
 
91
  ),
92
  ]
93
 
 
2
  import pandas as pd
3
  import re
4
  import json
5
+ from sklearn.model_selection import train_test_split
6
 
7
  _CITATION = """\
8
  @InProceedings{huggingface:dataset,
 
82
  df = df[
83
  ["imdb_id", "movie_id", "user_id", "rating", "title", "poster"]
84
  ]
85
+ # create train-test split
86
+ train, test = train_test_split(
87
+ df, test_size=0.1, shuffle=True, stratify=df["movie_id"], random_state=0
88
+ )
89
  # save
90
+ train.to_json(new_url+"/train.jsonl", orient="records", lines=True)
91
+ test.to_json(new_url+"/test.jsonl", orient="records", lines=True)
92
 
93
  return [
94
  datasets.SplitGenerator(
95
  name=datasets.Split.TRAIN,
96
+ gen_kwargs={"filepath": new_url+"/train.jsonl"}
97
+ ),
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TEST,
100
+ gen_kwargs={"filepath": new_url+"/test.jsonl"}
101
  ),
102
  ]
103