Beispiel #1
0
import os
import sys

sys.path.append(os.getcwd())

import recommendation

print recommendation.rmse('result')
Beispiel #2
0
	rmse    = 0.0
	test_records = 0
	counter = 0
	for user in customer:
		counter += 1
		recommendation.init_item_warehouse(item_warehouse)
		for item in item_warehouse:
			if item not in customer[user]['items']:
				score = vector.dot(customer[user]['feature'],item_warehouse[item]['feature'])
				if score > 5:
					score = 5.

				item_warehouse[item]['score'] = score

		if user in tester:
			result = recommendation.rmse(tester[user],item_warehouse)
			rmse += result[0]
			test_records += result[1]

#	print rmse,test_records
	rmse_local += sqrt(rmse * 1.0 / test_records)
print rmse_local / 5.

'''	if user in tester:
		test_records += len(tester[user])
		for titem in tester[user]:
			rs = recommendation.rankingscore(customer[user],titem,item_warehouse)

			ranking_score += rs

Beispiel #3
0
movies = ['mv_0013581','mv_0011328','mv_0008433','mv_0004607','mv_0000001',
          'mv_0000408']
# Predict the ratings corresponding to (movie,user) pair in test files in test
# folder
result = open('result','w')
for movie in movies:
    f = open('test/'+movie+'.txt')
    lines = f.readlines()
    f.close()
    user_list = []
    for i in range(1,len(lines)):
        line = lines[i]
        u = line.split(',',1)[0]
        user_list.append(u)

    for user in user_list:
        start = time.clock()
        test = recommendation.getRate(user,movie)
        print movie+'\t'+user+'\t'+str(test)
        print 'Prediction time: '+str(time.clock()-start)+' seconds\n'
        result.write(movie+'\t'+user+'\t'+str(test)+'\t'+str(time.clock()-start)
                     +'\n')
result.close()

# Evaluate accuracy
accuracy = recommendation.rmse('result')
print 'RMSE: '+str(accuracy)
prepare.create_error_statistic_file('result')