Beispiel #1
0
def get_user_match(name=None,gender=None,age=None,occupation=None):
	# Default values if gender, age or occupation are not passed in.
	_name = 'User'
	_gender = 'M'
	_age = 21
	_occupation = 'student'
	dataList,userList,itemList = read_data_files(dataName='data_files/u.data',itemName='data_files/u.item',userName='******')
	prefs = get_prefs(dataList,itemList,userList) 
	similarUsers = list(filter(lambda x: x['age'] == _age and x['gender'] == _gender and x['occupation'] == _occupation,userList))
	defaultLogger.info("{0} similar users found".format(len(similarUsers)))
Beispiel #2
0
def get_user_match(name=None,gender=None,age=None,occupation=None):
	# Default values if gender, age or occupation are not passed in.
	_name = 'User'
	_gender = 'M'
	_age = 21
	_occupation = 'student'

	if name:
		_name = name

	if gender:
		_gender = gender
	
	if age:
		_age = age

	if occupation:
		_occupation = occupation


	# Get the data for the math

	dataList,userList,itemList = read_data_files(dataName='data_files/u.data',itemName='data_files/u.item',userName='******')
	
	# Create a dictionary of users and the movies that they rated.
	prefs = get_prefs(dataList,itemList,userList) 
	

	similarUsers = list(filter(lambda x: x['age'] == _age and x['gender'] == _gender and x['occupation'] == _occupation,userList))
	defaultLogger.info("{0} similar users found".format(len(similarUsers)))
	
	# Ensure that there are at least 3 similar users found in the filter. 

	userInformation = {}

	for i in similarUsers:
		user_id = int(i['user_id'])

		defaultLogger.debug("Getting movie ratings for user: {0}".format(user_id))
		userPrefs = prefs[user_id]
		defaultLogger.debug("{0} movie ratings found for user: {0}".format(len(userPrefs),user_id))

		# Create a list that can be sorted on rating id 
		defaultLogger.debug("Creating list that can be sorted for user: {0}".format(user_id))
		movieRankingList = []
		for movie in userPrefs.keys():
			movieTitle = movie
			rating = userPrefs[movie]
			movieRankingList.append({'movie_title':movieTitle,'rating':rating})

		lowestToHigh = sorted(movieRankingList,key=lambda x: x['rating'],reverse=False)
		highestToLow = sorted(movieRankingList,key=lambda x: x['rating'],reverse=True)
		defaultLogger.info("Determining top three favorite movies and top three least favorite films for user: {0}".format(user_id))
		userInformation[user_id] = {'top_three_favorite':highestToLow[:3], 'bottom_three_favorite':lowestToHigh[:3]}
	return userInformation
Beispiel #3
0
def get_user_match(name=None, gender=None, age=None, occupation=None):
    # Default values if gender, age or occupation are not passed in.
    _name = 'User'
    _gender = 'M'
    _age = 21
    _occupation = 'student'
    dataList, userList, itemList = read_data_files(
        dataName='data_files/u.data',
        itemName='data_files/u.item',
        userName='******')
    prefs = get_prefs(dataList, itemList, userList)
    similarUsers = list(
        filter(
            lambda x: x['age'] == _age and x['gender'] == _gender and x[
                'occupation'] == _occupation, userList))
    defaultLogger.info("{0} similar users found".format(len(similarUsers)))
Beispiel #4
0
	for i in range(len(topFiveMostCorrelated)):
		print('{rank}){uid:.<48}{correlation_coeffient:<+6}'.format(rank=i+1,uid=topFiveMostCorrelated[i]['user_id'],correlation_coeffient=topFiveMostCorrelated[i]['correlation_coefficent']))

	# Print least correlated 
	print('{heading:-^54}'.format(heading='Top Five Least Correlated'))
	for i in range(len(topFiveMostCorrelated)):
		print('{rank}){uid:.<48}{correlation_coeffient:<+6}'.format(rank=i+1,uid=topFiveLeastCorrelated[i]['user_id'],correlation_coeffient=topFiveLeastCorrelated[i]['correlation_coefficent']))
	print(54*'-')
	print(54*'-')


	#pass

if __name__ == '__main__':
	dataList,userList,itemList = read_data_files(dataName='data_files/u.data',itemName='data_files/u.item',userName='******')
	prefs = get_prefs(dataList,itemList,userList)
	arguments = list(sys.argv)

	userThreads = [] # A list of user threads. 
	userThreadResults = {} # A list of results from those threads
	
	# Check for help flag 
	if '-h' in arguments:
		print("Usage: <user-id-num>...")
	else:
		for userId in range(1,len(sys.argv)):
			# Check to see if the userId is valid 
			if len(list(filter(lambda user: user['user_id'] == int(sys.argv[userId]),userList))) != 0:
				defaultLogger.debug("Creating thread for: {user_id}".format(user_id=sys.argv[userId]))
				# Create thread to process the user if the id is valid 
Beispiel #5
0
            "{rank}){uid:.<48}{correlation_coeffient:<+5}".format(
                rank=i + 1,
                uid=topFiveLeastCorrelated[i]["user_id"],
                correlation_coeffient=topFiveLeastCorrelated[i]["correlation_coefficent"],
            )
        )
    print(54 * "-")
    print(54 * "-")

    # pass


if __name__ == "__main__":
    dataList, userList, itemList = read_data_files(
        dataName="C:/Python27/AS7/src/data_files/u.data",
        itemName="C:/Python27/AS7/src/data_files/u.item",
        userName="******",
    )
    prefs = get_prefs(dataList, itemList, userList)
    arguments = list(sys.argv)

    userThreads = []  # A list of user threads.
    userThreadResults = {}  # A list of results from those threads

    # Check for help flag
    if "-h" in arguments:
        print("Usage: <user-id-num>...")
    else:
        for userId in range(1, len(sys.argv)):
            # Check to see if the userId is valid
            if len(list(filter(lambda user: user["user_id"] == int(sys.argv[userId]), userList))) != 0:
Beispiel #6
0
        print(
            "{rank}){uid:.<48}{correlation_coeffient:<+5}".format(
                rank=i + 1,
                uid=topFiveLeastCorrelated[i]["user_id"],
                correlation_coeffient=topFiveLeastCorrelated[i]["correlation_coefficent"],
            )
        )
    print(54 * "-")
    print(54 * "-")

    # pass


if __name__ == "__main__":
    dataList, userList, itemList = read_data_files(
        dataName="data_files/u.data", itemName="data_files/u.item", userName="******"
    )
    prefs = get_prefs(dataList, itemList, userList)
    arguments = list(sys.argv)

    userThreads = []  # A list of user threads.
    userThreadResults = {}  # A list of results from those threads

    # Check for help flag
    if "-h" in arguments:
        print("Usage: <user-id-num>...")
    else:
        for userId in range(1, len(sys.argv)):
            # Check to see if the userId is valid
            if len(list(filter(lambda user: user["user_id"] == int(sys.argv[userId]), userList))) != 0:
                defaultLogger.debug("Creating thread for: {user_id}".format(user_id=sys.argv[userId]))