Python数据分析代写 | CS 365: Homework 5 Programming Exercises

本次美国代写是Python数据分析相关的一个Programming Exercise

In [1]:
# add your imports here
# here are some examples of imports
import matplotlib.pyplot as plt # for plotting
import numpy as np # for simulating random choices
from collections import Counter # for aggregating the results

In the following exercises, we will run simulations of a recommender system that recommends
movies to users, as we discussed in class on 9/23, and in this Piazza post:
https://piazza.com/class/ksg5aj427qney?cid=126

We will start by generating baseline star-ratings to movies. We assume there are movies in the
system, and their ratings are distributed uniformly between 1.0 stars (terrible) and 5.0 stars
(awesome).

In [2]:
k = 10000
movies = np.random.uniform(1.0, 5.0, k)
print (movies)
[2.60119723 2.35860193 1.80319649 … 4.439829 4.32918526 2.44776013]

In this exercise, we ask you to now simulate ratings from two user different populations.
User population 1 consists of random movie-watchers. They pick movies completely at random,
without regard to the underlying rating. After watching movie i with rating ri , they then
generate a user rating

where δ is uniform on [-1.0, 1.0]
and constrain that rating to be in the valid range [1.0, 5.0]
u = max(1.0, u) # round up to 1.0 if needed
u = min(5.0, u) # round down to 5.0 if needed

A rating is recorded as the tuple (i, u).
Produce a list of 50,000 ratings produced by user population 1 and report the average rating the
users generated as average1.
====================
User population 2 consists of more discriminating users. They choose movies proportionally to
the underlying rating using the following selection probabilities:

They then generate a user rating using the same method as user population 1, except their δ is
uniform on [-0.5, 0.5].

Produce a list of 50,000 ratings produced by user population 2 and report the average rating the
users generated as average2.

[Hint: Implementation time-saver: consider using the numpy function random.choice() to
implement selections for User population 2]

In [3]:
# Your code here to compute average1 and average2
In [12]:
print(average1, average2)