Pipeline for song genre prediction: II
Having set up the steps of the pipeline in the previous exercise, you will now use it on the music_df
dataset to classify the genre of songs. What makes pipelines so incredibly useful is the simple interface that they provide.
X_train
, X_test
, y_train
, and y_test
have been preloaded for you, and confusion_matrix
has been imported from sklearn.metrics
.
This exercise is part of the course
Supervised Learning with scikit-learn
Exercise instructions
- Create a pipeline using the steps you previously defined.
- Fit the pipeline to the training data.
- Make predictions on the test set.
- Calculate and print the confusion matrix.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
steps = [("imputer", imp_mean),
("knn", knn)]
# Create the pipeline
pipeline = ____(____)
# Fit the pipeline to the training data
____
# Make predictions on the test set
y_pred = ____
# Print the confusion matrix
print(____(____, ____))