コード例 #1
0
ファイル: A6.py プロジェクト: TimothyBruce/anwala.github.io
def main():
    prefs = r.loadMovieLens(
        os.getcwd() +
        "/ml-100k")  # Calculates the preferences using recommendations.py
    movie_recommendations = r.getRecommendations(
        prefs, str(sub_id))  # Calculates all recommendations for sub user.

    print("\nThe most recommended movies for " + get_user(sub_id) +
          " (which is the substitute) are:")
    for i in range(
            5):  # This section prints out the recommendations for sub user.
        u = movie_recommendations[i][1]
        print(u)
    print("\nThe least recommended movies for the substitute are: ")
    for i in range(5):
        u = movie_recommendations[len(movie_recommendations) - (i + 1)][1]
        print(u)

    similiar_item_data = r.calculateSimilarItems(
        prefs)  # Calculate all similar movie data.
    print("\nFive similar movies to my favorite movie " + favorite_movie +
          " are:")
    fav_mov_sim = similiar_item_data[favorite_movie][
        0:5]  # For real me, some recommended movies for my preferences.
    for mov in fav_mov_sim:
        print(mov[1] + "    " + str(mov[0]))

    print("\nFive similar movies to my least favorite movie " +
          least_favorite_movie + " are:")
    lea_fav_mov_sim = similiar_item_data[least_favorite_movie][0:5]
    for mov in lea_fav_mov_sim:
        print(mov[1] + "    " + str(mov[0]))
コード例 #2
0
ファイル: A6.py プロジェクト: TimothyBruce/anwala.github.io
def get_most_and_least_similar_users():
    """
    Calculates users that are similar to the substitute user from problem one. Early on, I noticed that the program
    took a while to execute, so I multi-threaded the sim_distance function to expedite execution.

    :return:
    Prints out data on the top five most similar and least similar users to the substitute user.
    """
    pool = mp.Pool(mp.cpu_count())
    prefs = r.loadMovieLens(os.getcwd() + "/ml-100k")
    similarity_data = [
        pool.apply(get_similarity_data, args=(prefs, other_id + 1))
        for other_id in range(943)
    ]
    pool.close()
    similarity_data = sorted(similarity_data, key=lambda x: x[1])

    print("The most similar users to " + get_user(sub_id) +
          " (which is the substitute) are:")
    for i in range(5):
        u = get_user(similarity_data[len(similarity_data) - (i + 1)][0])
        print(u)

    print("\nThe least similar users are: ")
    for i in range(5):
        u = get_user(similarity_data[i][0]).split("\n")[0]
        print(u)
コード例 #3
0
def main():
    check_ids = find_similar_users()
    lens_data = recommendations.loadMovieLens()

    substitute_me = '645'
    find_favorite_movies(check_ids, lens_data)
    find_least_favorite_movies(check_ids, lens_data)
    find_correlated_users_subsitute(substitute_me, lens_data)
    find_least_correlated_users_subsitute(substitute_me, lens_data)
    get_top_recomendations(substitute_me,lens_data)
    get_worst_recomendations(substitute_me, lens_data)
    find_corerelated_films(lens_data)
コード例 #4
0
def main():
    results = {}
    resultsOfloadMovieLens = recommendations.loadMovieLens()
    uniqueValues = resultsOfloadMovieLens.keys()
    length = len(resultsOfloadMovieLens)

    for key in range(0,length):
        resultsOftopMatches = recommendations.topMatches(resultsOfloadMovieLens,uniqueValues[key],n=length)        
        for value in resultsOftopMatches:
            if value[1] == uniqueValues[key]:
                pass
              
    
    for key, value in sorted(results.items(), key=lambda e: e[1], reverse=True):        
        print key, results[key]
コード例 #5
0
ファイル: ratingsTopGun.py プロジェクト: bbreddy123/cs595-f14
def main():
    count = "Top Gun (1986)"
    resultsOfloadMovieLens = recommendations.loadMovieLens()
    resultsOfcalculateSimilarItems = recommendations.calculateSimilarItems(resultsOfloadMovieLens, n=80)
    print "*" * 60
    print "Movies received ratings most like or least like Top Gun"
    print "*" * 60
    print "value\t\t\t\t\t", "Movie Name"
    print "-" * 60

    for key, value in sorted(resultsOfcalculateSimilarItems.items(), key=lambda e: e[1], reverse=True):
        variable = key
        if count == variable:
            for value, movie in value:
                print value, movie
コード例 #6
0
def main():
    count = 'Top Gun (1986)'
    resultsOfloadMovieLens         = recommendations.loadMovieLens()
    resultsOfcalculateSimilarItems = recommendations.calculateSimilarItems(resultsOfloadMovieLens,n=80)
    print "*" * 60
    print "Movies received ratings most like or least like Top Gun"    
    print "*" * 60      
    print "value\t\t\t\t\t","Movie Name" 
    print "-" * 60 
    
    for key, value in sorted(resultsOfcalculateSimilarItems.items(), key=lambda e: e[1], reverse=True):        
        variable = key
        if (count == variable):  
            for value , movie in value: 
                print  value , movie            
コード例 #7
0
def main():
    results = {}
    resultsOfloadMovieLens = recommendations.loadMovieLens()
    uniqueValues = resultsOfloadMovieLens.keys()
    length = len(resultsOfloadMovieLens)

    for key in range(0, length):
        resultsOftopMatches = recommendations.topMatches(
            resultsOfloadMovieLens, uniqueValues[key], n=length)
        for value in resultsOftopMatches:
            if value[1] == uniqueValues[key]:
                pass

    for key, value in sorted(results.items(), key=lambda e: e[1],
                             reverse=True):
        print key, results[key]
コード例 #8
0
ファイル: topgun01.py プロジェクト: vneblitt/cs595-f13
# Valentina Neblitt-Jones
# CS 595 Introduction to Web Science
# Fall 2013
# Assignment #8 Question #5
# What movie received ratings most like Top Gun? Which movie received ratings that were least like Top Gun (negative correlation)?

import sys
import pprint

sys.path.insert(0, '/Users/vneblitt/Documents/cs595-f13/assignment08/library')

import recommendations

g = open('topgun.txt', 'w')

prefs = recommendations.loadMovieLens(path='/Users/vneblitt/Documents/cs595-f13/assignment08/dataset')

answer = recommendations.calculateSimilarItems(prefs,n=1664)

pp = pprint.PrettyPrinter(indent=4)

pp.pprint(answer['Top Gun (1986)'])

g.write(str(answer))
g.close()
コード例 #9
0
print recommendations.topMatches(recommendations.critics,'Toby',n=3,similarity=recommendations.sim_distance)

recommendations.getRecommendations(recommendations.critics,'Toby')

recommendations.getRecommendations(recommendations.critics,'Toby',similarity=recommendations.sim_distance)

movies=recommendations.transformPrefs(recommendations.critics)

#print movies

recommendations.topMatches(movies,'Superman Returns')

recommendations.getRecommendations(movies,'Just My Luck')

recommendations.getRecommendations(movies,'Lady in the Water')

itemsim=recommendations.calculateSimilarItems(recommendations.critics,n=8)
itemsim

recommendations.getRecommendedItems(recommendations.critics,itemsim,'Toby')

prefs=recommendations.loadMovieLens()
prefs['87']


recommendations.getRecommendations(prefs,'87')[0:30]

itemsim1=recommendations.calculateSimilarItems(prefs,n=50)
recommendations.getRecommendedItems(prefs,itemsim1,'87')[0:30]
コード例 #10
0
ファイル: correlated.py プロジェクト: Rokuji/Python
import recommendations as rec

pref = rec.loadMovieLens()
correlated = rec.topMatches(1, pref, '73')
noncorrelated = rec.topMatches(0, pref, '73')
print "Five Most Correlated Users: " + '73'
print "--------------------------------------------------------"
for user in correlated:
    print user[1]

print "--------------------------------------------------------"

print "Five Least Correlated Users: " + '73'
print "--------------------------------------------------------"
for user in noncorrelated:
    print user[1]
コード例 #11
0
ファイル: main.py プロジェクト: digideskio/MLStudy
# 
from appdata import AppData
import recommendations as rec
import sys
import pickle

if __name__ == '__main__':
  prefs = rec.loadMovieLens('../data/movielens-100k')
  itemPrefs=rec.transformPrefs(prefs)

  try:
    input = open('itemNeighbours.pkl', 'rb')
    itemNeighbours = pickle.load(input)
    input.close()
  except Exception, e:
    print "Calculating itemNeighbours.pkl"
    itemNeighbours = rec.calcNarestNeighbours(prefs, 10)
    output = open('itemNeighbours.pkl', 'wb')
    pickle.dump(itemNeighbours, output)
    output.close()

  try:
    input = open('userNeighbours.pkl', 'rb')
    userNeighbours = pickle.load(input)
    input.close()
  except Exception, e:
    print "Calculating userNeighbours.pkl"
    userNeighbours = rec.calcNarestNeighbours(itemPrefs, 10)
    output = open('userNeighbours.pkl', 'wb')
    pickle.dump(userNeighbours, output)
    output.close()
コード例 #12
0
#!/usr/local/bin/python
import sys
import recommendations

if __name__ == '__main__':
    fav_moviename   = "Die Hard (1988)"
    hate_moviename = "Kazaam (1996)"
    prefs = recommendations.loadMovieLens()
    itemPrefs = recommendations.transformPrefs(prefs)
    fav_results   = recommendations.topMatches(itemPrefs,fav_moviename,2000)
    hate_results   = recommendations.topMatches(itemPrefs,hate_moviename,2000)
    
print "Most 5 correlated for my top favourite movie"
for i in fav_results[0:5]:
	print i[0],i[1]
print '\n'
print "Least 5 correlated for my top favourite movie"    
fav_results.reverse()
for i in fav_results[0:5]:
	print i[0],i[1]
print '\n'        
print "Most 5 correlated for my least favourite movie"
for i in hate_results[0:5]:
	print i[0],i[1]
print '\n'
print "Least 5 correlated for my least favourite movie"    
hate_results.reverse()
for i in hate_results[0:5]:
	print i[0],i[1]
        
コード例 #13
0
#
from appdata import AppData
import recommendations as rec
import sys
import pickle

if __name__ == '__main__':
    prefs = rec.loadMovieLens('../data/movielens-100k')
    itemPrefs = rec.transformPrefs(prefs)

    try:
        input = open('itemNeighbours.pkl', 'rb')
        itemNeighbours = pickle.load(input)
        input.close()
    except Exception, e:
        print "Calculating itemNeighbours.pkl"
        itemNeighbours = rec.calcNarestNeighbours(prefs, 10)
        output = open('itemNeighbours.pkl', 'wb')
        pickle.dump(itemNeighbours, output)
        output.close()

    try:
        input = open('userNeighbours.pkl', 'rb')
        userNeighbours = pickle.load(input)
        input.close()
    except Exception, e:
        print "Calculating userNeighbours.pkl"
        userNeighbours = rec.calcNarestNeighbours(itemPrefs, 10)
        output = open('userNeighbours.pkl', 'wb')
        pickle.dump(userNeighbours, output)
        output.close()
コード例 #14
0
ファイル: recommend.py プロジェクト: chenruixuan/course
 def __init__(self):
     #userId为数据集中的用户ID,类型为str。maxNum为想要的推荐电影数量。
     self.userId = ''
     self.maxNum = 0
     self.resultList = []
     self.prefs = recommendations.loadMovieLens()
コード例 #15
0
ファイル: getFilmsLike.py プロジェクト: mkoga001/cs595-f13
#!/usr/local/bin/python

import sys
import pprint

sys.path.insert(0, '../starter-code')

import recommendations

if __name__ == '__main__':

    film = sys.argv[1]
    threshold = int(sys.argv[2])
    direction = sys.argv[3]

    prefs = recommendations.loadMovieLens('../data')

    result = recommendations.calculateSimilarItems(prefs, n=1682)

    if direction == 'most':
        print "Movies most like '" + film + "': '"
        for i in range(0, threshold):
            print result[film][i][1] + ' (' + str(result[film][i][0]) + ')'
    else:
        print "Movies least like '" + film + "': '"
        for i in range(1, threshold):
            print result[film][-i][1] + ' (' + str(result[film][-i][0]) + ')'
コード例 #16
0
ファイル: question4.py プロジェクト: jocII/cs532-s16
import recommendations as rec

prefs = rec.loadMovieLens("../data/ml-100k")


def getTopAndBottomCorrelated(movie_info, movie):
    m = movie_info[movie]
    top = m[:5]
    bottom = m[len(m) - 5 :]
    bottom.reverse()
    return top, bottom


movies_info = rec.calculateSimilarItems(prefs, n=2000, best=True)

best_movie = "Stargate (1994)"
worst_movie = "Batman Forever (1995)"

table = open("../docs/q4_table.tex", "w")
table.write("My favorite film from the data is: " + best_movie + "\n\n")
top, bottom = getTopAndBottomCorrelated(movies_info, best_movie)
table.write("The top 5 most correlated are:\n\n")
table.write("\\begin{longtable}{| c | c | c |}\n")
table.write("\\hline\n")
table.write("Position & Movie & Similarity\\\\\n")
count = 1
for l in top:
    table.write("\\hline\n {} & {} & {:.3f}\\\\\n".format(count, l[1], l[0]))
    count += 1
table.write("\\hline\n")
table.write("\\caption{Top 5 correlated to favorite movie}\n")
コード例 #17
0
ファイル: user_selector.py プロジェクト: erikaris/cs532-s16
 def load_directory(self, dir):
     self.prefs = recommendations.loadMovieLens(dir)
コード例 #18
0
 def __init__(self):
     #userId为数据集中的用户ID,类型为str。maxNum为想要的推荐电影数量。
     self.userId = ''
     self.maxNum = 0
     self.resultList = []
     self.prefs = recommendations.loadMovieLens()