1.1. Exercises

Categorical Variables

           name    colour    location    seed   shape  sweetness   water-content  weight  popularity
0         apple       red     canada    True   round     True          84         100      popular
1        banana    yellow     mexico   False    long     True          75         120      popular
2    cantaloupe    orange      spain    True   round     True          90        1360      neutral
3  dragon-fruit   magenta      china    True   round    False          96         600      not popular
4    elderberry    purple    austria   False   round     True          80           5      not popular
5           fig    purple     turkey   False    oval    False          78          40      neutral
6         guava     green     mexico    True    oval     True          83         450      neutral
7   huckleberry      blue     canada    True   round     True          73           5      not popular
8          kiwi     brown      china    True   round     True          80          76      popular
9         lemon    yellow     mexico   False    oval    False          83          65      popular

True or False: Ordinal Encoding

Try Ordinal Encoding Yourself!

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

We’ve seen our basketball dataset but have only used the features salary, weight and height. This time, let’s look at the country column and transform it.

Tasks:

  • Build an ordinal encoder that uses a dtype of int and name it ordinal_encoder.
  • Fit on X_column, transform it and save the results in an object named country_encoded.
Hint 1
  • Are you building OrdinalEncoder and using dtype=int?
  • Are you fitting the transformer?
Fully worked solution: