0
0
ML Pythonml~10 mins

Why recommendations drive engagement in ML Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the library used for building recommendation models.

ML Python
import [1]
Drag options to blanks, or click blank then click option'
Anumpy
Bsklearn
Ctensorflow
Dpandas
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing sklearn which is mainly for classical ML, not deep learning.
Choosing numpy or pandas which are for data manipulation, not modeling.
2fill in blank
medium

Complete the code to create a simple user-item interaction matrix using pandas.

ML Python
import pandas as pd
interactions = pd.DataFrame({'user_id': [1, 2, 1], 'item_id': [101, 102, 103], 'rating': [5, 3, 4]})
matrix = interactions.pivot(index='user_id', columns=[1], values='rating')
Drag options to blanks, or click blank then click option'
A'item_id'
B'rating'
C'user_id'
D'interaction'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user_id' as columns which would not create the correct matrix.
Using 'rating' which is the values, not columns.
3fill in blank
hard

Fix the error in the code that trains a simple recommendation model using TensorFlow.

ML Python
import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(1)
])
model.compile(optimizer='adam', loss=[1])
model.fit(x_train, y_train, epochs=5)
Drag options to blanks, or click blank then click option'
A'binary_crossentropy'
B'mse'
C'categorical_crossentropy'
D'accuracy'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'accuracy' which is for classification, not regression.
Using 'categorical_crossentropy' which is for multi-class classification.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps items to their average ratings above 3.

ML Python
average_ratings = {item: [1] for item, ratings in ratings_dict.items() if [2] > 3}
Drag options to blanks, or click blank then click option'
Asum(ratings)/len(ratings)
Bmax(ratings)
Csum(ratings)
Dlen(ratings)
Attempts:
3 left
💡 Hint
Common Mistakes
Using max or sum alone which do not give average.
Using length alone which is count, not average.
5fill in blank
hard

Fill all three blanks to create a dictionary of recommended items with predicted scores above 4.

ML Python
recommendations = [1] for item, score in predicted_scores.items() if score [2] 4}
sorted_recs = sorted(recommendations.items(), key=[3], reverse=True)
Drag options to blanks, or click blank then click option'
A{item: score
B>
Clambda x: x[1]
D[item, score
Attempts:
3 left
💡 Hint
Common Mistakes
Using list brackets instead of dictionary braces.
Using '<' instead of '>' causing wrong filtering.
Sorting by key instead of value.