第21章推薦システム
21.2.1. Getting the Data21.2.1 データを入手する
The MovieLens dataset is hosted by the GroupLens website. Several versions are available. We will use the MovieLens 100K dataset (Herlocker et al., 1999). This dataset is comprised of ratings, ranging from 1 to 5 stars, from 943 users on 1682 movies. It has been cleaned up so that each user has rated at least 20 movies. Some simple demographic information such as age, gender, genres for the users and items are also available. We can download the ml-100k.zip and extract the
u.data file, which contains all the ratings in the csv format. There are many other files in the folder, a detailed description for each file can be found in the README file of the dataset.英語のヒント
MovieLensのデータセットは、GroupLensのウェブサイトで公開されている。いくつかの版が手に入る。ここではMovieLens 100Kのデータセット(Herlocker et al., 1999)を使う。このデータセットは、943人の利用者による1682本の映画への、1から5の星の件の評価からなる。各利用者が少なくとも20本の映画を評価しているように整理されている。利用者とアイテムについての年齢、性別、ジャンルのような簡単な人口統計的な情報も手に入る。ml-100k.zipをダウンロードし、すべての件の評価をCSV形式で含む
u.dataファイルを展開できる。フォルダにはほかにも多くのファイルがあり、各ファイルの詳しい説明はデータセットのREADMEファイルにある。To begin with, let’s import the packages required to run this section’s experiments.
英語のヒント
まず、この節の実験を実行するのに必要なパッケージをインポートしよう。
import os
import pandas as pd
from mxnet import gluon, np
from d2l import mxnet as d2lThen, we download the MovieLens 100k dataset and load the interactions as
DataFrame.英語のヒント
それから、MovieLens 100kのデータセットをダウンロードし、やりとりを
DataFrameとして読み込む。#@save
d2l.DATA_HUB['ml-100k'] = (
'https://files.grouplens.org/datasets/movielens/ml-100k.zip',
'cd4dcac4241c8a4ad7badc7ca635da8a69dddb83')
#@save
def read_data_ml100k():
data_dir = d2l.download_extract('ml-100k')
names = ['user_id', 'item_id', 'rating', 'timestamp']
data = pd.read_csv(os.path.join(data_dir, 'u.data'), sep='\t',
names=names, engine='python')
num_users = data.user_id.unique().shape[0]
num_items = data.item_id.unique().shape[0]
return data, num_users, num_items