開始使用免費開始

用於歌曲曲風預測的 Pipeline:I

現在要來建立一個 pipeline。它會先以各特徵的平均值補齊遺漏值,接著建立一個 KNN 模型來進行歌曲曲風的分類。

上一題你建立並修改過的 music_df 資料集已為你預先載入,同時還有 KNeighborsClassifiertrain_test_split

本練習屬於課程

使用 scikit-learn 進行監督式學習

檢視課程

練習說明

  • 匯入 SimpleImputerPipeline
  • 建立一個 imputer。
  • 建立一個具有 3 個鄰居的 KNN 分類器。
  • 建立 steps,其為一個 tuple 清單,內容依序為你建立的 imputer 變數,命名為 "imputer",以及你建立的 knn 模型,命名為 "knn"

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import modules
____
____

# Instantiate an imputer
imputer = ____()

# Instantiate a knn model
knn = ____

# Build steps for the pipeline
steps = [("____", ____), 
         ("____", ____)]
編輯並執行程式碼