How it works...
We will only be looking at the numerical variables: the displacement, cylinders, and the fuel economy.
We loop through all these features and calculate the first and third quartiles using the .approxQuantile(...) method. The method takes the feature (column) name as its first parameter, the float (or list of floats) of quartiles to calculate as the second parameter, and the third parameter specifies the relative target precision (setting this value to 0 will find exact quantiles but it can be very expensive).
The method returns a list of two (in our case) values: Q1 and Q3. We then calculate the interquartile range and append the (feature_name, [lower_bound, upper_bound]) tuple to the cut_off_point list. After converting ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access