MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Supervised Learning with scikit-learn

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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(____(____, ____))
Edit dan Jalankan Kode