python退出帮助系统在哪_求帮忙跑一下,实在找不出问题在哪,基于word2vec的推荐系统...

基于word2vec的推荐系统named item2vec。网上也能搜到,想实现一下。文章中准确率达0.44,我跑出来的低的令人发指,是在找不出问题在哪,有兴趣的希望能帮忙跑一下,谢谢!;python 2.7

from gensim.models import Word2Vec

import logging

import sys

reload(sys)

sys.setdefaultencoding('utf8')

from sklearn.model_selection import train_test_split

c = []

def load_sequence(from_path):

with open(from_path) as fp:

[c.append(line.strip().split(",")) for line in fp]

def main():

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

load_sequence('E:\\pythonwork\\1105\\to666.txt') # 加载语料

c_train,c_text = train_test_split(c,test_size=0.2)

model = Word2Vec(c_train, size=20, window=3, min_count=1, workers=1, iter=3, sample=1e-4, negative=20) # 训练skip-gram模型; 默认window=5

test_size = float(len(c_text))

hit = 0.0

for current_pattern in c_text:

if len(current_pattern) < 2:

test_size -= 1.0

continue

# Reduce the current pattern in the test set by removing the last item

last_item = current_pattern.pop()

# Keep those items in the reduced current pattern, which are also in the models vocabulary

items = [it for it in current_pattern if it in model.wv.vocab]

if len(items) <= 2:

test_size -= 1.0

continue

# Predict the most similar items to items

prediction = model.most_similar(positive=items,topn=20)

# Check if the item that we have removed from the test, last_item, is among

# the predicted ones.

for predicted_item, score in prediction:

if predicted_item == last_item:

hit += 1.0

print 'Accuracy like measure: {}'.format(hit / test_size)

if __name__ == "__main__":

main()

数据集:链接描述

参考样例:链接描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值