Question: What to submit Write all the required functions described below in the given template file named hw 1 . py Fill in the function code
What to submit
Write all the required functions described below in the given template file named hwpy
Fill in the function code for all the functions in this template. Note: Every function has a pass statement because Python does not allow empty functions. The pass statement does nothing, it's simply a filler. You can delete it when you write in your code.
You may implement other helper functions as needed.
Make sure to test your programs on files other than the samples we have provided, to cover the various paths of logic in your code.
Make sure you write ALL your test calls in the main function. Do NOT write ANY code outside of any of the functions.
When you are done writing and testing, submit ONLY the filledin hwpy file to Canvas.
Do NOT submit a Jupyter notebook, it will not be accepted for grading.
You are allowed up to submissions total over regular and late submissions only the last submission will be graded.
How to test your code
You can test your program by calling your functions in the hwpy file from the main function.All test code must be in the main function ONLY. If you write ANY code outside of any of the functions, you will lose credit.In Terminal, execute your program like this: python hwpy This was explained in class: see jannotes.ipynbjannotes.html between cells # and # Writing and executing standalone outside Jupyter notebook Python programs.Make sure the test files are in the same folder as the program. You may develop and test your code in a Jupyter notebook, but for submission you will need to move your code over to hwpy and execute it as above to make sure it works correctly. The process of moving code from a Jupyter notebook to a Python file has been explained in class.You can run your tests on the given ratings and movies files, but testing on only these files may not be sufficient. You should make your own test files as well, to make sure that you cover the various paths of logic in your functions. You are not required to submit any of your test files.You may assume that all parameter values to your functions will be legitimate, so you are not required to check whether the parameter values are valid.In any function that requires the returned values to be sorted or ranked, ties may be broken arbitrarily between equal values.You may retain the main function when submitting, but we will IGNORE itFor this assignment only, grading will be done by an AUTOGRADER program that will call the functions in your hwpy and check the returned value against the expected correct value. It will NOT call your main function.The AUTOGRADER does not look at printed output, so anything you print in your program will be ignored. There will not be any manual inspection of code, credit is based solely on whether your functions return correct results.Partial CreditThere is no partial credit for code structure, etc. Credit is given only when correct values are returned from your functions. However, each function will be tested on several cases. So for instance, if a function runs correctly on out of test cases, you will get full points for the cases and zero for the third. In this sense, there is partial credit for each function.Data InputRatings file: A text file that contains movie ratings. Each line has the name with year of a movie, its rating range inclusive and the id of the user who rated the movie. A movie can have multiple ratings from different users. A user can rate a particular movie only once. A user can however rate multiple movies. Here's a sample ratings file.Movies file: A text file that contains the genres of movies. Each line has a genre, a movie id and the name with year of the movie. To keep it simple, each movie belongs to a single genre. Here's a sample movies file.Note: A movie name includes the year, since it's possible different movies have the same title, but were made in different years. However, no two movies will have the same name in the same year.You may assume that input files will be correctly formatted, and data types will be as expected. So you don't need to write code to catch any formatting or data typing errors.For all computation of rating, do not round up or otherwise modify the rating unless otherwise specified.ImplementationTask : Reading Data pts Write a function readratingsdataf that takes in a ratings file name, and returns a dictionary. Note: the parameter is a file name string such as "myratings.txt NOT a file pointer. The dictionary should have movie as key, and the list of all ratings for it as value.For example: movieratingsdict "The Lion King : "Titanic : pts Write a function readmoviegenref that takes in a movies file name and returns a dictionary. The dictionary should have a onetoone mapping from movie to genre.For example "Toy Story : "Adventure", "Golden Eye : "Action" Watch out for leading and trailing whitespaces in movie name and genre name, and remove them before storing in the dictionary.Task : Processing Data pts Genre dictionaryWrite a function creategenredict that takes as a parameter a movietogenre dictionary, of the kind created in Task The function should return another dictionary in which a genre is mapped to all the movies in that genre.For example: genre: m m m genre: m m pts Average RatingWrite a function calculateaveragerating that takes as a parameter a ratings dictionary, of the kind created in Task It should return a dictionary where the movie is mapped to its average rating computed from the ratings list.For example: SpiderMan : SpiderMan : Task : Recommendation pts Popularity basedIn services such as Netflix and Spotify, you often see recommendations with the heading Popular movies or Trending top Write a function getpopularmovies that takes as parameters a dictionary of movietoaverage rating as created in Task and an integer n default should be The function should return a dictionary movie:average rating, same structure as input dictionary of top n movies based on the average ratings. If there are fewer than n movies, it should return all movies in ranked order of average ratings from highest to lowest. pts Threshold RatingWrite a function filtermovies that takes as parameters a dictionary of movietoaverage rating same as for the popularity based function above and a threshold rating with default value of The function should filter movies based on the threshold rating, and return a dictionary with same structure as the input. For example, if the threshold rating is the returned dictionary should have only those movies from the input whose average rating is equal to or greater than pts Popularity Genre basedIn most recommendation systems, genre of the moviesongbook plays an important role. Often, features like popularity, genre, artist are combined to present recommendations to a user.Write a function getpopularingenre that, given a genre, a genretomovies dictionary as created in Task a dictionary of movie:average rating as created in Task and an integer n default returns the top n most popular movies in that genre based on the average ratings. The return value should be a dictionary of movietoaverage rating of movies that make the cut. If there are fewer than n movies, it should return all movies in ranked order of average ratings from highest to lowest.Genres will be from those in the movie:genre dictionary created in Task The genre name will exactly match one of the genres in the dictionary, so you do not need to do any upper or lower case conversion. pts Genre RatingOne important analysis for content platforms is to determine ratings by genre.Write a function getgenrerating that takes the same parameters as getpopularingenre above, except for n and returns the average rating of the movies in the given genre. pts Genre PopularityWrite a function genrepopularity that takes as parameters a genretomovies dictionary as created in Task a movietoaverage rating dictionary as created in Task and n default and returns the topn rated genres as a dictionary of genre:average rating. If there are fewer than n genres, it should return all genres in ranked order of average ratings from highest to lowest. Hint: Use the above getgenrerating function as a helper.Task : User Focused pts Read the ratings file to return a usertomovies dictionary that maps user ID to a list of the movies they rated, along with the rating they gave. Write a function named readuserratings for this, with the ratings file as the parameter.For example: u: m rm r u: m rm rwhere ui is user ID mi is movie, ri is corresponding rating. You can handle user ID as int or string type, but make sure you consistently use it as the same type everywhere in your code. pts Write a function getusergenre that takes as parameters a user id the usertomovies dictionary as created in Task above and the movietogenre dictionary as created in Task and returns the top genre that the user likes based on the user's ratings. Here, the top genre for the user will be determined by taking the average rating of the movies genrewise that the user has rated. If multiple genres have the same highest ratings for the user, return any one of genres arbitrarily as the top genre. pts Recommend most popular highest average rating movies from the user's top genre that the user has not yet rated. Write a function recommendmovies for this, that takes as parameters a user id the usertomovies dictionary as created in Task above the movietogenre dictionary as created in Task and the movietoaverage rating dictionary as created in Task The function should return a dictionary of movietoaverage rating. If fewer than movies make the cut, then return all the movies that make the cut in ranked order of average ratings from highest to lowest.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
