Encoding¶
Encoding features is a very important part of the data science life cycle. In data science, generality is important and having too many categories can compromise that and lead to incorrect results. In addition, some algorithmic optimizations are linear and prefer categorized information, and some can’t process non-numerical features.
There are many encoding techniques:
User-Defined Encoding: The most flexible encoding. The user can choose how to encode the different categories.
Label Encoding: Each category is converted to an integer using a bijection to [0;n-1] where n is the feature number of unique values.
One-hot Encoding: This technique creates dummies (values in {0,1}) of each category. The categories are then separated into n features.
Mean Encoding: This technique uses the frequencies of each category for a specific response column.
Discretization: This technique uses various mathematical technique to encode continuous features into categories.
To demonstrate encoding data in vastorbit, we’ll use the well-known titanic dataset.
from vastorbit.datasets import load_titanic
titanic = load_titanic()
titanic.head(100)
123 pclassInteger | 123 survivedInteger | Abc nameVarchar(164) | Abc sexVarchar(20) | 123 ageDouble | 123 sibspInteger | 123 parchInteger | Abc ticketVarchar(36) | 123 fareDouble | Abc cabinVarchar(30) | Abc embarkedVarchar(20) | Abc boatVarchar(100) | 123 bodyInteger | Abc home.destVarchar(100) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 3 | 1 | McCormack, Mr. Thomas Joseph | male | [null] | 0 | 0 | 367228 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 2 | 3 | 1 | McCoy, Miss. Agnes | female | [null] | 2 | 0 | 367226 | 23.25 | [null] | Q | 16 | [null] | [null] |
| 3 | 3 | 1 | McCoy, Miss. Alicia | female | [null] | 2 | 0 | 367226 | 23.25 | [null] | Q | 16 | [null] | [null] |
| 4 | 3 | 1 | McCoy, Mr. Bernard | male | [null] | 2 | 0 | 367226 | 23.25 | [null] | Q | 16 | [null] | [null] |
| 5 | 3 | 1 | McDermott, Miss. Brigdet Delia | female | [null] | 0 | 0 | 330932 | 7.7875 | [null] | Q | 13 | [null] | [null] |
| 6 | 3 | 0 | McEvoy, Mr. Michael | male | [null] | 0 | 0 | 36568 | 15.5 | [null] | Q | [null] | [null] | [null] |
| 7 | 3 | 1 | McGovern, Miss. Mary | female | [null] | 0 | 0 | 330931 | 7.8792 | [null] | Q | 13 | [null] | [null] |
| 8 | 3 | 1 | McGowan, Miss. Anna "Annie" | female | 15.0 | 0 | 0 | 330923 | 8.0292 | [null] | Q | [null] | [null] | [null] |
| 9 | 3 | 0 | McGowan, Miss. Katherine | female | 35.0 | 0 | 0 | 9232 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 10 | 3 | 0 | McMahon, Mr. Martin | male | [null] | 0 | 0 | 370372 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 11 | 3 | 0 | McNamee, Mr. Neal | male | 24.0 | 1 | 0 | 376566 | 16.1 | [null] | S | [null] | [null] | [null] |
| 12 | 3 | 0 | McNamee, Mrs. Neal (Eileen O'Leary) | female | 19.0 | 1 | 0 | 376566 | 16.1 | [null] | S | [null] | 53 | [null] |
| 13 | 3 | 0 | McNeill, Miss. Bridget | female | [null] | 0 | 0 | 370368 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 14 | 3 | 0 | Meanwell, Miss. (Marion Ogden) | female | [null] | 0 | 0 | SOTON/O.Q. 392087 | 8.05 | [null] | S | [null] | [null] | [null] |
| 15 | 3 | 0 | Meek, Mrs. Thomas (Annie Louise Rowley) | female | [null] | 0 | 0 | 343095 | 8.05 | [null] | S | [null] | [null] | [null] |
| 16 | 3 | 0 | Meo, Mr. Alfonzo | male | 55.5 | 0 | 0 | A.5. 11206 | 8.05 | [null] | S | [null] | 201 | [null] |
| 17 | 3 | 0 | Mernagh, Mr. Robert | male | [null] | 0 | 0 | 368703 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 18 | 3 | 1 | Midtsjo, Mr. Karl Albert | male | 21.0 | 0 | 0 | 345501 | 7.775 | [null] | S | 15 | [null] | [null] |
| 19 | 3 | 0 | Miles, Mr. Frank | male | [null] | 0 | 0 | 359306 | 8.05 | [null] | S | [null] | [null] | [null] |
| 20 | 3 | 0 | Mineff, Mr. Ivan | male | 24.0 | 0 | 0 | 349233 | 7.8958 | [null] | S | [null] | [null] | [null] |
| 21 | 3 | 0 | Minkoff, Mr. Lazar | male | 21.0 | 0 | 0 | 349211 | 7.8958 | [null] | S | [null] | [null] | [null] |
| 22 | 3 | 0 | Mionoff, Mr. Stoytcho | male | 28.0 | 0 | 0 | 349207 | 7.8958 | [null] | S | [null] | [null] | [null] |
| 23 | 3 | 0 | Mitkoff, Mr. Mito | male | [null] | 0 | 0 | 349221 | 7.8958 | [null] | S | [null] | [null] | [null] |
| 24 | 3 | 1 | Mockler, Miss. Helen Mary "Ellie" | female | [null] | 0 | 0 | 330980 | 7.8792 | [null] | Q | 16 | [null] | [null] |
| 25 | 3 | 0 | Moen, Mr. Sigurd Hansen | male | 25.0 | 0 | 0 | 348123 | 7.65 | F G73 | S | [null] | 309 | [null] |
| 26 | 3 | 1 | Moor, Master. Meier | male | 6.0 | 0 | 1 | 392096 | 12.475 | E121 | S | 14 | [null] | [null] |
| 27 | 3 | 1 | Moor, Mrs. (Beila) | female | 27.0 | 0 | 1 | 392096 | 12.475 | E121 | S | 14 | [null] | [null] |
| 28 | 3 | 0 | Moore, Mr. Leonard Charles | male | [null] | 0 | 0 | A4. 54510 | 8.05 | [null] | S | [null] | [null] | [null] |
| 29 | 3 | 1 | Moran, Miss. Bertha | female | [null] | 1 | 0 | 371110 | 24.15 | [null] | Q | 16 | [null] | [null] |
| 30 | 3 | 0 | Moran, Mr. Daniel J | male | [null] | 1 | 0 | 371110 | 24.15 | [null] | Q | [null] | [null] | [null] |
| 31 | 3 | 0 | Moran, Mr. James | male | [null] | 0 | 0 | 330877 | 8.4583 | [null] | Q | [null] | [null] | [null] |
| 32 | 3 | 0 | Morley, Mr. William | male | 34.0 | 0 | 0 | 364506 | 8.05 | [null] | S | [null] | [null] | [null] |
| 33 | 3 | 0 | Morrow, Mr. Thomas Rowan | male | [null] | 0 | 0 | 372622 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 34 | 3 | 1 | Moss, Mr. Albert Johan | male | [null] | 0 | 0 | 312991 | 7.775 | [null] | S | B | [null] | [null] |
| 35 | 3 | 1 | Moubarek, Master. Gerios | male | [null] | 1 | 1 | 2661 | 15.2458 | [null] | C | C | [null] | [null] |
| 36 | 3 | 1 | Moubarek, Master. Halim Gonios ("William George") | male | [null] | 1 | 1 | 2661 | 15.2458 | [null] | C | C | [null] | [null] |
| 37 | 3 | 1 | Moubarek, Mrs. George (Omine "Amenia" Alexander) | female | [null] | 0 | 2 | 2661 | 15.2458 | [null] | C | C | [null] | [null] |
| 38 | 3 | 1 | Moussa, Mrs. (Mantoura Boulos) | female | [null] | 0 | 0 | 2626 | 7.2292 | [null] | C | [null] | [null] | [null] |
| 39 | 3 | 0 | Moutal, Mr. Rahamin Haim | male | [null] | 0 | 0 | 374746 | 8.05 | [null] | S | [null] | [null] | [null] |
| 40 | 3 | 1 | Mullens, Miss. Katherine "Katie" | female | [null] | 0 | 0 | 35852 | 7.7333 | [null] | Q | 16 | [null] | [null] |
| 41 | 3 | 1 | Mulvihill, Miss. Bertha E | female | 24.0 | 0 | 0 | 382653 | 7.75 | [null] | Q | 15 | [null] | [null] |
| 42 | 3 | 0 | Murdlin, Mr. Joseph | male | [null] | 0 | 0 | A./5. 3235 | 8.05 | [null] | S | [null] | [null] | [null] |
| 43 | 3 | 1 | Murphy, Miss. Katherine "Kate" | female | [null] | 1 | 0 | 367230 | 15.5 | [null] | Q | 16 | [null] | [null] |
| 44 | 3 | 1 | Murphy, Miss. Margaret Jane | female | [null] | 1 | 0 | 367230 | 15.5 | [null] | Q | 16 | [null] | [null] |
| 45 | 3 | 1 | Murphy, Miss. Nora | female | [null] | 0 | 0 | 36568 | 15.5 | [null] | Q | 16 | [null] | [null] |
| 46 | 3 | 0 | Myhrman, Mr. Pehr Fabian Oliver Malkolm | male | 18.0 | 0 | 0 | 347078 | 7.75 | [null] | S | [null] | [null] | [null] |
| 47 | 3 | 0 | Naidenoff, Mr. Penko | male | 22.0 | 0 | 0 | 349206 | 7.8958 | [null] | S | [null] | [null] | [null] |
| 48 | 3 | 1 | Najib, Miss. Adele Kiamie "Jane" | female | 15.0 | 0 | 0 | 2667 | 7.225 | [null] | C | C | [null] | [null] |
| 49 | 3 | 1 | Nakid, Miss. Maria ("Mary") | female | 1.0 | 0 | 2 | 2653 | 15.7417 | [null] | C | C | [null] | [null] |
| 50 | 3 | 1 | Nakid, Mr. Sahid | male | 20.0 | 1 | 1 | 2653 | 15.7417 | [null] | C | C | [null] | [null] |
| 51 | 3 | 1 | Nakid, Mrs. Said (Waika "Mary" Mowad) | female | 19.0 | 1 | 1 | 2653 | 15.7417 | [null] | C | C | [null] | [null] |
| 52 | 3 | 0 | Nancarrow, Mr. William Henry | male | 33.0 | 0 | 0 | A./5. 3338 | 8.05 | [null] | S | [null] | [null] | [null] |
| 53 | 3 | 0 | Nankoff, Mr. Minko | male | [null] | 0 | 0 | 349218 | 7.8958 | [null] | S | [null] | [null] | [null] |
| 54 | 3 | 0 | Nasr, Mr. Mustafa | male | [null] | 0 | 0 | 2652 | 7.2292 | [null] | C | [null] | [null] | [null] |
| 55 | 3 | 0 | Naughton, Miss. Hannah | female | [null] | 0 | 0 | 365237 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 56 | 3 | 0 | Nenkoff, Mr. Christo | male | [null] | 0 | 0 | 349234 | 7.8958 | [null] | S | [null] | [null] | [null] |
| 57 | 3 | 1 | Nicola-Yarred, Master. Elias | male | 12.0 | 1 | 0 | 2651 | 11.2417 | [null] | C | C | [null] | [null] |
| 58 | 3 | 1 | Nicola-Yarred, Miss. Jamila | female | 14.0 | 1 | 0 | 2651 | 11.2417 | [null] | C | C | [null] | [null] |
| 59 | 3 | 0 | Nieminen, Miss. Manta Josefina | female | 29.0 | 0 | 0 | 3101297 | 7.925 | [null] | S | [null] | [null] | [null] |
| 60 | 3 | 0 | Niklasson, Mr. Samuel | male | 28.0 | 0 | 0 | 363611 | 8.05 | [null] | S | [null] | [null] | [null] |
| 61 | 3 | 1 | Nilsson, Miss. Berta Olivia | female | 18.0 | 0 | 0 | 347066 | 7.775 | [null] | S | D | [null] | [null] |
| 62 | 3 | 1 | Nilsson, Miss. Helmina Josefina | female | 26.0 | 0 | 0 | 347470 | 7.8542 | [null] | S | 13 | [null] | [null] |
| 63 | 3 | 0 | Nilsson, Mr. August Ferdinand | male | 21.0 | 0 | 0 | 350410 | 7.8542 | [null] | S | [null] | [null] | [null] |
| 64 | 3 | 0 | Nirva, Mr. Iisakki Antino Aijo | male | 41.0 | 0 | 0 | SOTON/O2 3101272 | 7.125 | [null] | S | [null] | [null] | Finland Sudbury, ON |
| 65 | 3 | 1 | Niskanen, Mr. Juha | male | 39.0 | 0 | 0 | STON/O 2. 3101289 | 7.925 | [null] | S | 9 | [null] | [null] |
| 66 | 3 | 0 | Nosworthy, Mr. Richard Cater | male | 21.0 | 0 | 0 | A/4. 39886 | 7.8 | [null] | S | [null] | [null] | [null] |
| 67 | 3 | 0 | Novel, Mr. Mansouer | male | 28.5 | 0 | 0 | 2697 | 7.2292 | [null] | C | [null] | 181 | [null] |
| 68 | 3 | 1 | Nysten, Miss. Anna Sofia | female | 22.0 | 0 | 0 | 347081 | 7.75 | [null] | S | 13 | [null] | [null] |
| 69 | 3 | 0 | Nysveen, Mr. Johan Hansen | male | 61.0 | 0 | 0 | 345364 | 6.2375 | [null] | S | [null] | [null] | [null] |
| 70 | 3 | 0 | O'Brien, Mr. Thomas | male | [null] | 1 | 0 | 370365 | 15.5 | [null] | Q | [null] | [null] | [null] |
| 71 | 3 | 0 | O'Brien, Mr. Timothy | male | [null] | 0 | 0 | 330979 | 7.8292 | [null] | Q | [null] | [null] | [null] |
| 72 | 3 | 1 | O'Brien, Mrs. Thomas (Johanna "Hannah" Godfrey) | female | [null] | 1 | 0 | 370365 | 15.5 | [null] | Q | [null] | [null] | [null] |
| 73 | 3 | 0 | O'Connell, Mr. Patrick D | male | [null] | 0 | 0 | 334912 | 7.7333 | [null] | Q | [null] | [null] | [null] |
| 74 | 3 | 0 | O'Connor, Mr. Maurice | male | [null] | 0 | 0 | 371060 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 75 | 3 | 0 | O'Connor, Mr. Patrick | male | [null] | 0 | 0 | 366713 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 76 | 3 | 0 | Odahl, Mr. Nils Martin | male | 23.0 | 0 | 0 | 7267 | 9.225 | [null] | S | [null] | [null] | [null] |
| 77 | 3 | 0 | O'Donoghue, Ms. Bridget | female | [null] | 0 | 0 | 364856 | 7.75 | [null] | Q | [null] | [null] | [null] |
| 78 | 3 | 1 | O'Driscoll, Miss. Bridget | female | [null] | 0 | 0 | 14311 | 7.75 | [null] | Q | D | [null] | [null] |
| 79 | 3 | 1 | O'Dwyer, Miss. Ellen "Nellie" | female | [null] | 0 | 0 | 330959 | 7.8792 | [null] | Q | [null] | [null] | [null] |
| 80 | 3 | 1 | Ohman, Miss. Velin | female | 22.0 | 0 | 0 | 347085 | 7.775 | [null] | S | C | [null] | [null] |
| 81 | 3 | 1 | O'Keefe, Mr. Patrick | male | [null] | 0 | 0 | 368402 | 7.75 | [null] | Q | B | [null] | [null] |
| 82 | 3 | 1 | O'Leary, Miss. Hanora "Norah" | female | [null] | 0 | 0 | 330919 | 7.8292 | [null] | Q | 13 | [null] | [null] |
| 83 | 3 | 1 | Olsen, Master. Artur Karl | male | 9.0 | 0 | 1 | C 17368 | 3.1708 | [null] | S | 13 | [null] | [null] |
| 84 | 3 | 0 | Olsen, Mr. Henry Margido | male | 28.0 | 0 | 0 | C 4001 | 22.525 | [null] | S | [null] | 173 | [null] |
| 85 | 3 | 0 | Olsen, Mr. Karl Siegwart Andreas | male | 42.0 | 0 | 1 | 4579 | 8.4042 | [null] | S | [null] | [null] | [null] |
| 86 | 3 | 0 | Olsen, Mr. Ole Martin | male | [null] | 0 | 0 | Fa 265302 | 7.3125 | [null] | S | [null] | [null] | [null] |
| 87 | 3 | 0 | Olsson, Miss. Elina | female | 31.0 | 0 | 0 | 350407 | 7.8542 | [null] | S | [null] | [null] | [null] |
| 88 | 3 | 0 | Olsson, Mr. Nils Johan Goransson | male | 28.0 | 0 | 0 | 347464 | 7.8542 | [null] | S | [null] | [null] | [null] |
| 89 | 3 | 1 | Olsson, Mr. Oscar Wilhelm | male | 32.0 | 0 | 0 | 347079 | 7.775 | [null] | S | A | [null] | [null] |
| 90 | 3 | 0 | Olsvigen, Mr. Thor Anderson | male | 20.0 | 0 | 0 | 6563 | 9.225 | [null] | S | [null] | 89 | Oslo, Norway Cameron, WI |
| 91 | 3 | 0 | Oreskovic, Miss. Jelka | female | 23.0 | 0 | 0 | 315085 | 8.6625 | [null] | S | [null] | [null] | [null] |
| 92 | 3 | 0 | Oreskovic, Miss. Marija | female | 20.0 | 0 | 0 | 315096 | 8.6625 | [null] | S | [null] | [null] | [null] |
| 93 | 3 | 0 | Oreskovic, Mr. Luka | male | 20.0 | 0 | 0 | 315094 | 8.6625 | [null] | S | [null] | [null] | [null] |
| 94 | 3 | 0 | Osen, Mr. Olaf Elon | male | 16.0 | 0 | 0 | 7534 | 9.2167 | [null] | S | [null] | [null] | [null] |
| 95 | 3 | 1 | Osman, Mrs. Mara | female | 31.0 | 0 | 0 | 349244 | 8.6833 | [null] | S | [null] | [null] | [null] |
| 96 | 3 | 0 | O'Sullivan, Miss. Bridget Mary | female | [null] | 0 | 0 | 330909 | 7.6292 | [null] | Q | [null] | [null] | [null] |
| 97 | 3 | 0 | Palsson, Master. Gosta Leonard | male | 2.0 | 3 | 1 | 349909 | 21.075 | [null] | S | [null] | 4 | [null] |
| 98 | 3 | 0 | Palsson, Master. Paul Folke | male | 6.0 | 3 | 1 | 349909 | 21.075 | [null] | S | [null] | [null] | [null] |
| 99 | 3 | 0 | Palsson, Miss. Stina Viola | female | 3.0 | 3 | 1 | 349909 | 21.075 | [null] | S | [null] | [null] | [null] |
| 100 | 3 | 0 | Palsson, Miss. Torborg Danira | female | 8.0 | 3 | 1 | 349909 | 21.075 | [null] | S | [null] | [null] | [null] |
Let’s look at the age of the passengers.
titanic["age"].hist()
By using the discretize() method, we can discretize the data using equal-width binning.
titanic["age"].discretize(method = "same_width", h = 10)
titanic["age"].bar(max_cardinality = 10)
We can also discretize the data using frequency bins.
titanic = load_titanic()
titanic["age"].discretize(method = "same_freq", nbins = 5)
titanic["age"].bar(max_cardinality = 5)
We can view the available techniques in the discretize() method with the help() method.
help(titanic["age"].discretize)
To encode a categorical feature, we can use label encoding. For example, the column sex has two categories (male and female) that we can represent with 0 and 1, respectively.
titanic["sex"].label_encode()
titanic["sex"].head(100)
123 sexInteger | |
|---|---|
| 1 | 1 |
| 2 | 0 |
| 3 | 0 |
| 4 | 1 |
| 5 | 0 |
| 6 | 1 |
| 7 | 0 |
| 8 | 0 |
| 9 | 0 |
| 10 | 1 |
| 11 | 1 |
| 12 | 0 |
| 13 | 0 |
| 14 | 0 |
| 15 | 0 |
| 16 | 1 |
| 17 | 1 |
| 18 | 1 |
| 19 | 1 |
| 20 | 1 |
| 21 | 1 |
| 22 | 1 |
| 23 | 1 |
| 24 | 0 |
| 25 | 1 |
| 26 | 1 |
| 27 | 0 |
| 28 | 1 |
| 29 | 0 |
| 30 | 1 |
| 31 | 1 |
| 32 | 1 |
| 33 | 1 |
| 34 | 1 |
| 35 | 1 |
| 36 | 1 |
| 37 | 0 |
| 38 | 0 |
| 39 | 1 |
| 40 | 0 |
| 41 | 0 |
| 42 | 1 |
| 43 | 0 |
| 44 | 0 |
| 45 | 0 |
| 46 | 1 |
| 47 | 1 |
| 48 | 0 |
| 49 | 0 |
| 50 | 1 |
| 51 | 0 |
| 52 | 1 |
| 53 | 1 |
| 54 | 1 |
| 55 | 0 |
| 56 | 1 |
| 57 | 1 |
| 58 | 0 |
| 59 | 0 |
| 60 | 1 |
| 61 | 0 |
| 62 | 0 |
| 63 | 1 |
| 64 | 1 |
| 65 | 1 |
| 66 | 1 |
| 67 | 1 |
| 68 | 0 |
| 69 | 1 |
| 70 | 1 |
| 71 | 1 |
| 72 | 0 |
| 73 | 1 |
| 74 | 1 |
| 75 | 1 |
| 76 | 1 |
| 77 | 0 |
| 78 | 0 |
| 79 | 0 |
| 80 | 0 |
| 81 | 1 |
| 82 | 0 |
| 83 | 1 |
| 84 | 1 |
| 85 | 1 |
| 86 | 1 |
| 87 | 0 |
| 88 | 1 |
| 89 | 1 |
| 90 | 1 |
| 91 | 0 |
| 92 | 0 |
| 93 | 1 |
| 94 | 1 |
| 95 | 0 |
| 96 | 0 |
| 97 | 1 |
| 98 | 1 |
| 99 | 0 |
| 100 | 0 |
When a feature has few categories, the most suitable choice is the one-hot encoding. Label encoding converts a categorical feature to numerical without retaining its mathematical relationships. Let’s use a one-hot encoding on the embarked column.
titanic["embarked"].one_hot_encode()
titanic.select(["embarked", "embarked_C", "embarked_Q"])
Abc embarkedVarchar(20) | 123 embarked_CInteger | 123 embarked_QInteger | |
|---|---|---|---|
| 1 | Q | 0 | 1 |
| 2 | Q | 0 | 1 |
| 3 | Q | 0 | 1 |
| 4 | Q | 0 | 1 |
| 5 | Q | 0 | 1 |
| 6 | Q | 0 | 1 |
| 7 | Q | 0 | 1 |
| 8 | Q | 0 | 1 |
| 9 | Q | 0 | 1 |
| 10 | Q | 0 | 1 |
| 11 | S | 0 | 0 |
| 12 | S | 0 | 0 |
| 13 | Q | 0 | 1 |
| 14 | S | 0 | 0 |
| 15 | S | 0 | 0 |
| 16 | S | 0 | 0 |
| 17 | Q | 0 | 1 |
| 18 | S | 0 | 0 |
| 19 | S | 0 | 0 |
| 20 | S | 0 | 0 |
One-hot encoding can be expensive if the column in question has a large number of categories. In that case, we should use mean encoding. Mean encoding replaces each category of a variable with its corresponding average over a partition by a response column. This makes it an efficient way to encode the data, but be careful of over-fitting.
Let’s use a mean encoding on the home.dest variable.
titanic["home.dest"].mean_encode("survived")
titanic.head(100)
123 pclassInteger | 123 survivedInteger | Abc nameVarchar(164) | 123 sexInteger | Abc ageVarchar | 123 sibspInteger | 123 parchInteger | Abc ticketVarchar(36) | 123 fareDouble | Abc cabinVarchar(30) | Abc embarkedVarchar(20) | Abc boatVarchar(100) | 123 bodyInteger | 123 home.destInt | 123 embarked_CBool | 123 embarked_QBool | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 3 | 1 | de Mulder, Mr. Theodore | 1 | [25.0;31.0] | 0 | 0 | 345774 | 9.5 | [null] | S | 11 | [null] | 1.0 | 0 | 0 |
| 2 | 3 | 0 | Ford, Mr. Arthur | 1 | [null] | 0 | 0 | A/5 1478 | 8.05 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 3 | 2 | 0 | Reeves, Mr. David | 1 | [31.0;42.0] | 0 | 0 | C.A. 17248 | 10.5 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 4 | 3 | 1 | Glynn, Miss. Mary Agatha | 0 | [null] | 0 | 0 | 335677 | 7.75 | [null] | Q | 13 | [null] | 1.0 | 0 | 1 |
| 5 | 3 | 0 | Carr, Miss. Jeannie | 0 | [31.0;42.0] | 0 | 0 | 368364 | 7.75 | [null] | Q | [null] | [null] | 0.0 | 0 | 1 |
| 6 | 2 | 0 | Chapman, Mr. John Henry | 1 | [31.0;42.0] | 1 | 0 | SC/AH 29037 | 26.0 | [null] | S | [null] | 17 | 0.0 | 0 | 0 |
| 7 | 2 | 0 | Chapman, Mrs. John Henry (Sara Elizabeth Lawry) | 0 | [25.0;31.0] | 1 | 0 | SC/AH 29037 | 26.0 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 8 | 2 | 0 | Botsford, Mr. William Hull | 1 | [25.0;31.0] | 0 | 0 | 237670 | 13.0 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 9 | 3 | 1 | Abrahim, Mrs. Joseph (Sophie Halaut Easu) | 0 | [0.17;19.0] | 0 | 0 | 2657 | 7.2292 | [null] | C | C | [null] | 1.0 | 1 | 0 |
| 10 | 2 | 1 | Hart, Mrs. Benjamin (Esther Ada Bloomfield) | 0 | [42.0;80.0] | 1 | 1 | F.C.C. 13529 | 26.25 | [null] | S | 14 | [null] | 0.6666666666666666 | 0 | 0 |
| 11 | 2 | 1 | Hart, Miss. Eva Miriam | 0 | [0.17;19.0] | 0 | 2 | F.C.C. 13529 | 26.25 | [null] | S | 14 | [null] | 0.6666666666666666 | 0 | 0 |
| 12 | 2 | 0 | Hart, Mr. Benjamin | 1 | [42.0;80.0] | 1 | 1 | F.C.C. 13529 | 26.25 | [null] | S | [null] | [null] | 0.6666666666666666 | 0 | 0 |
| 13 | 1 | 1 | Pears, Mrs. Thomas (Edith Wearne) | 0 | [19.0;25.0] | 1 | 0 | 113776 | 66.6 | C2 | S | 8 | [null] | 0.5 | 0 | 0 |
| 14 | 1 | 0 | Pears, Mr. Thomas Clinton | 1 | [25.0;31.0] | 1 | 0 | 113776 | 66.6 | C2 | S | [null] | [null] | 0.5 | 0 | 0 |
| 15 | 3 | 1 | Cohen, Mr. Gurshon "Gus" | 1 | [0.17;19.0] | 0 | 0 | A/5 3540 | 8.05 | [null] | S | 12 | [null] | 1.0 | 0 | 0 |
| 16 | 2 | 0 | del Carlo, Mr. Sebastiano | 1 | [25.0;31.0] | 1 | 0 | SC/PARIS 2167 | 27.7208 | [null] | C | [null] | 295 | 0.5 | 1 | 0 |
| 17 | 2 | 1 | del Carlo, Mrs. Sebastiano (Argenia Genovesi) | 0 | [19.0;25.0] | 1 | 0 | SC/PARIS 2167 | 27.7208 | [null] | C | 12 | [null] | 0.5 | 1 | 0 |
| 18 | 1 | 0 | Crosby, Capt. Edward Gifford | 1 | [42.0;80.0] | 1 | 1 | WE/P 5735 | 71.0 | B22 | S | [null] | 269 | 0.6666666666666666 | 0 | 0 |
| 19 | 1 | 1 | Crosby, Miss. Harriet R | 0 | [31.0;42.0] | 0 | 2 | WE/P 5735 | 71.0 | B22 | S | 7 | [null] | 0.6666666666666666 | 0 | 0 |
| 20 | 1 | 1 | Crosby, Mrs. Edward Gifford (Catherine Elizabeth Halstead) | 0 | [42.0;80.0] | 1 | 1 | 112901 | 26.55 | B26 | S | 7 | [null] | 0.6666666666666666 | 0 | 0 |
| 21 | 1 | 0 | Rood, Mr. Hugh Roscoe | 1 | [null] | 0 | 0 | 113767 | 50.0 | A32 | S | [null] | [null] | 0.0 | 0 | 0 |
| 22 | 2 | 1 | Herman, Mrs. Samuel (Jane Laver) | 0 | [42.0;80.0] | 1 | 2 | 220845 | 65.0 | [null] | S | 9 | [null] | 0.6 | 0 | 0 |
| 23 | 2 | 0 | Sweet, Mr. George Frederick | 1 | [0.17;19.0] | 0 | 0 | 220845 | 65.0 | [null] | S | [null] | [null] | 0.6 | 0 | 0 |
| 24 | 2 | 0 | Herman, Mr. Samuel | 1 | [42.0;80.0] | 1 | 2 | 220845 | 65.0 | [null] | S | [null] | [null] | 0.6 | 0 | 0 |
| 25 | 2 | 1 | Herman, Miss. Kate | 0 | [19.0;25.0] | 1 | 2 | 220845 | 65.0 | [null] | S | 9 | [null] | 0.6 | 0 | 0 |
| 26 | 2 | 1 | Herman, Miss. Alice | 0 | [19.0;25.0] | 1 | 2 | 220845 | 65.0 | [null] | S | 9 | [null] | 0.6 | 0 | 0 |
| 27 | 3 | 1 | Baclini, Miss. Eugenie | 0 | [0.17;19.0] | 2 | 1 | 2666 | 19.2583 | [null] | C | C | [null] | 1.0 | 1 | 0 |
| 28 | 3 | 1 | Baclini, Miss. Helene Barbara | 0 | [0.17;19.0] | 2 | 1 | 2666 | 19.2583 | [null] | C | C | [null] | 1.0 | 1 | 0 |
| 29 | 3 | 1 | Baclini, Miss. Marie Catherine | 0 | [0.17;19.0] | 2 | 1 | 2666 | 19.2583 | [null] | C | C | [null] | 1.0 | 1 | 0 |
| 30 | 3 | 1 | Baclini, Mrs. Solomon (Latifa Qurban) | 0 | [19.0;25.0] | 0 | 3 | 2666 | 19.2583 | [null] | C | C | [null] | 1.0 | 1 | 0 |
| 31 | 3 | 0 | Barbara, Miss. Saiide | 0 | [0.17;19.0] | 0 | 1 | 2691 | 14.4542 | [null] | C | [null] | [null] | 0.0 | 1 | 0 |
| 32 | 3 | 0 | Barbara, Mrs. (Catherine David) | 0 | [42.0;80.0] | 0 | 1 | 2691 | 14.4542 | [null] | C | [null] | [null] | 0.0 | 1 | 0 |
| 33 | 3 | 0 | Elias, Mr. Joseph | 1 | [31.0;42.0] | 0 | 2 | 2675 | 7.2292 | [null] | C | [null] | [null] | 0.0 | 1 | 0 |
| 34 | 2 | 0 | Giles, Mr. Ralph | 1 | [19.0;25.0] | 0 | 0 | 248726 | 13.5 | [null] | S | [null] | 297 | 0.0 | 0 | 0 |
| 35 | 1 | 1 | Brown, Mrs. John Murray (Caroline Lane Lamson) | 0 | [42.0;80.0] | 2 | 0 | 11769 | 51.4792 | C101 | S | D | [null] | 1.0 | 0 | 0 |
| 36 | 2 | 1 | Ball, Mrs. (Ada E Hall) | 0 | [31.0;42.0] | 0 | 0 | 28551 | 13.0 | D | S | 10 | [null] | 1.0 | 0 | 0 |
| 37 | 1 | 1 | Bowen, Miss. Grace Scott | 0 | [42.0;80.0] | 0 | 0 | PC 17608 | 262.375 | [null] | C | 4 | [null] | 1.0 | 1 | 0 |
| 38 | 3 | 0 | Ekstrom, Mr. Johan | 1 | [42.0;80.0] | 0 | 0 | 347061 | 6.975 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 39 | 2 | 1 | Webber, Miss. Susan | 0 | [31.0;42.0] | 0 | 0 | 27267 | 13.0 | E101 | S | 12 | [null] | 1.0 | 0 | 0 |
| 40 | 1 | 0 | Minahan, Dr. William Edward | 1 | [42.0;80.0] | 2 | 0 | 19928 | 90.0 | C78 | Q | [null] | 230 | 0.5 | 0 | 1 |
| 41 | 1 | 1 | Minahan, Mrs. William Edward (Lillian E Thorpe) | 0 | [31.0;42.0] | 1 | 0 | 19928 | 90.0 | C78 | Q | 14 | [null] | 0.5 | 0 | 1 |
| 42 | 1 | 1 | Williams, Mr. Richard Norris II | 1 | [19.0;25.0] | 0 | 1 | PC 17597 | 61.3792 | [null] | C | A | [null] | 0.5 | 1 | 0 |
| 43 | 1 | 0 | Williams, Mr. Charles Duane | 1 | [42.0;80.0] | 0 | 1 | PC 17597 | 61.3792 | [null] | C | [null] | [null] | 0.5 | 1 | 0 |
| 44 | 3 | 0 | Elsbury, Mr. William James | 1 | [42.0;80.0] | 0 | 0 | A/5 3902 | 7.25 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 45 | 3 | 1 | Finoli, Mr. Luigi | 1 | [null] | 0 | 0 | SOTON/O.Q. 3101308 | 7.05 | [null] | S | 15 | [null] | 1.0 | 0 | 0 |
| 46 | 3 | 0 | Eklund, Mr. Hans Linus | 1 | [0.17;19.0] | 0 | 0 | 347074 | 7.775 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 47 | 3 | 1 | Bradley, Miss. Bridget Delia | 0 | [19.0;25.0] | 0 | 0 | 334914 | 7.725 | [null] | Q | 13 | [null] | 1.0 | 0 | 1 |
| 48 | 1 | 1 | Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) | 0 | [42.0;80.0] | 0 | 1 | 11767 | 83.1583 | C50 | C | 7 | [null] | 1.0 | 1 | 0 |
| 49 | 1 | 1 | Earnshaw, Mrs. Boulton (Olive Potter) | 0 | [19.0;25.0] | 0 | 1 | 11767 | 83.1583 | C54 | C | 7 | [null] | 1.0 | 1 | 0 |
| 50 | 3 | 1 | Asplund, Mr. Johan Charles | 1 | [19.0;25.0] | 0 | 0 | 350054 | 7.7958 | [null] | S | 13 | [null] | 1.0 | 0 | 0 |
| 51 | 2 | 0 | Harbeck, Mr. William H | 1 | [42.0;80.0] | 0 | 0 | 248746 | 13.0 | [null] | S | [null] | 35 | 0.0 | 0 | 0 |
| 52 | 3 | 1 | Goldsmith, Master. Frank John William "Frankie" | 1 | [0.17;19.0] | 0 | 2 | 363291 | 20.525 | [null] | S | C D | [null] | 0.6666666666666666 | 0 | 0 |
| 53 | 3 | 0 | Goldsmith, Mr. Frank John | 1 | [31.0;42.0] | 1 | 1 | 363291 | 20.525 | [null] | S | [null] | [null] | 0.6666666666666666 | 0 | 0 |
| 54 | 3 | 1 | Goldsmith, Mrs. Frank John (Emily Alice Brown) | 0 | [25.0;31.0] | 1 | 1 | 363291 | 20.525 | [null] | S | C D | [null] | 0.6666666666666666 | 0 | 0 |
| 55 | 3 | 0 | Aronsson, Mr. Ernst Axel Algot | 1 | [19.0;25.0] | 0 | 0 | 349911 | 7.775 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 56 | 2 | 1 | Angle, Mrs. William A (Florence "Mary" Agnes Hughes) | 0 | [31.0;42.0] | 1 | 0 | 226875 | 26.0 | [null] | S | 11 | [null] | 0.5 | 0 | 0 |
| 57 | 2 | 0 | Angle, Mr. William A | 1 | [31.0;42.0] | 1 | 0 | 226875 | 26.0 | [null] | S | [null] | [null] | 0.5 | 0 | 0 |
| 58 | 1 | 1 | Tucker, Mr. Gilbert Milligan Jr | 1 | [25.0;31.0] | 0 | 0 | 2543 | 28.5375 | C53 | C | 7 | [null] | 1.0 | 1 | 0 |
| 59 | 3 | 0 | Waelens, Mr. Achille | 1 | [19.0;25.0] | 0 | 0 | 345767 | 9.0 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 60 | 3 | 0 | Adams, Mr. John | 1 | [25.0;31.0] | 0 | 0 | 341826 | 8.05 | [null] | S | [null] | 103 | 0.0 | 0 | 0 |
| 61 | 3 | 0 | Brocklebank, Mr. William Alfred | 1 | [31.0;42.0] | 0 | 0 | 364512 | 8.05 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 62 | 3 | 0 | Denkoff, Mr. Mitto | 1 | [null] | 0 | 0 | 349225 | 7.8958 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 63 | 2 | 0 | Myles, Mr. Thomas Francis | 1 | [42.0;80.0] | 0 | 0 | 240276 | 9.6875 | [null] | Q | [null] | [null] | 0.0 | 0 | 1 |
| 64 | 2 | 1 | Brown, Mrs. Thomas William Solomon (Elizabeth Catherine Ford) | 0 | [31.0;42.0] | 1 | 1 | 29750 | 39.0 | [null] | S | 14 | [null] | 0.6666666666666666 | 0 | 0 |
| 65 | 2 | 1 | Brown, Miss. Edith Eileen | 0 | [0.17;19.0] | 0 | 2 | 29750 | 39.0 | [null] | S | 14 | [null] | 0.6666666666666666 | 0 | 0 |
| 66 | 2 | 0 | Brown, Mr. Thomas William Solomon | 1 | [42.0;80.0] | 1 | 1 | 29750 | 39.0 | [null] | S | [null] | [null] | 0.6666666666666666 | 0 | 0 |
| 67 | 2 | 1 | Renouf, Mrs. Peter Henry (Lillian Jefferys) | 0 | [25.0;31.0] | 3 | 0 | 31027 | 21.0 | [null] | S | [null] | [null] | 0.5 | 0 | 0 |
| 68 | 2 | 0 | Renouf, Mr. Peter Henry | 1 | [31.0;42.0] | 1 | 0 | 31027 | 21.0 | [null] | S | 12 | [null] | 0.5 | 0 | 0 |
| 69 | 1 | 1 | Barkworth, Mr. Algernon Henry Wilson | 1 | [42.0;80.0] | 0 | 0 | 27042 | 30.0 | A23 | S | B | [null] | 1.0 | 0 | 0 |
| 70 | 2 | 0 | Downton, Mr. William James | 1 | [42.0;80.0] | 0 | 0 | 28403 | 26.0 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 71 | 3 | 0 | Canavan, Mr. Patrick | 1 | [19.0;25.0] | 0 | 0 | 364858 | 7.75 | [null] | Q | [null] | [null] | 0.0 | 0 | 1 |
| 72 | 2 | 1 | Brown, Miss. Amelia "Mildred" | 0 | [19.0;25.0] | 0 | 0 | 248733 | 13.0 | F33 | S | 11 | [null] | 1.0 | 0 | 0 |
| 73 | 1 | 0 | Loring, Mr. Joseph Holland | 1 | [25.0;31.0] | 0 | 0 | 113801 | 45.5 | [null] | S | [null] | [null] | 0.5 | 0 | 0 |
| 74 | 2 | 1 | Kelly, Mrs. Florence "Fannie" | 0 | [42.0;80.0] | 0 | 0 | 223596 | 13.5 | [null] | S | 9 | [null] | 0.5 | 0 | 0 |
| 75 | 3 | 1 | Badman, Miss. Emily Louisa | 0 | [0.17;19.0] | 0 | 0 | A/4 31416 | 8.05 | [null] | S | C | [null] | 1.0 | 0 | 0 |
| 76 | 1 | 1 | Sloper, Mr. William Thompson | 1 | [25.0;31.0] | 0 | 0 | 113788 | 35.5 | A6 | S | 7 | [null] | 1.0 | 0 | 0 |
| 77 | 1 | 1 | Shutes, Miss. Elizabeth W | 0 | [31.0;42.0] | 0 | 0 | PC 17582 | 153.4625 | C125 | S | 3 | [null] | 1.0 | 0 | 0 |
| 78 | 3 | 1 | Abelseth, Miss. Karen Marie | 0 | [0.17;19.0] | 0 | 0 | 348125 | 7.65 | [null] | S | 16 | [null] | 1.0 | 0 | 0 |
| 79 | 3 | 0 | Assaf, Mr. Gerios | 1 | [19.0;25.0] | 0 | 0 | 2692 | 7.225 | [null] | C | [null] | [null] | 0.2 | 1 | 0 |
| 80 | 3 | 0 | Attalah, Mr. Sleiman | 1 | [25.0;31.0] | 0 | 0 | 2694 | 7.225 | [null] | C | [null] | [null] | 0.2 | 1 | 0 |
| 81 | 3 | 1 | Assaf Khalil, Mrs. Mariana ("Miriam") | 0 | [42.0;80.0] | 0 | 0 | 2696 | 7.225 | [null] | C | C | [null] | 0.2 | 1 | 0 |
| 82 | 3 | 0 | Caram, Mrs. Joseph (Maria Elias) | 0 | [null] | 1 | 0 | 2689 | 14.4583 | [null] | C | [null] | [null] | 0.2 | 1 | 0 |
| 83 | 3 | 0 | Caram, Mr. Joseph | 1 | [null] | 1 | 0 | 2689 | 14.4583 | [null] | C | [null] | [null] | 0.2 | 1 | 0 |
| 84 | 1 | 1 | Ostby, Miss. Helene Ragnhild | 0 | [19.0;25.0] | 0 | 1 | 113509 | 61.9792 | B36 | C | 5 | [null] | 0.5 | 1 | 0 |
| 85 | 1 | 0 | Ostby, Mr. Engelhart Cornelius | 1 | [42.0;80.0] | 0 | 1 | 113509 | 61.9792 | B30 | C | [null] | 234 | 0.5 | 1 | 0 |
| 86 | 2 | 1 | Abelson, Mrs. Samuel (Hannah Wizosky) | 0 | [25.0;31.0] | 1 | 0 | P/PP 3381 | 24.0 | [null] | C | 10 | [null] | 0.5 | 1 | 0 |
| 87 | 2 | 0 | Abelson, Mr. Samuel | 1 | [25.0;31.0] | 1 | 0 | P/PP 3381 | 24.0 | [null] | C | [null] | [null] | 0.5 | 1 | 0 |
| 88 | 2 | 1 | Reynaldo, Ms. Encarnacion | 0 | [25.0;31.0] | 0 | 0 | 230434 | 13.0 | [null] | S | 9 | [null] | 1.0 | 0 | 0 |
| 89 | 3 | 0 | Andersson, Miss. Ellis Anna Maria | 0 | [0.17;19.0] | 4 | 2 | 347082 | 31.275 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 90 | 3 | 0 | Andersson, Miss. Ingeborg Constanzia | 0 | [0.17;19.0] | 4 | 2 | 347082 | 31.275 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 91 | 3 | 0 | Andersson, Miss. Sigrid Elisabeth | 0 | [0.17;19.0] | 4 | 2 | 347082 | 31.275 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 92 | 3 | 0 | Andersson, Mr. Anders Johan | 1 | [31.0;42.0] | 1 | 5 | 347082 | 31.275 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 93 | 3 | 0 | Andersson, Mrs. Anders Johan (Alfrida Konstantia Brogren) | 0 | [31.0;42.0] | 1 | 5 | 347082 | 31.275 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 94 | 3 | 0 | Andersson, Miss. Ebba Iris Alfrida | 0 | [0.17;19.0] | 4 | 2 | 347082 | 31.275 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 95 | 3 | 0 | Andersson, Master. Sigvard Harald Elias | 1 | [0.17;19.0] | 4 | 2 | 347082 | 31.275 | [null] | S | [null] | [null] | 0.0 | 0 | 0 |
| 96 | 1 | 0 | Roebling, Mr. Washington Augustus II | 1 | [25.0;31.0] | 0 | 0 | PC 17590 | 50.4958 | A24 | S | [null] | [null] | 0.0 | 0 | 0 |
| 97 | 1 | 0 | Blackwell, Mr. Stephen Weart | 1 | [42.0;80.0] | 0 | 0 | 113784 | 35.5 | T | S | [null] | [null] | 0.0 | 0 | 0 |
| 98 | 1 | 1 | Spedden, Mr. Frederic Oakley | 1 | [42.0;80.0] | 1 | 1 | 16966 | 134.5 | E34 | C | 3 | [null] | 1.0 | 1 | 0 |
| 99 | 1 | 1 | Spedden, Master. Robert Douglas | 1 | [0.17;19.0] | 0 | 2 | 16966 | 134.5 | E34 | C | 3 | [null] | 1.0 | 1 | 0 |
| 100 | 1 | 1 | Spedden, Mrs. Frederic Oakley (Margaretta Corning Stone) | 0 | [31.0;42.0] | 1 | 1 | 16966 | 134.5 | E34 | C | 3 | [null] | 1.0 | 1 | 0 |
vastorbit offers many encoding techniques. For example, the case_when() and decode() methods allow the user to use a customized encoding on a column. The discretize() method allows you to reduce the number of categories in a column. It’s important to get familiar with all the techniques available so you can make informed decisions about which to use for a given dataset.