1. 学习
  2. /
  3. 课程
  4. /
  5. Preprocessing for Machine Learning in Python

Connected

练习

Encoding categorical variables - binary

Take a look at the hiking dataset. There are several columns here that need encoding before they can be modeled, one of which is the Accessible column. Accessible is a binary feature, so it has two values, Y or N, which need to be encoded into 1's and 0's. Use scikit-learn's LabelEncoder method to perform this transformation.

说明

100 XP
  • Store LabelEncoder() in a variable named enc.
  • Using the encoder's .fit_transform() method, encode the hiking dataset's "Accessible" column. Call the new column Accessible_enc.
  • Compare the two columns side-by-side to see the encoding.