如何处理图书交叉数据集中的 0 个条目

How to handle 0 entries in book crossing dataset

我正在处理书籍 crossing Data-set ,它有一个文件给出了用户 X 对书籍 Y 的评分,但是很多条目包含值 0,这意味着用户 X 喜欢书籍 Y 但没有给出评分给它。我正在使用协同过滤,因此这些 0 条目给我带来了问题,就好像被 0 分会降低这本书的整体评分。

我是数据科学领域的新手,有人可以帮助我解决这个问题吗?

我能想到的是用用户的平均图书评分代替 0 评分,但我又没有任何论据来支持我的想法。

ISBN码很乱,错的ISBN很多,不统一

这里只是几个例子:

"User-ID";"ISBN";"Book-Rating"
"11676";" 9022906116";"7"
"11676";"\"0432534220\"";"6"
"11676";"\"2842053052\"";"7"
"11676";"0 7336 1053 6";"0"
"11676";"0=965044153";"7"
"11676";"0000000000";"9"
"11676";"00000000000";"8"
"146859";"01402.9182(PB";"7"
"158509";"0672=630155(P";"0"
"194500";"(THEWINDMILLP";"0"

所以我建议先清理一下:

df.ISBN = df.ISBN.str.replace(r'[^\w\d]+', '')

然后计算平均收视率:

avg_ratings = df.groupby('ISBN')['Book-Rating'].mean().round().astype(np.int8)

最后为这些书籍设置平均评分,评分为零:

df.loc[df['Book-Rating'] == 0, 'Book-Rating'] = df.loc[df['Book-Rating'] == 0, 'ISBN'].map(avg_ratings)

更新:

从 Pandas 0.20.1 the .ix indexer is deprecated, in favor of the more strict .iloc and .loc indexers 开始。