这组题目围绕一个 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):司机 IDpassenger_id(int):乘客 IDdate(str):行程日期status(str):行程状态
status 的可能取值包括:
"Rejected by the driver"
"Cancelled by the passenger"
"Success"Task 1:Calculate the average driver rating
计算 drivers.csv 中 rating 列的平均值。
结果需要保存为:
insight_type: "average_driver_rating"
value: calculated average ratingTask 2:Calculate the percentage of drivers with a second language
计算拥有第二语言的司机比例。
如果:
second_language != "no"则表示司机拥有第二语言。
结果需要表示为百分比,并保存为:
insight_type: "percentage_drivers_with_second_language"
value: calculated percentageTask 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 rateOutput
最终生成:
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, 2023as today.
数据分布在多个 CSV 文件中。
1. drivers.csv
包含:
driver_id(int):司机唯一 IDcar_id(int):车辆 IDage(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 = 05. 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_yearOutput
保存结果:
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):司机唯一 IDcar_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-learnData 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可以使用:
OrdinalEncoderEncoder 必须:
- 在 Training Data 上
fit - 使用同一个 Encoder 转换 Train Data
- 使用同一个 Encoder 转换 Test Data
不能分别对 Train 和 Test 单独 Fit。
3. Standardize net_worth_of_tips
使用:
StandardScaler对:
net_worth_of_tips进行标准化。
Scaler 同样只能:
fit training data然后使用该 Scaler 分别转换:
train
test4. 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 = 1This 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代写等服务助您早日上岸~
