mirror of
https://github.com/apachecn/ailearning.git
synced 2026-02-13 15:26:28 +08:00
更新文件名
This commit is contained in:
@@ -200,7 +200,7 @@ class ItemBasedCF():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ratingfile = 'input/16.RecommendedSystem/ml-1m/ratings.dat'
|
||||
ratingfile = 'input/16.RecommenderSystems/ml-1m/ratings.dat'
|
||||
|
||||
# 创建ItemCF对象
|
||||
itemcf = ItemBasedCF()
|
||||
@@ -1,17 +1,18 @@
|
||||
|
||||
|
||||
# 负样本采样过程
|
||||
def RandomSelectNegativeSample(self, items):
|
||||
ret = dict()
|
||||
for i in items.keys():
|
||||
ret[i] = 1
|
||||
|
||||
|
||||
n = 0
|
||||
for i in range(0, len(items) * 3):
|
||||
item = items_pool[random.randint(0, len(items_pool) - 1)]
|
||||
if item in ret:
|
||||
continue
|
||||
ret[item] = 0
|
||||
n + = 1
|
||||
n += 1
|
||||
if n > len(items):
|
||||
break
|
||||
return ret
|
||||
@@ -19,7 +20,7 @@ def RandomSelectNegativeSample(self, items):
|
||||
|
||||
def LatentFactorModel(user_items, F, N, alpha, lambda):
|
||||
[P, Q] = InitModel(user_items, F)
|
||||
for step in range(0,N):
|
||||
for step in range(0, N):
|
||||
for user, items in user_items.items():
|
||||
samples = RandSelectNegativeSamples(items)
|
||||
for item, rui in samples.items():
|
||||
@@ -208,7 +208,7 @@ class UserBasedCF():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ratingfile = 'input/16.RecommendedSystem/ml-1m/ratings.dat'
|
||||
ratingfile = 'input/16.RecommenderSystems/ml-1m/ratings.dat'
|
||||
|
||||
# 创建UserCF对象
|
||||
usercf = UserBasedCF()
|
||||
Reference in New Issue
Block a user