capital one oa 真题数据分析与机器学习完整题目整理:Taxi Drivers Dataset 四道题

这组题目围绕一个 Taxi Drivers(出租车司机)数据集展开,共分为 4 个连续任务,涵盖基础数据分析、数据收集与特征工程、数据预处理,以及最终的机器学习分类预测。

整体流程可以理解为:

原始 CSV 数据 → 基础分析 → 特征整合 → 数据清洗与编码 → 分类模型训练与预测

下面整理完整题目内容,方便直接阅读和练习。


Question 1 of 4:Basic Data Analysis

Description

You are provided with datasets containing information about taxi drivers and their rides. Your task is to perform some basic data analysis and save the results to a CSV file.

The data is located in the following CSV files.

1. drivers.csv

包含司机基本信息:

  • driver_id (int):司机唯一标识
  • age (int):司机年龄
  • second_language (str):司机的第二语言
    如果司机没有第二语言,则值为 "no"
  • rating (float):司机平均评分

2. rides_{i}.csv

行程数据被拆分成 4 个文件:

rides_1.csv
rides_2.csv
rides_3.csv
rides_4.csv

每个文件包含:

  • ride_id (int):行程唯一标识
  • driver_id (int):司机 ID
  • passenger_id (int):乘客 ID
  • date (str):行程日期
  • status (str):行程状态

status 的可能取值包括:

"Rejected by the driver"
"Cancelled by the passenger"
"Success"

Task 1:Calculate the average driver rating

计算 drivers.csvrating 列的平均值。

结果需要保存为:

insight_type: "average_driver_rating"
value: calculated average rating

Task 2:Calculate the percentage of drivers with a second language

计算拥有第二语言的司机比例。

如果:

second_language != "no"

则表示司机拥有第二语言。

结果需要表示为百分比,并保存为:

insight_type: "percentage_drivers_with_second_language"
value: calculated percentage

Task 3:Calculate the ride success rate

读取并合并:

rides_1.csv
rides_2.csv
rides_3.csv
rides_4.csv

然后计算:

status == "Success"

的行程所占百分比。

结果保存为:

insight_type: "ride_success_rate"
value: calculated success rate

Output

最终生成:

analysis_results.csv

文件结构类似:

insight_type,value
average_driver_rating,...
percentage_drivers_with_second_language,...
ride_success_rate,...

Question 2 of 4:Data Collection and Feature Engineering

Description

You are given access to the data containing information about taxi drivers and their rides, created by April 15th, 2023.

When calculating any time features, consider:

April 15th, 2023

as today.

数据分布在多个 CSV 文件中。


1. drivers.csv

包含:

  • driver_id (int):司机唯一 ID
  • car_id (int):车辆 ID
  • age (int):年龄
  • started_driving_year (int):开始驾驶年份
  • second_language (str):第二语言,没有则为 "no"
  • rating (float):司机评分
  • net_worth_of_tips (float):收到的小费总额
  • driver_class (str):司机类别

driver_class 的值为:

"A class"
"B class"

2. rides_{i}.csv

行程数据拆分为:

rides_1.csv
rides_2.csv
rides_3.csv
rides_4.csv

包含:

  • ride_id (int)
  • driver_id (int)
  • passenger_id (int)
  • date (str)
  • status (str)
  • 多个 Upvote 字段

其中状态包括:

"Rejected by the driver"
"Cancelled by the passenger"
"Success"

部分评价字段以:

_upvote_given

结尾,例如:

car_clearness_upvote_given

这些字段用于统计司机收到的总 Upvotes 数量。


3. Car Data

车辆数据包含司机所使用汽车的信息。

司机数据和车辆数据通过:

car_id

进行关联。

车辆相关字段包括:

model
manufacture_year
last_inspection...

Required Data Processing

1. Merge driver and car information

drivers.csv 和车辆数据按照:

car_id

进行合并。

最终每个司机都需要获得对应车辆信息。


2. Calculate driving experience

使用 2023 年作为当前年份。

计算:

experience = 2023 - started_driving_year

得到司机的驾驶经验年数。


3. Calculate days since inspection

计算车辆距离上次检查已经过去多少天。

当前日期固定为:

2023-04-15

因此:

days_since_inspection

需要表示:

2023-04-15 - last inspection date

之间的天数。


4. Calculate number of upvotes

首先读取并合并全部四个 ride 文件。

找到所有字段名以:

_upvote_given

结尾的列。

对每一次 Ride,将这些 Boolean Upvote 字段进行求和,得到这次行程产生的 Upvotes 数量。

随后按照:

driver_id

进行聚合,统计每位司机获得的 Upvotes 总数。

最终生成:

number_of_upvotes

如果某位司机从未获得 Upvote,则:

number_of_upvotes = 0

5. Construct the final dataset

最终输出的数据应包含:

driver_id
car_model
car_manufacture_year
days_since_inspection
age
experience
second_language
rating
net_worth_of_tips
number_of_upvotes
driver_class

其中车辆字段需要进行重命名:

model

改为:

car_model

以及:

manufacture_year

改为:

car_manufacture_year

Output

保存结果:

collected.csv

不需要输出 DataFrame index。


Question 3 of 4:Data Preparation

Description

You are given a dataset containing information about taxi drivers and their performance metrics.

The dataset includes various attributes for each driver.

数据包含以下字段:

  • driver_id (int):司机唯一 ID
  • car_model (str):车辆型号
  • car_manufacture_year (int):车辆生产年份
  • days_since_inspection (int):距离上次车辆检查的天数
  • age (int):司机年龄
  • experience (int):驾驶经验年数
  • second_language (str):第二语言
  • rating (float):司机平均评分
  • net_worth_of_tips (float):收到的小费总额
  • number_of_rejected_rides (int):司机拒绝的 Ride 数量
  • number_of_upvotes (int):司机获得的 Upvotes 总数
  • number_of_complaints (int):投诉总数
  • number_of_incidents (int):事故 / Incident 数量
  • driver_class (str):司机所属类别

数据被划分为训练集和测试集:

70% Train
30% Test

训练集:

data/train.csv

测试集:

data/test.csv

可以使用 Python 数据处理工具,例如:

pandas
numpy
scikit-learn

Data Preparation Requirements

1. Handle missing age values

训练集的 age 中可能存在缺失值。

首先计算:

mean_age = round(train["age"].mean())

使用训练集平均年龄填补:

train
test

两个数据集中的缺失 age

需要注意,平均年龄必须只根据训练集计算,不能使用测试集计算平均值。


2. Encode categorical variables

对以下两个类别字段进行编码:

second_language
car_model

可以使用:

OrdinalEncoder

Encoder 必须:

  1. 在 Training Data 上 fit
  2. 使用同一个 Encoder 转换 Train Data
  3. 使用同一个 Encoder 转换 Test Data

不能分别对 Train 和 Test 单独 Fit。


3. Standardize net_worth_of_tips

使用:

StandardScaler

对:

net_worth_of_tips

进行标准化。

Scaler 同样只能:

fit training data

然后使用该 Scaler 分别转换:

train
test

4. Encode driver_class

将目标变量转换为数字:

"A class" → 0
"B class" → 1

转换完成后:

driver_class

应成为数值型分类标签。


5. Save processed datasets

处理后的训练集保存为:

processed_train.csv

处理后的测试集保存为:

processed_test.csv

保存 CSV 时:

index=False

即不要输出 Pandas 自动生成的行索引。


Question 4 of 4:Machine Learning Classification

Description

In this question, you are given the dataset that is a result of the previous question.

To prevent being able to use the dataset for the answer to the previous question, random adjustments were applied, but the format and structure remain the same.

Using the cleaned dataset from the prior question, your goal is to train a classifier that is able to predict whether the driver is:

A class = 0

或者:

B class = 1

This is a free-form task, so feel free to use any machine-learning model you want.

You can also use any Python libraries you want.


Dataset Split

上一题中的 Testing Data 被进一步拆分成 Validation 和 Test。

最终数据比例为:

Train      70%
Validation 15%
Test       15%

训练集:

data/train.csv

验证集:

data/val.csv

测试集:

data/test.csv

其中:

Training Set

包含完整特征和:

driver_class

用于训练模型。

Validation Set

同样包含:

driver_class

可以用来评估模型性能、调整模型参数和分类阈值。

Test Set

不包含:

driver_class

最终需要预测这些司机所属的类别。


Modeling Task

Your task is to predict classes of the drivers from test.csv with the lowest possible error.

需要训练一个二分类模型预测:

0 = A class
1 = B class

可以自由选择模型,例如:

Logistic Regression
Random Forest
Gradient Boosting
XGBoost
LightGBM
SVM
KNN
Neural Network

或者其他合适的分类模型。


Evaluation Metrics

评价指标包括:

precision
recall

其中:

B class

也就是:

driver_class = 1

被视为 Positive Class

题目的主要目标是:

maximize recall, while keeping the precision on the relatively high level

也就是说,需要尽可能提高:

Recall

同时保持:

Precision

处于相对较高的水平。

因此这并不是单纯追求 Accuracy 的分类问题。


Validation

模型训练完成后,可以使用:

data/val.csv

测试模型。

重点观察:

precision
recall

尤其是:

B class

对应的 Recall。

当对 Validation Set 的表现满意后,再对:

data/test.csv

进行预测。


Prediction Output

最终测试集的预测结果需要保存为:

predictions.csv

文件中只能包含一列:

driver_class

格式如下:

driver_class
0
1
1
0
...

每一行对应 test.csv 中同一位置的司机。


Scoring the Solution

为了避免测试数据泄漏,当点击:

Run

时,系统只会使用测试数据前 10 行计算部分 Score。

剩余数据会通过 Hidden Tests 检查。

如果需要查看完整数据上的最终得分,需要点击:

Submit

提交答案。

运行限制为:

execution time limit: 8 seconds
memory limit: 4 GB

整套题目的数据流程

这四道题实际上构成了一套完整的数据科学 Pipeline。

第一题首先要求从原始数据中进行简单统计:

Raw Data
    ↓
Basic Data Analysis

第二题开始进行多表数据整合以及 Feature Engineering:

drivers.csv
cars.csv
rides_1.csv
rides_2.csv
rides_3.csv
rides_4.csv
        ↓
Merge + Aggregate
        ↓
collected.csv

第三题进一步完成机器学习之前的数据预处理:

Missing Value Handling
        ↓
Categorical Encoding
        ↓
Feature Scaling
        ↓
Target Encoding
        ↓
processed_train.csv
processed_test.csv

第四题则进入正式建模阶段:

Training Data
      ↓
Classifier
      ↓
Validation
      ↓
Precision / Recall
      ↓
Test Prediction
      ↓
predictions.csv

因此,这并不是四道完全独立的题,而是一套从 数据读取、数据分析、特征工程、数据预处理一直到机器学习建模 的完整 Data Science 实战题。

我们也有代面试,面试辅助,OA代写等服务助您早日上岸~

Leave a Reply

Your email address will not be published. Required fields are marked *