2.2.5 健身分析决策树回归

请根据题目要求,在下方空白处填入正确的代码(点击 💡 按钮查看提示)

数据集说明
文件名:fitness analysis.csv
TimestampYour name Your gender Your age daily_steps
2019/07/03 11:48:...ParkaviFemale19 to 2512270
2019/07/03 11:51:...NithilaaFemale19 to 255860
2019/07/03 11:56:...Karunya vFemale15 to 1810390
2019/07/04 5:43:3...AnushaFemale15 to 1810191
2019/07/04 5:44:2...NikkithaFemale19 to 2510734
2019/07/04 6:23:3...GirijaFemale40 and above11265
2019/07/04 6:33:2...SrinivasanMale40 and above5466
2019/07/04 7:40:5...RanjaniFemale15 to 189426
2019/07/04 8:06:1...Bupesh RMale19 to 2510578
2019/07/04 8:09:0...SudhanMale15 to 1813322
共 545 条数据,仅展示前 10 条
代码填空
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
import pickle
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
# 加载数据集
df = 
# 显示前五行数据
print()
# 选择相关特征进行建模
X = df[['Your gender ', 'How important is exercise to you ?', 'How healthy do you consider yourself?']]
X = (X)  # 将分类变量转为数值变量
# 设置目标变量
y =   
# 将数据集划分为训练集和测试集(测试集占20%)
X_train, X_test, y_train, y_test = (, random_state=42)
# 创建并训练决策树回归模型
 = (random_state=42)
# 训练决策树回归模型
# 保存训练好的模型
with open('2.2.5_model.pkl', 'wb') as model_file:
    pickle.
# 进行预测
y_pred = 
# 将结果保存到文本文件中
results = pd.DataFrame({'实际值': y_test, '预测值': y_pred})
results_filename = '2.2.5_results.txt'
(, index=False, sep='\t')  
# 将测试结果保存到报告文件中
report_filename = '2.2.5_report.txt'
with open() as f:
    f.write(f'均方误差: {}\n')
    f.write(f'平均绝对误差: {}\n')
    f.write(f'决定系数: {}\n')
提示: