Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part B: Discovering genres? (Exercises 3-5) Each review connects a user to a book. Suppose we want to cluster users into groups based on what

Part B: Discovering genres? (Exercises 3-5)

Each review connects a user to a book. Suppose we want to cluster users into groups based on what books they reviewed; or similarly, suppose we want to cluster books together based on who reviewed them. This kind of clustering betweentwotimes of objects is sometimes referred to as abiclusteringproblem.

To biclustering, we first need to build a (sparse) matrix that encodes these connections. Here is one way. LetA

Aanmn

mnmatrix ofm

musers (rows) andn

nbooks (columns). Let each entrya

i,j

ai,jbe the rating that useri

igave to bookj

j. With such a matrix, we can then use a biclustering algorithm calledspectral co-clusteringto construct both user-user and book-book clusters.

Exercise 3 (2 points): Map string IDs to logical indices

Suppose you are given a pandasSeriesobject,x, whose values are strings. For example, supposexis the followingSeries:

xcatdogcatcataardvarkdoganemoneaardvark

Write function,create_map(x), so that it does the following:

  1. It determines the unique values inx.
  2. It sorts these unique values in ascending order.
  3. It assigns each unique value to a unique integer, starting from 0 and corresponding to the value's position in sorted order.
  4. It constructs and returns a Python dictionary that mapsx-values (keys) to integers (values).

For instance, for the precedingx, the unique sorted values would beaardvark,anemone,cat, anddog. Therefore, we would assignaardvarkto 0,anemoneto 1,catto 2, anddogto 3. Therefore, the function would return the dictonary,

{'aardvark': 0, 'anemone': 1, 'cat': 2, 'dog', 3} 

Note:Your function mustnotmodify the inputSeries,x. The test cell will check for that and may fail with strange errors if you do so.

In[]:

def create_map(x): assert isinstance(x, pd.Series) ### ### YOUR CODE HERE ### 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions