{
  "schemaVersion": 1,
  "id": "2.2.4",
  "title": "低碳生活行为影响因素预测线性回归模型开发与测试",
  "durationMinutes": 20,
  "category": "模型开发与测试",
  "scenario": "在应对气候变化的背景下，了解和促进低碳生活行为变得越来越重要。现要求根据提供的“大学生低碳生活行为的影响因素数据集”，补全2.2.4.ipynb代码。选择合适的特征，开发一个预测大学生低碳生活行为的模型。利用测试工具对模型进行测试，并对测试结果进行分析，完成测试报告，并运用工具对错误原因进行纠正。\n\n（1）正确加载数据集，并显示前五行的数据。\n\n（2）请使用线性回归模型，要求设定自变量和因变量，并根据自变量特征进行模型训练，最终将训练好的模型以文件名2.2.4_model.pkl保存到考生文件夹，结果文件以2.2.4_results.txt保存到考生文件夹。\n\n（3）使用测试工具对模型进行测试，并记录测试结果，命名2.2.4_report.txt，保存到考生文件夹。\n\n（4）对测试结果进行详细分析，并编写测试报告，包括模型性能评估、错误分析及改进建议，将答案写到答题卷文件中，答题卷文件命名为“2.2.4.docx”，保存到考生文件夹。\n\n（5）运用工具分析算法中错误案例产生的原因并进行纠正，重新得到模型训练结果，以文件名2.2.4_results_xg.txt保存到考生文件夹。\n\n（6）将以上代码以及运行结果，以html格式保存并命名为2.2.4.html，保存到考生文件夹，考生文件夹命名为“准考证号+身份证后6位”。",
  "skillRequirements": "(1) 能够维护日常训练集与测试集。\n\n(2) 能使用工具对算法进行训练。\n\n(3) 能够使用测试工具对人工智能产品的使用进行测试。\n\n(4) 能够对测试结果进行分析，编写测试报告。\n\n(5) 能够运用工具，分析算法中错误案例产生的原因并进行纠正。",
  "qualityIndicators": "(1) 深入理解业务，训练符合业务需求的模型。\n\n(2) 数据预处理步骤完整，方法选择合理。\n\n(3) 代码实现正确，结果符合预期。\n\n(4) 测试结果分析全面，报告详细。",
  "tasks": [
    {
      "id": "code-fill",
      "type": "code-fill",
      "title": "补全代码任务",
      "instructions": "依据公开题面和附件补全代码空位；仅检查完成度与提交格式，不公开标准内容。",
      "codeBlocks": [
        "import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_squared_error, r2_score\nimport joblib\nfrom xgboost import XGBRegressor\n\n# 加载数据集\ndata = __________\n\n# 显示数据集的前五行\nprint(__________)\n\n# 删除不必要的列并处理分类变量\ndata_cleaned = __________(__________=['序号', '所用时间'])  # 删除不必要的列\ndata_cleaned = pd.get_dummies(data_cleaned, drop_first=True)  # 将分类变量转换为哑变量/指示变量\n\n# 定义目标变量和特征\ntarget = '5.您进行过绿色低碳的相关生活方式吗?'  # 确保这是目标变量\n\n# 定义自变量和因变量\nX = __________(__________=__________)\ny = __________\n\n# 将数据拆分为训练集和测试集（测试集占20%）\nX_train, X_test, y_train, y_test = __________(__________, random_state=42)\n\n# 初始化线性回归模型\nmodel = __________\n# 训练线性回归模型\n__________\n\n# 保存训练好的模型\nmodel_filename = '2.2.4_model.pkl'\njoblib.__________\n\n# 进行预测\ny_pred = __________\n\n# 将结果保存到文本文件中\nresults = pd.DataFrame({'实际值': y_test, '预测值': y_pred})\nresults_filename = '2.2.4_results.txt'\n__________(__________, index=False, sep='\\t')  # 使用制表符分隔值保存到文本文件\n\n# 将测试结果保存到报告文件中\nreport_filename = '2.2.4_report.txt'\nwith open(report_filename, 'w') as f:\n    f.write(f'均方误差: {__________}\\n')\n    f.write(f'决定系数: {__________}\\n')\n    \n# 分析并纠正错误（示例：使用XGBoost）\n# 初始化XGBoost模型（设定树的数量为1000，学习率为0.05，每棵树的最大深度为5，）\nxgb_model = __________(__________, subsample=0.8, colsample_bytree=0.8)\n# 训练XGBoost模型\n__________\n\n# 使用XGBoost模型进行预测\ny_pred_xg = __________\n\n# 将XGBoost结果保存到文本文件中\nresults_xg_filename = '2.2.4_results_xg.txt'\nresults_xg = pd.DataFrame({'实际值': y_test, '预测值': y_pred_xg})\nresults_xg.to_csv(results_xg_filename, index=False, sep='\\t')  # 使用制表符分隔值保存到文本文件\n\n# 将XGBoost测试结果保存到报告文件中\nreport_filename_xgb = '2.2.4_report_xgb.txt'\nwith open(report_filename_xgb, 'w') as f:\n    f.write(f'均方误差: {__________}\\n')\n    f.write(f'决定系数: {__________}\\n')\n",
        ""
      ],
      "blanks": [
        {
          "id": "blank-1",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-2",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-3",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-4",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-5",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-6",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-7",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-8",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-9",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-10",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-11",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-12",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-13",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-14",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-15",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-16",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-17",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-18",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-19",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-20",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-21",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-22",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-23",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-24",
          "block": 1,
          "placeholder": "__________",
          "gradingMode": "completion-and-format-only"
        }
      ]
    },
    {
      "id": "2-2-response",
      "type": "rubric-response",
      "title": "模型开发与测试报告",
      "instructions": "说明模型开发、测试和结果评价过程。",
      "sections": [
        {
          "id": "response",
          "label": "作答内容"
        }
      ],
      "rubric": [
        {
          "id": "criterion-1",
          "label": "数据划分与特征处理合理",
          "weight": 25
        },
        {
          "id": "criterion-2",
          "label": "模型选择和训练过程清晰",
          "weight": 25
        },
        {
          "id": "criterion-3",
          "label": "测试指标与题目目标匹配",
          "weight": 25
        },
        {
          "id": "criterion-4",
          "label": "包含误差分析、复现和改进建议",
          "weight": 25
        }
      ]
    },
    {
      "id": "artifact-submission",
      "type": "artifact-submission",
      "title": "选择结果文件",
      "instructions": "文件仅在本机选择并校验，不上传，也不持久化文件内容。",
      "items": [
        {
          "id": "artifact-1",
          "label": "提交文件：2.2.4_model.pkl",
          "filename": "2.2.4_model.pkl",
          "extensions": [
            ".pkl"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        },
        {
          "id": "artifact-2",
          "label": "提交文件：2.2.4_results.txt",
          "filename": "2.2.4_results.txt",
          "extensions": [
            ".txt"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        },
        {
          "id": "artifact-3",
          "label": "提交文件：2.2.4.docx",
          "filename": "2.2.4.docx",
          "extensions": [
            ".docx"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        },
        {
          "id": "artifact-4",
          "label": "提交文件：2.2.4_results_xg.txt",
          "filename": "2.2.4_results_xg.txt",
          "extensions": [
            ".txt"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        },
        {
          "id": "artifact-5",
          "label": "提交文件：2.2.4.html",
          "filename": "2.2.4.html",
          "extensions": [
            ".html"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        }
      ]
    }
  ],
  "attachments": [
    {
      "name": "2.2.4.docx",
      "url": "assets/2.2.4/2.2.4.docx",
      "size": 14998,
      "sha256": "da733b10dd64cf1f2f094ce9a07d59c6d87c1fd0b7bedd280cd3edce131c9347",
      "mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    },
    {
      "name": "2.2.4.ipynb",
      "url": "assets/2.2.4/2.2.4.ipynb",
      "size": 3738,
      "sha256": "c6190b604a24062662b6905d0cf6a80f82989415ec6a8ca1cec5c4f5eec9c59a",
      "mime": "application/x-ipynb+json"
    },
    {
      "name": "2.2.4.md",
      "url": "assets/2.2.4/2.2.4.md",
      "size": 2374,
      "sha256": "e76f87d8911944cc1341a903939310b56303f43cac0835da54726dc6a7a22630",
      "mime": "text/markdown"
    },
    {
      "name": "大学生低碳生活行为的影响因素数据集.xlsx",
      "url": "assets/2.2.4/大学生低碳生活行为的影响因素数据集.xlsx",
      "size": 57588,
      "sha256": "c299518811916b0b80ffb90604417da59550bbf299d9309b740920ec3e2ebfac",
      "mime": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    }
  ],
  "grading": {
    "mode": "completion-and-format-only"
  },
  "review": {
    "status": "approved",
    "notice": "由公开题面通用生成，未使用答案树。",
    "conflicts": []
  },
  "contentVersion": "8a223d4beb88ef3c"
}
