Aan de slagGa gratis aan de slag

Recommending books with support

A library wants to get members to read more and has decided to use market basket analysis to figure out how. They approach you to do the analysis and ask that you use the five most highly-rated books from the goodbooks-10k dataset, which was introduced in the video. You are given the data in one-hot encoded format in a pandas DataFrame called books.

Each column in the DataFrame corresponds to a book and has the value TRUE if the book is contained in a reader's library and is rated highly. To make things simpler, we'll work with shortened book names: Hunger, Potter, and Twilight.

Deze oefening maakt deel uit van de cursus

Market Basket Analysis in Python

Cursus bekijken

Oefeninstructies

  • Compute the support for {Hunger, Potter}.
  • Compute the support for {Hunger, Twilight}.
  • Compute the support for {Potter, Twilight}.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Compute support for Hunger and Potter
supportHP = np.logical_and(books['Hunger'], books['____']).mean()

# Compute support for Hunger and Twilight
supportHT = ____(books['Hunger'], books['Twilight']).mean()

# Compute support for Potter and Twilight
supportPT = np.logical_and(books['Potter'], books['Twilight']).____

# Print support values
print("Hunger Games and Harry Potter: %.2f" % supportHP)
print("Hunger Games and Twilight: %.2f" % supportHT)
print("Harry Potter and Twilight: %.2f" % supportPT)
Code bewerken en uitvoeren