{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c06c4c8-c8b3-40b4-81c7-eeedfc992d52",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 加载数据\n",
    "data = __________\n",
    "\n",
    "# 显示前五行的数据\n",
    "__________\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "# 设置图像尺寸\n",
    "plt.figure(figsize=(12, 8))\n",
    "\n",
    "# 识别数值列用于箱线图\n",
    "numeric_cols = data.select_dtypes(include=['float64', 'int64']).columns\n",
    "\n",
    "# 创建箱线图\n",
    "for i, col in enumerate(numeric_cols, 1):\n",
    "    plt.subplot(3, 4, i)\n",
    "    sns.boxplot(x=data[col])\n",
    "    plt.title(col)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()\n",
    "\n",
    "# 使用IQR处理异常值\n",
    "Q1 = __________(0.25)\n",
    "Q3 = __________(0.75)\n",
    "IQR = __________\n",
    "\n",
    "# 移除异常值\n",
    "data_cleaned = data[~((data[numeric_cols] < (Q1 - 1.5 * __________)) | (data[numeric_cols] > (Q3 + 1.5 * __________))).any(axis=1)]\n",
    "\n",
    "# 检查处理重复值\n",
    "duplicates = __________()\n",
    "num_duplicates = duplicates.sum()\n",
    "data_cleaned = data_cleaned[~duplicates]\n",
    "\n",
    "print(f'删除的重复行数: {num_duplicates}')\n",
    "\n",
    "#对数据进行归一化处理\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "\n",
    "scaler = MinMaxScaler()\n",
    "data_cleaned[numeric_cols] = __________\n",
    "\n",
    "# 设定目标变量\n",
    "target_variable = __________\n",
    "\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# 定义特征和目标\n",
    "X = __________(columns=[__________])   #1分\n",
    "y = __________                         #1分\n",
    "\n",
    "# 划分数据（训练集占80%）\n",
    "X_train, X_test, y_train, y_test = __________(__________, random_state=42)\n",
    "\n",
    "# 显示划分后的数据形状\n",
    "print(f'训练数据形状: {X_train.shape}')\n",
    "print(f'测试数据形状: {X_test.shape}')\n",
    "\n",
    "# 保存清洗后的数据到CSV\n",
    "cleaned_file_path = '2.1.3_cleaned_data.csv'\n",
    "__________(__________, index=False)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
