FastPrepPrepare Taxi Driver Classification Data

Prepare Taxi Driver Classification Data

Boston Consulting Group logoBoston Consulting Group● MediumINTERNOA

Problem statement

Prepare train_drivers and test_drivers for a binary driver-classification task. Return both transformed datasets in one table, with all training rows first and all test rows second. Add dataset as the first column, using "train" or "test".

  1. Compute the mean non-null training age. Fill missing ages in both datasets with that mean, then truncate every age to an integer.
  2. For car_model and second_language, sort the distinct training strings in ascending order and encode them as 0, 1, and so on. Encode any value not seen in training as -1.
  3. Compute the training mean and population standard deviation of net_worth_of_tips. Standardize that column in both datasets with those training statistics and round it to five decimal places. If the training standard deviation is 0, return 0 for every standardized tip value.
  4. Encode "A class" as 0 and "B class" as 1. Preserve a null test label as null.

Keep all other values unchanged and return the declared columns in order.

Table schema

Pandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

train_drivers

Labeled training driver features.

ColumnTypeNullableDescription
driver_idPKIntegerNo—
car_modelTextNo—
car_manufacture_yearIntegerNo—
days_since_inspectionIntegerNo—
ageIntegerYes—
experienceIntegerNo—
second_languageTextNo—
ratingDecimalNo—
net_worth_of_tipsDecimalNo—
number_of_rejected_ridesIntegerNo—
number_of_upvotesIntegerNo—
number_of_complaintsIntegerNo—
number_of_incidentsIntegerNo—
driver_classTextYes—

test_drivers

Driver features to transform with training-only statistics.

ColumnTypeNullableDescription
driver_idPKIntegerNo—
car_modelTextNo—
car_manufacture_yearIntegerNo—
days_since_inspectionIntegerNo—
ageIntegerYes—
experienceIntegerNo—
second_languageTextNo—
ratingDecimalNo—
net_worth_of_tipsDecimalNo—
number_of_rejected_ridesIntegerNo—
number_of_upvotesIntegerNo—
number_of_complaintsIntegerNo—
number_of_incidentsIntegerNo—
driver_classTextYes—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
datasetTextNo—
driver_idIntegerNo—
car_modelIntegerNo—
car_manufacture_yearIntegerNo—
days_since_inspectionIntegerNo—
ageIntegerNo—
experienceIntegerNo—
second_languageIntegerNo—
ratingDecimalNo—
net_worth_of_tipsDecimalNo—
number_of_rejected_ridesIntegerNo—
number_of_upvotesIntegerNo—
number_of_complaintsIntegerNo—
number_of_incidentsIntegerNo—
driver_classIntegerYes—

Row order: must match exactly. Numeric tolerance: 0.00001.

Constraints

  • train_drivers and test_drivers are both non-empty.
  • At least one training age is non-null.
  • Training rows have driver_class equal to "A class" or "B class".
  • Test labels may be null.
  • Every numeric input is finite.
  • Result row order is exact.

More Boston Consulting Group problems

See Boston Consulting Group hiring insights