編碼技巧
在投影片中,我們介紹了兩種編碼技巧:標籤編碼(label encoding)與獨熱編碼(one-hot encoding)。 實務上要用哪一種,取決於當下情境。不過,在面試時你應該兩種都能熟練運用。
在本練習中,你會在同一個資料集上實作這兩種方法,也就是前面看過、已預先載入到變數 laptops 的laptop prices 資料集。
本練習屬於課程
用 Python 練習統計面試題
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from sklearn import preprocessing
# Create the encoder and print our encoded new_vals
encoder = preprocessing.LabelEncoder()
new_vals = encoder.fit_transform(____)
print(____)