第21章推薦システム
21.2.2. Statistics of the Dataset21.2.2 データセットの統計
Let’s load up the data and inspect the first five records manually. It is an effective way to learn the data structure and verify that they have been loaded properly.
英語のヒント
データを読み込んで、最初の5件の記録を手作業で調べよう。これは、データの構造を知り、正しく読み込まれたことを確かめる効果的な方法である。
data, num_users, num_items = read_data_ml100k()
sparsity = 1 - len(data) / (num_users * num_items)
print(f'number of users: {num_users}, number of items: {num_items}')
print(f'matrix sparsity: {sparsity:f}')
print(data.head(5))number of users: 943, number of items: 1682
matrix sparsity: 0.936953
user_id item_id rating timestamp
0 196 242 3 881250949
1 186 302 3 891717742
2 22 377 1 878887116
3 244 51 2 880606923
4 166 346 1 886397596We can see that each line consists of four columns, including “user id” 1-943, “item id” 1-1682, “rating” 1-5 and “timestamp”. We can construct an interaction matrix of size , where and are the number of users and the number of items respectively. This dataset only records the existing ratings, so we can also call it rating matrix and we will use interaction matrix and rating matrix interchangeably in case that the values of this matrix represent exact ratings. Most of the values in the rating matrix are unknown as users have not rated the majority of movies. We also show the sparsity of this dataset. The sparsity is defined as
1 - number of nonzero entries / ( number of users * number of items). Clearly, the interaction matrix is extremely sparse (i.e., sparsity = 93.695%). Real world datasets may suffer from a greater extent of sparsity and has been a long-standing challenge in building recommender systems. A viable solution is to use additional side information such as user/item features to alleviate the sparsity.英語のヒント
各行が、「user id」(1〜943)、「item id」(1〜1682)、「rating」(1〜5)、「timestamp」の四つの列からなることがわかる。大きさのやりとり行列を作れる。ここで、とはそれぞれ利用者の数とアイテムの数である。このデータセットは存在する評価だけを記録しているので、これを評価行列と呼ぶこともでき、この行列の値が正確な評価を表す場合には、やりとり行列と評価行列を区別せずに使う。利用者はたいていの映画を評価していないので、評価行列の値のほとんどは未知である。このデータセットの疎性も示す。疎性は
1 - number of nonzero entries / ( number of users * number of items)と定義される。明らかに、やりとり行列はきわめて疎である(つまり疎性は93.695%)。現実のデータセットはさらに大きな疎性に悩まされることがあり、これは推薦システムを作るうえで長年の難題であった。実行可能な解決策の一つは、利用者やアイテムの特徴のような追加の付随情報を使って疎性を和らげることである。We then plot the distribution of the count of different ratings. As expected, it appears to be a normal distribution, with most ratings centered at 3-4.
英語のヒント
それから、異なる評価の件数の分布をプロットする。予想どおり、たいていの評価が3〜4に集まった正規分布のように見える。
d2l.plt.hist(data['rating'], bins=5, ec='black')
d2l.plt.xlabel('Rating')
d2l.plt.ylabel('Count')
d2l.plt.title('Distribution of Ratings in MovieLens 100K')
d2l.plt.show()